Skip to content

Instantly share code, notes, and snippets.

@colelawrence
colelawrence / GetStarted1_Script.fsx
Created March 28, 2017 17:19
Practicing F-Sharp, very similar to Elixir concepts.
#load "GetStarted1.fs"
open GetStarted1
// https://fsharpforfunandprofit.com/posts/control-flow-expressions/
// https://docs.microsoft.com/en-us/dotnet/articles/fsharp/tour#pipelines-and-composition
// Pattern matching examples
let a,b = 1,2
type Person = {First:string; Last:string}

Keybase proof

I hereby claim:

  • I am colelawrence on github.
  • I am colelawr (https://keybase.io/colelawr) on keybase.
  • I have a public key whose fingerprint is 8370 0CDE B75E 31F7 7605 4CF5 0D82 40E5 138C 1DB1

To claim this, I am signing this object:

@colelawrence
colelawrence / randAlphanum.go
Created August 8, 2018 13:48
Random alpha-numeric rust and golang
func randAlphanum() byte {
// >>> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~<<<
// lowercase 97...122 = 26
// uppercase 65...90 = 26
// numerals 48...57 = 10
// lowercase 0...25, + 97
// uppercase 26...51, + 39
// numerals 52...61, - 4
var val = rand.Intn(62)
if val >= 52 {
@colelawrence
colelawrence / speech-recognition.lua
Last active March 2, 2021 16:56
unknown realtalk sample -- not sure if this would work with current realtalk system, just playing around...
-- Voice recognizer
-- `_ speaking is heard _`
When /person/ speaking is heard /speech/:
-- word { confidence, lowercase, pauses_after }
local words = identify(speech)
-- `_ was asked if they meant _ of _`
When (person) was asked if they meant /option index/ of /possible_choices/,
-- `_ as _ is _`
/yes_or_no/ as (nlp_yes_no(words)) is (not_nil):
@colelawrence
colelawrence / on-scroll.js
Created May 31, 2019 04:54
Passive onscroll event listener
onScroll(window, (scrollX, scrollY) => {
log({ scrollX, scrollY })
})
function onScroll(target: HTMLElement, fn) {
const onscroll = (_evt) => fn(target.scrollX, target.scrollY);
if (supportsPassive()) {
target.addEventListener("scroll", onscroll, { passive: true })
} else {
@colelawrence
colelawrence / scroll-into-view.js
Last active May 31, 2019 05:35
Scroll into view assistant for triggering animations and stuff
const log = console.log.bind(console);
const elts = [].slice.call(document.getElementsByClassName("siv"));
elts.forEach(elt => elt.classList.add("siv-enabled"));
elts.forEach(elt => log(elt, { offset: getOffset(elt) }));
onScroll(window, (scrollX, scrollY) => {
elts.forEach(elt => {
const top = getOffset(elt).top;
@colelawrence
colelawrence / Tree-Sitter-grammar.d.ts
Last active September 19, 2019 20:42
Tree-Sitter "grammar.js" file TypeScript definitions
type Combinator = string | RegExp | any;
type Previous = {
members: RuleMember[];
};
type RuleMember = { name: string };
/**
* Every grammar rule is written as a JavaScript function that takes a parameter conventionally called $. The syntax $.identifier is how you refer to another grammar symbol within a rule.
/**
* Get a single readable and writable value which is persisted into IndexedDB
* @template T
* @param {IDBDatabase | PromiseLike<IDBDatabase>} db
* @param {T} init is used if value does not exist
* @returns {Promise<{
* get: () => Promise<T>,
* set: (value: T) => Promise<void>,
* }>} promise of savable value
const init = Symbol();
const error = Symbol();
/**
* Stream can be thought of like a Promise which can be resolved multiple times.
* Also, a stream does not have a separate channel for errors.
*/
export class Stream<T> {
private listeners = new Set<
[(addValue: T) => any, (rejectError: any) => any]
type LanguageKey = keyof Definitions<any>
let currentLanguage: LanguageKey = "en"
/**
* @param namespace most underlying i18n solutions like to have a namespace
*/
function define<T>(namespace: string, definitions: Definitions<T>): Translate<T> {
// ... set up with your existing translation library which supports fallbacks and such...
return key => `Key (${key}) has no definition`