Skip to content

Instantly share code, notes, and snippets.

View icanhasjonas's full-sized avatar
🎩
crunching

Jonas Frost icanhasjonas

🎩
crunching
  • Bombsquad Inc, FRST Corp
  • Los Angeles, Chicago, Copenhagen, Stockholm, Bangkok
View GitHub Profile
type ExtractArgType<T> = T extends ArgBuilder<infer U> ? U : T
type ExtractTypeBuilderType<T> = T extends TypeBuilder<infer U> ? U : T
type ExtractFieldType<T> = T extends FieldBuilder<string, {}, infer U, boolean> ? U : T
type AcceptedType = string | number | boolean | TypeBuilder<any>
class SchemaBuilder<T = {}> {
query<Builder extends TypeBuilder<{}>>(builder: (typeBuilder: TypeBuilder) => Builder) {
const result = builder(new TypeBuilder())
return (this as unknown) as SchemaBuilder<T & ExtractTypeBuilderType<Builder>>
@icanhasjonas
icanhasjonas / QueryFilterAttribute.cs
Last active March 6, 2019 23:59
Self Formatting SQLish Filters... for the lazy
[AttributeUsage( AttributeTargets.Property )]
public class QueryFilterAttribute : Attribute {
public QueryFilterAttribute( string fieldName )
{
FieldName = fieldName;
}
public QueryFilterAttribute() { }
public string FieldName { get; }

THE WORLD'S BEST CHILI

The recipe was originally found in a book by the Texas journalist Francis X Tolbert, a man who devoted his life to this fiery meat pot.

It all began in the early 60's when Tolbert wrote an article like got the title "The Hunt for the Real Chilin".

In the coming years, he received 48,000 letters from all of the world corner. He read, prepared, traveled, tested, and interviewed living legends

@icanhasjonas
icanhasjonas / decorated-queries.ts
Created November 1, 2018 16:35
Example of decorated interfaces...
interface Query {
query(sql: string): Promise<any>
}
class QueryImplementation implements Query {
query(sql: string) {
return new Promise<string>(resolve => {
setTimeout(() => resolve('Hello'), 2000)
})
@icanhasjonas
icanhasjonas / fully-typed-context.ts
Created October 31, 2018 04:59
Fully Type Checked and Filtered configuration context for components
type PropertyNames<T> = keyof T
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type Filtered<T, C> = { [K in keyof T]: T[K] extends C ? K : never }[keyof T]
class ConfigurationPageContext<T> {
addTextSetting<K extends PropertyNames<T>>(
field: Extract<K, Filtered<T, string>>,
title: string,
defaultValue: string = null
): ConfigurationPageContext<Omit<T, K>> {
@icanhasjonas
icanhasjonas / webcrawler.cs
Last active February 22, 2023 10:49
Web Crawler in C#
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@icanhasjonas
icanhasjonas / AwaitableCancellationTokenExtensions.cs
Last active June 7, 2017 19:05
Awaitable Cancellation Tokens
public static class AwaitableCancellationTokenExtensions
{
public struct CancellationTokenAwaiter : ICriticalNotifyCompletion, INotifyCompletion
{
private readonly CancellationToken _cancellationToken;
public CancellationTokenAwaiter(CancellationToken cancellationToken)
{
_cancellationToken = cancellationToken;
}
@icanhasjonas
icanhasjonas / glitter.asm
Last active April 7, 2017 16:47 — forked from a904guy/fucked_it_all.batch
Upgraded Jonathan Moo's ANY Window's problem fixing script. (Everyone needs glitter. WARNING: DO NOT RUN!.. My assembly skills may have deteriorated over the years)
mov ax, 0320h ; Load glitter pixels
mov dx, 0080h ; 80 pixels wide screen glitter
xor cx, cx ; Big fan of Xorn/marvel(c)
mov bx, cx ; Make sure glitter is Baxed and Counxted
int 13h ; Interest 13

Keybase proof

I hereby claim:

  • I am icanhasjonas on github.
  • I am icanhasjonas (https://keybase.io/icanhasjonas) on keybase.
  • I have a public key whose fingerprint is 353F 2B54 41B3 0DA8 69E8 EBCD 4A32 C3CB AC9D CC54

To claim this, I am signing this object:

@icanhasjonas
icanhasjonas / is.d.ts
Last active September 11, 2019 12:17
is.js typescript definition file
interface TypeMethods {
arguments(value: any): boolean;
array(value: any): boolean;
boolean(value: any): boolean;
date(value: any): boolean;
error(value: any): boolean;
function(value: any): boolean;
nan(value: any): boolean;
null(value: any): boolean;
number(value: any): boolean;