Skip to content

Instantly share code, notes, and snippets.

View tengla's full-sized avatar

Thomas Eng tengla

  • Oslo, Norway
View GitHub Profile
@tengla
tengla / main.ts
Created February 26, 2025 09:57
Separation of concerns
// src/index.test.ts
import { describe, expect, it } from "bun:test";
import { AppointmentAccessService } from "./index";
describe('AppointmentAccessService', () => {
it('should allow user to find own appointments', () => {
const service = AppointmentAccessService.withUser({
id: 'jane', roles: ['user']
});
interface User {
id: string;
name: string;
roles: string[];
}
function withRoles(roles: string[]) {
return function (_target: Selector, _propertyName: string, propertyDescriptor: PropertyDescriptor) {
let originalMethod = propertyDescriptor.value!;
@tengla
tengla / sockets.ts
Created October 28, 2024 21:20
ws message observable
import {
Observable, retry, map, throwError,
catchError, of, mergeMap, filter
} from "rxjs";
type Message<T> = {
status: number;
data: null;
} | {
@tengla
tengla / node-typescript-esm.md
Created November 21, 2023 22:16 — forked from khalidx/node-typescript-esm.md
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

const target = {
warn(...args){
console.log('tick')
console.log(this);
console.log(...args)
}
};
const logger = new Proxy(target, {
get (target, prop) {
@tengla
tengla / keybase.md
Last active November 3, 2020 11:08

Keybase proof

I hereby claim:

  • I am tengla on github.
  • I am fjosgut (https://keybase.io/fjosgut) on keybase.
  • I have a public key ASDVQIvPio9Qr3oW6lx6tIpE8xiqEr_Q7k5t4ojV2h_WNgo

To claim this, I am signing this object:

@tengla
tengla / upload.js
Last active January 23, 2019 12:41
Hapi file upload handler.
const Joi = require('joi');
module.exports = {
method: 'post',
path: '/upload',
config: {
validate: {
payload: {
files: Joi.array().items(
Joi.any()
@tengla
tengla / clock.js
Created November 13, 2018 22:10
An analog clock in React.
import React, { Component } from 'react';
const style = {
container: {
position: 'relative',
height: '420px',
width: '420px',
margin: '0 auto',
border: '1px solid #aaa'
},
@tengla
tengla / named_regexp.rb
Created November 9, 2012 10:30
Named regexp in Ruby
#!/usr/bin/env ruby -w
r = %r{name:(?<name>[A-Za-z]+);age:(?<age>\d+);location:(?<location>\w+)}x
DATA.read.split("\n").each do |row|
res = r.match(row)
puts res[:name] + " " + res[:age] + " " + res[:location]
end
__END__
@tengla
tengla / person.rb
Created January 17, 2012 12:21
Some meta-progging example in Ruby
class Person
@people = []
@@id = 0
attr_accessor :id, :name, :age
def initialize(args)
@id = (@@id += 1)
@name = args[:name]