Skip to content

Instantly share code, notes, and snippets.

fn main() {
let xs: Vec<Box<dyn PrintableNumber>> = vec![Box::new(Foo), Box::new(Bar)];
print_each(xs);
}
struct Foo;
struct Bar;
// Combined trait that requires both ToString and ToInt
trait PrintableNumber: ToString + ToInt {}
letterChar : Char -> Boolean
letterChar c = List.contains c <| toCharList "abcdefghijklmnopqrstuvwxyz"
groupAnswers : Text -> Map Char Nat
groupAnswers gr =
combine : Map Char Nat -> Char -> Map Char Nat
combine accMap c =
if letterChar c then
use Nat +
putWith (+) c 1 accMap
/**
* Observable version of the above
*/
function drawRectsObservable() {
// implement this function!
const svg = document.getElementById("drawRects")!,
mousedown = Observable.fromEvent<MouseEvent>(svg, 'mousedown'),
mousemove = Observable.fromEvent<MouseEvent>(svg, 'mousemove'),
mouseup = Observable.fromEvent<MouseEvent>(svg, 'mouseup'),
class Observable<Input> {
// ... SNIP
/** Create two new observables, where one contains only those inputs for which the condition
* holds, and the other contains only those for which the condition does not hold
*/
splitBy(condition: (_:Input)=>boolean): [Observable<Input>, Observable<Input>] {
const yes = this.filter(condition);
const no = this.filter(i => ! condition(i));
@sullyj3
sullyj3 / sort_gen.c
Last active August 30, 2015 14:07
Something horrifying I created as an extension exercise my first semester learning C.
#include <stdio.h>
void print_prototype(int num_elements);
void print_func(int num_elements);
void sort_func_generator(int num_elements);
int main(int argc, char *argv[]) {
int num_ints;
scanf("%d", &num_ints);
sort_func_generator(num_ints);
@sullyj3
sullyj3 / hybrid_loop.py
Created July 5, 2014 07:44
suggestion for an additional for-loop structure.
#######################################
# suggestion for an additional for-loop structure.
#######################################
for x in y while condition:
do_stuff()
# as syntax sugar for:
for x in y:
def checkio(text):
nopunc=""
alph="abcdefghijklmnopqrstuvwxyz"
for char in text:
if char.lower() in alph:
nopunc+=char.lower()
maxcount=1
mostfreq=""