Skip to content

Instantly share code, notes, and snippets.

@imhoffd
imhoffd / AsyncIterableSubject.test.ts
Created March 27, 2022 21:11
AsyncIterableSubject
import AsyncIterableSubject from '../AsyncIterableSubject'
let subject: AsyncIterableSubject<number>
const iterateAndReturnFirst = async <T>(
subject: AsyncIterableSubject<T>,
): Promise<IteratorResult<T>> => {
const iterator = subject[Symbol.asyncIterator]()
return iterator.next()
}
@imhoffd
imhoffd / ci.yml
Last active April 19, 2024 19:46
Parallelizing Jest in GitHub Actions
name: CI
on: [push]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }}
steps:
- uses: actions/checkout@v2
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqQmHXeWG737iR40rMO5enlhHMTGTmTi4Kehql9TxheN1PPujeBlQk6Kl0ylYDjPqqUBrSxq/tdxHyyF8h5QD+L5uO9PHyEVLoNCE0gYRhvSupf6K4EhZNz91KVYchRNZcldt6esf6KQfZIF20fNKLnIBJ5rkGO3vJJJkDZIBMH3IzMI7DUyZIA3RBE7wzfbSaZC3X87GWxS3IYM31IdFHXlKwBNFQpv4PKZ3RAeLRHpSuiyXlIuBWE7KEJCxcbDSFSTc3oFNUkwQACSfDze9Gt2T3zCowVB+G5k1pTpBunmMb6uXdzcqAzR41M2cpbbqRCpRmqzbW8psUbcsyTMM5

Keybase proof

I hereby claim:

  • I am dwieeb on github.
  • I am dwieeb (https://keybase.io/dwieeb) on keybase.
  • I have a public key ASBUmZuuhf2WcqCVzbd0Jpgzbi2jgGCtpBBi1pWoG3VsCAo

To claim this, I am signing this object:

@imhoffd
imhoffd / tair.ts
Last active December 31, 2016 21:58
class A { a: string }
class B { b: string }
// Tair's example.
let z = [new B(), new A()]; // z is inferred as array type of A | B
let [a1, b1] = z; // a1 and b1 are of type A | B
let x1 = a1.a + b1.b; // won't work (a1 could be of type B, b1 could be of type A)
let x2 = a1.b + b1.a; // won't work (a1 could be of type A, b1 could be of type B)
// Fixed
class Animal:
pass
# def __init__(self, name=None):
# print("IN ANIMAL")
# self.name = name
# self.position = (0, 0)
class Moveable:
@imhoffd
imhoffd / Threading.scala
Created January 30, 2015 16:48
threading in scala with futures
import scala.util.{Success, Failure}
import scala.concurrent._
import ExecutionContext.Implicits.global
import duration._
class Thing {
private var _a = 0
def a = {
Thread.sleep(500L)
@imhoffd
imhoffd / models.py
Created January 9, 2015 23:24
sqlalchemy polymorphic load_only
# no
query = session.query(MySubModel)
query = query.options(load_only("id", "type"))
# yes, but does not filter type of model
query = session.query(MyModel).with_polymorphic(MySubModel)
query = query.options(load_only("id", "type"))
# yes, but ew
query = session.query(MyModel)
@imhoffd
imhoffd / examples.php
Created November 11, 2014 18:24
strptime2 - parses dates given a format
<?php
require 'strptime2.php';
echo '<pre>';
echo strptime2('12/29/1989', 'm/d/Y') . "\n";
echo strptime2('7/15/1989 10:13am', 'n/d/Y h:ia') . "\n";
echo strptime2('07/15/1989 10:13AM', 'm/d/Y h:iA') . "\n";
echo strptime2('Sep 12, 2013 22:12', 'M j, Y H:i') . "\n";
echo strptime2('Thursday, July 26, 2012 - 2:48:12PM', 'l, F j, Y - g:i:sA') . "\n";
@imhoffd
imhoffd / vCardGenerator.php
Created November 11, 2014 18:23
vCard Generator
<?php
/**
* This class is for generating a string in microformat (vCard or hCard) with supplied data.
* It currently only supports vCard format version 3.0.
*
* Available parameters (description in parentheses) and suggested format (default value in parentheses):
* - 'strict' (true = enforce strict vCard format, false = try your best) => false
* - 'acceptedPhoneNumberTypes' => 'work', 'home', 'mobile'
* - 'acceptedAddressTypes' => 'work', 'home'
*