Skip to content

Instantly share code, notes, and snippets.

View domgetter's full-sized avatar

Dominic Muller domgetter

View GitHub Profile

Vocabulary of functional programming

  • first-class function
    • when you can store a function in a variable
  • anonymous function
    • a function without a name
  • closures and pure functions
    • closure - function with at least one free variable (variable defined elsewhere)
    • pure function - a function where the variables are bound to the function's scope
  • also, a function that always returns the same output for some input
@domgetter
domgetter / havewant.rb
Last active August 3, 2016 20:19
Will tell you what Ruby method(s) you want given the input and output Now works with arguments!
class HaveWant
attr_reader :answers
def initialize(*have, want)
@have = have[0]
@args = have[1..-1]
@want = want
find_matches
class Thread
class TimeoutError < StandardError; end
def self.timeout(n)
temp_queue = Queue.new
work_thread = Thread.new { temp_queue << {return: yield} } # wrapping in a hash guarantees uniqueness of output
timeout_thread = Thread.new { sleep n; temp_queue << :timeout }
if (ret_val = temp_queue.pop) == :timeout # this pop is blocking, so it either waits on the yield or the timeout
work_thread.kill
raise TimeoutError
@domgetter
domgetter / definitions.txt
Last active June 10, 2016 17:15
Programming Definitions
Set: Unordered list of unique elements.
Array: Ordered list of elements.
HashMap: Unordered list of key-value pairs where the keys are unique.
(Note: this has many different names.
Hash in Ruby, Perl
Dictionary in Python (keys must be immutable)
Object in Javascript (value functions can introspect)
Map in Clojure
HashMap in Java
Associative Array in PHP,Perl,Wikipedia
vi
automating actions through repetition and composition
with strengths to ubiquity and use through the terminal
"programmable editing"
emacs
extensibility by way of the power of lisp
make the editor do everything that you want in the way you want
make these functionalities easy to put in and pull out
a truly "programmable" editor
colo elflord
require 'chunky_png' # viewable at: http://i.imgur.com/C9Utu2N.png
palette = ["X","O","#","*","o","%","=","-","."]
puts ChunkyPNG::Image.from_file("poke_red.png").pixels.map {|p| p/256 % 256}.each_slice(160).map {|r| r.map {|n| palette[9-n/10*100/256]}.join("") }.join("\n")
=begin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@domgetter
domgetter / install-tmux
Last active March 15, 2016 01:13 — forked from rothgar/install-tmux
Install tmux 1.9 on rhel/centos 6
# Install tmux on Centos release 6.5
# install deps
yum install gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local
@domgetter
domgetter / maybe_monad.java
Last active February 14, 2016 14:45
An implementation of the Maybe monad in Java for instructional purposes.
import java.util.function.Function;
// Maybe is a monad. Why is it a monad? It is a monad because it:
// A) wraps a value
// B) provides a way of applying functions/calling methods on the wrapped value
// C) always returns an instance of itself when it does this.
class Maybe<T> {
private T value;
public Maybe(T value) {
class Maybe
def initialize(value)
@value = value
end
def map(&block)
Maybe.new(bind &block)
end
def bind