Skip to content

Instantly share code, notes, and snippets.

View isaacsanders's full-sized avatar

Isaac Sanders isaacsanders

View GitHub Profile
(defn build-id3-tree
"Builds an ID3 Decision tree to find target-attr based on the examples"
[examples target-attr attributes]
(cond
(same? target-attr examples) { :label (target-attr (first examples)) }
(empty? attributes) { :label (most-common target-attr examples) }
:else (let [attr (max-val #(information-gain % examples) attributes)
groups (group-by attr examples)
child-agent (agent {})]
(loop [[value subset] (first groups)
@isaacsanders
isaacsanders / closure.rb
Created August 30, 2013 19:33
An naïve implementation of a Closure object in Ruby
class Closure
attr_reader :formals, :bodies, :env
def initialize(formals, bodies, env)
@formals = Array(formals)
@bodies = Array(bodies)
@env = env
end
def call(*args)
raise argument_error(args) if args.length != formals.length
@isaacsanders
isaacsanders / woes.txt
Created June 16, 2013 19:57
my ri woes
$ ri Faraday::Middleware
/Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/store.rb:196:in `load': instance of RDoc::Context::Section needs to have method `marshal_load' (TypeError)
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/store.rb:196:in `block in load_class'
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/store.rb:195:in `open'
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/store.rb:195:in `load_class'
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/driver.rb:609:in `block in classes_and_includes_for'
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/driver.rb:607:in `map'
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.12.2/lib/rdoc/ri/driver.rb:607:in `classes_and_includes_for'
from /Users/isaac/.rvm/gems/ruby-2.0.0-p195@chicago_ideas/gems/rdoc-3.
define_method :foo do |bar, &block|
block.call(bar)
end
@isaacsanders
isaacsanders / namespace.rb
Created March 1, 2013 21:28
Namespace code
namespace "Foo::Bar" do
# Define methods in here.
# `namespace` defines modules all the way down,
# or classes if the constant is already defined.
end
@isaacsanders
isaacsanders / web.hs
Created February 27, 2013 21:43
Type signatures for web interaction
adminDashboard :: User -> Page
adminDashboard Admin user = dashboardPage
adminDashboard _ = unauthorizedPage
homePage :: User -> Page
homePage Admin user = adminHomePage
homePage Member user = memberHomePage
homePage _ = signInPage
@isaacsanders
isaacsanders / gist:5034024
Created February 25, 2013 22:44
SERIOUSLY WTF HAPPENED!
$ ruby
Could not find i18n-0.6.1 in any of the sources
Run `bundle install` to install missing gems.
@isaacsanders
isaacsanders / mkmf.log
Last active December 14, 2015 04:18
The output from `rvm install ruby --debug`
=== OpenSSL for Ruby configurator ===
=== Checking for system dependent stuff... ===
have_library: checking for t_open() in -lnsl... -------------------- no
"/usr/local/bin/gcc-4.2 -o conftest -I../../.ext/include/x86_64-darwin12.2.0 -I../.././include -I../.././ext/openssl -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/opt/local/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libxml2/include -I/usr/local/opt/libxslt/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/curl-ca-bundle/include -I/usr/local/opt/sqlite/include -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -pipe conftest.c -L. -L../.. -L/opt/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/op
%W{ X - O
- X -
O - X }
@isaacsanders
isaacsanders / RubeGoldbergSearch.java
Created January 16, 2013 05:49
Any thoughts on making this even more awful?
public static int search(Integer[] arriArrayToBeSearched, Integer iItemToBeFoundInArray){
int iIndexOfItemToBeFoundInArrayInArrayToBeSearched = -1;
int iLengthOfArrayToBeSearched = 0;
int iTemporaryVariable = arriArrayToBeSearched.length;
while (iTemporaryVariable > 0) {
iLengthOfArrayToBeSearched += 1;
iTemporaryVariable -= 1;
}
for (int indexInArrayToBeSearched = 0; indexInArrayToBeSearched < iLengthOfArrayToBeSearched; indexInArrayToBeSearched += 1) {
Integer iMemberOfArrayToBeSearchedAtCurrentIndex = arriArrayToBeSearched[indexInArrayToBeSearched];