- 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HaveWant | |
attr_reader :answers | |
def initialize(*have, want) | |
@have = have[0] | |
@args = have[1..-1] | |
@want = want | |
find_matches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colo elflord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Maybe | |
def initialize(value) | |
@value = value | |
end | |
def map(&block) | |
Maybe.new(bind &block) | |
end | |
def bind |