Skip to content

Instantly share code, notes, and snippets.

View davidkellis's full-sized avatar

David Ellis davidkellis

View GitHub Profile
C# program:
using System;
using System.Threading.Tasks;
namespace Scratch
{
class Program
{
static void Main()
0 * 0 = 0 5 * 0 = 0
0 * 1 = 0 5 * 1 = 5
0 * 2 = 0 5 * 2 = 10
0 * 3 = 0 5 * 3 = 15
0 * 4 = 0 5 * 4 = 20
0 * 5 = 0 5 * 5 = 25
0 * 6 = 0 5 * 6 = 30
0 * 7 = 0 5 * 7 = 35
0 * 8 = 0 5 * 8 = 40
0 * 9 = 0 5 * 9 = 45
package truthy
interface Truthy for T {
fn truthy?(T) -> Boolean
}
def ||[A: Truthy, B: Truthy](a: A, b: B): A | B => truthy?(a) ? a : b
def &&[A: Truthy, B: Truthy](a: A, b: B): A | B => truthy?(a) ? a : b
def !(a: Truthy): Boolean => !a.truthy?
fn slowAdd(x: Int, y: Int) -> Int {
sleep(2.seconds)
x + y
}
// main1 takes 4 seconds to run
fn main1() {
a = slowAdd(1, 2)
b = slowAdd(10, 20)
puts(a + b)
interface Enumerable T for E {
fn each(E, T -> Unit) -> Unit
}
impl Enumerable T for Array T {
fn each(array: Array T, f: T -> Unit) -> Unit { ... }
}
impl Enumerable T for I : Iterator T {
fn each(it: I, visit: T -> Unit) = ...
}
impl Enumerable T for Iterator T {
@davidkellis
davidkellis / gist:e1b9b5e6e406a47dfc0744114b6a77ca
Last active September 2, 2017 04:21
interfaces extreme 1
interface Enumerable T for E {
fn each(E, T -> Unit) -> Unit
}
impl Enumerable T for Array T {
fn each(array: Array T, f: T -> Unit) -> Unit { ... }
}
impl Enumerable T for I : Iterator T {
fn each(it: I, visit: T -> Unit) = ...
}
impl Enumerable T for Iterator T {
@davidkellis
davidkellis / gist:f90febaec142b7acad39a0621ea45a40
Last active September 2, 2017 03:51
interface examples that need to play nice together
interface Enumerable T for E {
fn each(E, T -> Unit) -> Unit
}
impl Enumerable T for Array T {
fn each(array: Array T, f: T -> Unit) -> Unit { ... }
}
impl Enumerable T for I : Iterator T {
fn each(it: I, visit: T -> Unit) = ...
}
impl Enumerable T for Iterator T {
package hashids
MinAlphabetLength = 16
SepDiv = 3.5
GuardDiv = 12
DefaultAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
DefaultSeps = "cfhistuCFHISTU"
struct Encoder {
// I found the following implementation (verbatim) of Fibers in Go at https://play.golang.org/p/NSIlZ327sC
// I'm capturing it here for future reference.
package main
import (
"errors"
"fmt"
)
@davidkellis
davidkellis / gist:909449e13905d8bfbd49c30d20f7fbca
Last active September 7, 2017 13:35 — forked from silviorelli/gist:ad8e1d80bdc0245eb7e7
Install Ruby 1.8.7 on macOS Sierra (10.12) with rbenv
brew install apple-gcc42 openssl libyaml libffi
xcode-select --install
export CC=/usr/local/bin/gcc-4.2
export CFLAGS='-g -O2'
export RUBY_CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl`
export CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl`
# I had to edit the svn repo URL in /usr/local/Cellar/ruby-build/20160913/share/ruby-build/1.8.7-p375 and change the URL from http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7 to https://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7
rbenv install 1.8.7-p375