Skip to content

Instantly share code, notes, and snippets.

Chad Austin chadaustin

Block or report user

Report or block chadaustin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View enum-from-any.swift
import Foundation
enum Enum: Int {
case one = 1
case two = 2
}
func enumFromAny<T>(_ ctor: (Int) -> T?, _ v: Any) -> T? {
if let n = v as? NSNumber {
return ctor(n.intValue)
View deinit.swift
var count: Int = 1234
class C {
init() {
myThing = count
count += 1
Swift.print("🇺🇸 Entry")
}
deinit {
View equivalent.hs
data AnyObservable t = forall o. (ObservableData o, DataType o ~ t) => AnyObservable o
View record-constraints.cx
trait T1 {}
trait T2 {}
impl T1 Number {}
impl T2 Number {}
fun a<T: T1>(_: {...: T}) {
}
fun b<T: T2>(_: {...: T}) {
View Observable.hs
{-# LANGUAGE TypeFamilies, FlexibleContexts, ExistentialQuantification, ScopedTypeVariables #-}
type Token = String
class Observable ob where
type EventType ob
addObserver :: ob -> (EventType ob -> IO ()) -> IO Token
removeObserver :: ob -> Token -> IO ()
class Observable ob => ObservableData ob where
View existential.swift
protocol P {
func go()
}
extension String: P {
func go() {
print("String")
}
}
extension Int: P {
View memsafe.swift
//
// main.swift
// memsafe
//
// Created by Chad Austin on 8/10/16.
// Copyright © 2016 Chad Austin. All rights reserved.
//
import Foundation
View void.js
function main() {
var $0;
if (((void 0)===(void 0))) {
{
}
$0 = 1;
}
else {
}
{
View circular-buffer.d.ts
declare module 'circular-buffer' {
class CircularBuffer<T> {
constructor(capacity: number);
size(): number;
capacity(): number;
enq(value: T): void;
deq(): T;
get(idx: number): T;
get(start, end): T[];
toarray(): T[];
You can’t perform that action at this time.