Skip to content

Instantly share code, notes, and snippets.

View alexpw's full-sized avatar

Alex Walker alexpw

View GitHub Profile
set -g prefix `
bind ` send-prefix
# Use vi or emacs-style key bindings in the status line,
# for example at the command prompt. The default is emacs,
# unless the VISUAL or EDITOR environment variables are set
# and contain the string `vi'.
set -g status-keys vi
set-option -g default-shell /opt/homebrew/bin/fish
@alexpw
alexpw / poll.clj
Last active August 29, 2015 14:18
kathy's sandbox poll fn (quick and dirty)
(defn poll []
(let [opts (atom {})]
(fn [& args]
(if (empty? args)
(when (seq @opts)
(print-table (for [[k v] (reverse (sort-by last @opts))]
{:name k :votes v})))
(doseq [arg args
:when (or (string? arg) (keyword? arg))
:let [arg (keyword arg)]]
@alexpw
alexpw / gist:93ee2082f0cd2a54496d
Created November 21, 2014 21:07
haskell fold/scan reimplementation exercise
module FoldScan where
import Prelude hiding (foldl, foldl', foldl1,
foldr, foldr', foldr1,
scanl, scanl1, scanr, scanr1)
-- (map fn list) -> list
-- map is (1:1) with the original list and returns a copy of a list after applying a fn to each element
@alexpw
alexpw / gist:c229ab22a60c3ac4a5db
Last active August 29, 2015 14:09
ch1 hw - std and tail-call recursion
-- module cis194.ch1 where
-- std
toDigits' :: Integer -> [Integer]
toDigits' = reverse . f
where
f 0 = []
f x = (x `rem` 10) : f (x `div` 10)
@alexpw
alexpw / 2.1.suffix.clj
Created October 28, 2014 17:16
pfds 2.1 suffixes sml
(defn suffixes
"Recursive suffixes"
[xs]
(if-let [xs (seq xs)]
(cons xs (suffixes (rest xs)))
[()]))
(defn suffixes
@alexpw
alexpw / 2.1.suffixes.sml
Created October 28, 2014 17:03
pfds 2.1 suffixes sml
(* use "suffix.sml"; *)
(* input = output *)
(* [1,2,3] = [[1,2,3], [2,3], [3], []] *)
(* std recursion *)
fun suffixes ([]) = [[]]
| suffixes (xs) = xs :: suffixes (tl xs);
(require '[clojure.string :as s])
(defn bool->int
[bool]
(if bool 1 0))
(defn single-char-days
"Translate two-char representation of certain day to one"
[days]
(-> days
@alexpw
alexpw / gist:c44ff885aadfef5c342e
Created August 28, 2014 05:51
xdebug segmentation fault 11; minimal test case
<?php
class F
{
public static $fns = [
'apply' => 'call_user_func_array',
'min' => 'min',
];
public static function __callStatic($method, $args)
@alexpw
alexpw / gist:61619aa5924514d1180a
Last active August 29, 2015 14:05
Example implementation of partial function application and currying in Javascript.
/**
* A partial function applicator.
*/
function partial() {
var fn = arguments[0];
var slice = Array.prototype.slice;
var partialArgs = slice.call(arguments, 1);
return function () {
var args = slice.apply(arguments);
return fn.apply(null, partialArgs.concat(args));
(mapcat (fn [[k coll]] (map vector (repeat k) coll))
[[:a [1 2]] [:b [3 4]]])
=> '([:a 1] [:a 2] [:b 3] [:b 4])