Skip to content

Instantly share code, notes, and snippets.

numeronym :: String -> String
numeronym a@(x:[]) = a
numeronym a@(x:y:[]) = a
numeronym x = (head x):(middle x) ++ [last x] where
middle = show . length . init . tail
// lib.rs
pub mod tokenizer {
use std::str::Chars;
// use std::fs::read_to_string;
pub struct WSP<'a> {
text: Chars<'a>,
curr: String,
punc: Option<String>,
module Beer (song) where
import Data.Char (toLower)
song :: String
song = go 99 "" where
go (-1) acc = acc
go n acc = go (n - 1) $ acc ++ (bottleLine n ++ takeOneLine n)
showBottles :: Int -> String
import Control.Monad.State
import qualified Data.Sequence as S
data St = St { offsets :: S.Seq Int
, pos :: Int
, moves :: Int
}
@swizzard
swizzard / lib.rs
Last active August 16, 2017 20:46
cell implementation
use std::collections::HashMap;
#[derive(Debug, Eq, PartialEq)]
struct Cell<'a> {
row: u32,
column: u32,
neighbors: HashMap<Direction, &'a Cell<'a>>,
}
impl<'a> Cell<'a> {
@swizzard
swizzard / pv.clj
Created June 28, 2017 18:53
PVector
(ns noc.pv)
(defprotocol IPVec
(x [x] "get X")
(y [y] "get Y")
(z [z] "get Z"))
(extend-protocol IPVec
clojure.lang.PersistentVector
(x [v] (first v))
@swizzard
swizzard / RenamerMixin.py
Created February 28, 2017 13:35
django rest framework serializer mixin to allow renaming fields on incoming data
class RenamerMixin(serializers.Serializer):
def to_internal_value(self, data):
for key, value in self.renamed.iteritems():
data[value] = data.pop(key)
return super(RenamerMixin, self).to_internal_value(data)
@swizzard
swizzard / SetOn.ts
Created December 21, 2016 20:22
Typescript Set-like that uses provided function to check 'identity'
class SetOn<T> {
contents: T[];
constructor(private identFunction: (a: T) => any, initialContents: T[] = []) {
for (let o of initialContents) {
this.add(o);
}
}
private areEq(a: T, b: T) {
return this.identFunction(a) === this.identFunction(b);
}
@swizzard
swizzard / setup_pgb.sh
Created October 6, 2016 13:16
Bash script + plist to create /var/run/pgbouncer + give it correct perms on boot
# /wherever/setup_pgb.sh
#! /bin/bash
mkdir /var/run/pgbouncer
chown samuelraker:staff /var/run/pgbouncer
# /Library/LaunchDaemons/setup_pgb.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@swizzard
swizzard / mono_maybe.py
Created June 13, 2016 14:09
python Maybe monad :(
def mono(a, b):
"""
Maybe monad-esque reducing function to determine monotonicity
"""
if a is False:
return False
elif a > b:
return False
else:
return b