class User < Crecto::Model
schema "users" do
field :name, String
end
end
user = User.init_with(name: "hello") # doesn't fail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////////////////////////////////////////////////////////////// Array utilities | |
| type Length<T extends any[]> = T["length"]; | |
| type Head<T extends any[]> = T[0]; | |
| type Tail<T extends any[]> = ((...xs: T) => any) extends ((_x: any, ...xs: infer R) => any) ? R : []; | |
| type AllTrue<Ts extends any[]> = { | |
| 0: true, | |
| 1: false, | |
| 2: AllTrue<Tail<Ts>> | |
| }[Length<Ts> extends 0 ? 0 : Head<Ts> extends false ? 1 : 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo ' | |
| activate application "Reminders" | |
| tell application "System Events" to keystroke "n" using command down | |
| tell application "System Events" to keystroke "'"$*"'" | |
| tell application "System Events" to keystroke return | |
| ' | osascript - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Command } from 'commander'; | |
| export class Program<ArgumentTypes extends { [key: string]: any }> { | |
| private readonly parseFn: (cmd: Command) => ArgumentTypes; | |
| private readonly command: Command; | |
| constructor(command: Command, parse: (cmd: Command) => ArgumentTypes) { | |
| this.parseFn = parse; | |
| this.command = command; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EventEmitter<T extends object> { | |
| private readonly listeners: { | |
| [key in keyof T]?: ((value: T[key]) => void)[]; | |
| } = {}; | |
| emit<Event extends keyof T>(event: Event, value: T[Event]) { | |
| const listeners = this.listeners[event]; | |
| if (listeners) { | |
| listeners.forEach(listener => listener(value)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as te from 'fp-ts/lib/TaskEither'; | |
| import * as arr from 'fp-ts/lib/Array'; | |
| import { pipe } from 'fp-ts/lib/pipeable'; | |
| type TaskEither<A, B> = te.TaskEither<A, B>; | |
| type TERight<T> = T extends TaskEither<any, infer R> ? R : never; | |
| /** | |
| * Transforms an object of `TaskEither`s into a TaskEither of the resolved objects. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add2(a: number, b: number) { | |
| return a + b; | |
| } | |
| function add4(a: number, b: number, c: number, d: number) { | |
| return a + b + c + d; | |
| } | |
| function concat(a: string, b: string) { | |
| return (a + b).length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Lens<RootObject extends object, ChangableObject> { | |
| getter: (x: RootObject) => ChangableObject; | |
| setter: (x: RootObject, newValue: ChangableObject) => RootObject; | |
| static simple<RootObject extends object, T extends keyof RootObject>( | |
| name: T | |
| ) { | |
| return new Lens<RootObject, RootObject[T]>( | |
| x => x[name], | |
| (x, v) => ({ ...x, [name]: v }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| record Ok(O), result : O | |
| record Err(E), error : E | |
| ## hopefully it could have been | |
| # alias Result(O, E) = Ok(O) | Error(E) | |
| ## but it can't | |
| def mytest(i) | |
| if i < 0 | |
| Ok.new(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let pi = 4.0 *. atan(1.0); | |
| type t = | |
| | Radians(float) | |
| | Degrees(float); | |
| let toRadians = d => | |
| switch (d) { | |
| | Radians(d) => Radians(d) | |
| | Degrees(d) => Radians(d *. pi /. 180.) |