Skip to content

Instantly share code, notes, and snippets.

wget -O ~/deleting_code.mp3 https://dl.dropbox.com/u/2233/deleting_code.mp3
echo '#!/usr/bin/env ruby
deletions = `git diff HEAD --numstat`.lines.to_a.map do |l|
l.split(" ")
end.map do
|(add,del,_)| del.to_i - add.to_i
end.inject(:+).to_i
@jbrechtel
jbrechtel / outline.markdown
Last active December 11, 2015 09:38
Learning to program

Programming basics

Flow control

Variables

Methods

Classes

Scope

Algorithmic complexity (brief)

Ruby basics

Classes

Bundle 'Lokaltog/vim-powerline'
Bundle 'scrooloose/nerdtree'
Bundle 'wincent/Command-T'
Bundle 'benmills/vimux'
Bundle 'jbrechtel/vimux-ruby-test'
Bundle 'tpope/vim-endwise'
Bundle 'edsono/vim-matchit'
Bundle 'vim-ruby/vim-ruby'
Bundle 'mileszs/ack.vim'
Bundle 'desert-warm-256'
(defn cell-state [room x-pos y-pos]
(cond
(> 0 x-pos) :wall
(> 0 y-pos) :wall
(<= (count room) x-pos) :wall
(<= (count room) y-pos) :wall
:else ((room x-pos) y-pos)))
(defn agent-state [room, x-pos, y-pos]
(let [current (cell-state room x-pos y-pos)
(def possible-states [:clean :dirty :wall])
(def state-permutations
(for [north possible-states,
south possible-states,
east possible-states,
west possible-states,
curr possible-states]
{:north north :south south :east east :west west :current curr}))
(defn breed [parent-a parent-b]
(let [breed-index (rand (count parent-a))
transmission-a (take breed-index parent-a)
transmission-b (drop breed-index parent-b)
pure-child (concat transmission-a transmission-b)]
mutate-agent pure-child))
{"mobileview":{"sections":[{"id":0,"text":""},{"toclevel":1,"line":"English","id":1,"text":"<h2><span class=\"mw-headline\" id=\"English\">English<\/span><\/h2>\n<div class=\"sister-wikipedia sister-project noprint floatright\" style=\"border: 1px solid #aaa; font-size: 90%; background: #f9f9f9; width: 250px; padding: 4px; text-align: left;\">\n<div style=\"float: left;\">\n<div class=\"floatnone\"><span class=\"mw-mf-image-replacement\">[Image]<\/span><\/div>\n<\/div>\n<div style=\"margin-left: 60px;\"><a href=\"\/wiki\/Wikipedia\" title=\"Wikipedia\">Wikipedia<\/a> has an article on:\n<div style=\"margin-left: 10px;\"><b class=\"Latn\" lang=\"en\" xml:lang=\"en\"><a href=\"\/\/en.wikipedia.org\/wiki\/This\" class=\"extiw\" title=\"w:This\">This<\/a><\/b><\/div>\n<\/div>\n<\/div>\n<p><span class=\"interProject\"><a href=\"\/\/en.wikipedia.org\/wiki\/This\" class=\"extiw\" title=\"w:This\">Wikipedia<\/a><\/span><\/p>"},{"toclevel":2,"line":"Etymology","id":2,"text":"<h3><span class=\"mw-headline\" id=\"Etymol
@jbrechtel
jbrechtel / foo.txt
Created October 27, 2012 10:59
nth vs last/take
clojoomba.core.runner=> (time (count (nth (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200}) 2)))
"Elapsed time: 133.896 msecs"
20
clojoomba.core.runner=> (time (count (nth (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200}) 2)))
"Elapsed time: 121.748 msecs"
20
clojoomba.core.runner=> (time (count (nth (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200}) 2)))
"Elapsed time: 113.795 msecs"
20
clojoomba.core.runner=> (time (count (last (take 2 (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200})))))
@jbrechtel
jbrechtel / cake.scala
Created September 17, 2012 00:17
really bad cake pattern example
class Foo {
val emailer: EmailService
}
trait Fakes {
val emailer = new FakeEmailService()
}
trait RealThings {
val emailer = new SmtpEmailService()
@jbrechtel
jbrechtel / memoize.clj
Created September 15, 2012 14:54
Confused with memoize
;not sure why this doesn't really memoize the anonymous function call
(defn add [a b] ((memoize (fn [x y] (Thread/sleep 1000) (+ x y))) a b))
;this does correctly memoize the (non anonymous) function call
(defn adds [a b] (Thread/sleep 1000) (+ a b))
(def addf (memoize adds))