Skip to content

Instantly share code, notes, and snippets.

View balinterdi's full-sized avatar

Balint Erdi balinterdi

View GitHub Profile
@balinterdi
balinterdi / clj
Created July 19, 2012 17:28
my current Clojure repl launcher
#!/bin/sh
clj_base="${HOME}/code/clojure";
java -cp .:${clj_base}/lib/jline-0.9.94.jar:${clj_base}/clojure/target/clojure-1.5.0-master-SNAPSHOT.jar:${clj_base}/criterium-0.2.2-SNAPSHOT-standalone.jar:${clj_base}/clojurescript jline.ConsoleRunner clojure.main "$@"
@balinterdi
balinterdi / subset_sum.clj
Created August 15, 2012 11:56
Subset sum
(def sum-of-pos-elements (memoize (fn [xs] (apply + (filter #(>= % 0) xs)))))
(def sum-of-neg-elements (memoize (fn [xs] (apply + (filter #(< % 0) xs)))))
(defn subset-sum
"Returns the indexes of elements in xs whose sum is s"
([xs s]
(subset-sum xs (dec (count xs)) s))
([xs i s]
"Returns the indexes of elements x0...xi (in xs) whose sum is s"
(let [sol (subset-sum xs i s [])]
@balinterdi
balinterdi / .gitignore
Created November 3, 2012 21:39
Solutions to the 4clojure.com problems
repl-port
@balinterdi
balinterdi / ruby_call_class.rb
Created November 5, 2012 16:00
New syntax for calling Class objects in Ruby
# encoding: utf-8
class Greeter
def self.call(language)
new(language)
end
def initialize(language)
@language = language
end
@balinterdi
balinterdi / rails_startup_times
Created November 22, 2012 14:56
Rails startup times
# 1.9.3-p194-perf - GC tweaks
✓ ~/code/sspinc/cartman » time bundle exec rake environment
bundle exec rake environment 5.16s user 1.60s system 95% cpu 7.067 total
✓ ~/code/sspinc/cartman » time bundle exec rake environment
bundle exec rake environment 5.23s user 1.57s system 95% cpu 7.113 total
# 1.9.3-p194-perf - No GC tweaks
✓ ~/code/sspinc/cartman » time bundle exec rake environment
bundle exec rake environment 6.60s user 1.44s system 98% cpu 8.157 total
» time bundle exec rake environment
@balinterdi
balinterdi / group_by_reducers.clj
Created December 7, 2012 09:15
Implement group-by with reducers
(ns group-by-reducers.core
(:require [clojure.core.reducers :as r :only [fold reduce map]])
(:require [criterium.core :as c]))
(defn group-by-naive [f coll]
(reduce
(fn [groups a]
(assoc groups (f a) (conj (get groups a []) a)))
{}
coll))
(ns benchmark-assoc.core
(:require [criterium.core :as crit]))
(defn no-assoc [items]
(apply hash-map (vec (flatten items))))
(defn assoc-all [items]
(apply assoc {} (vec (flatten items))))
(defn assoc-each-one [items]
@balinterdi
balinterdi / gist:5213779
Last active December 15, 2015 06:09
Trying to find a way to resubmit a form with a model that has become invalid. The transaction cannot be reused and the dirty model cannot be moved to another transaction since it is dirty.
becameInvalid: ->
@get('transaction').remove(this)
transaction = App.store.transaction()
transaction.add(this) # => Uncaught Error: assertion failed: Once a record has changed, you cannot move it into a different transaction
@balinterdi
balinterdi / controlGroup.handlebars
Created March 27, 2013 21:19
Example view with layout in ember.js
<label class="control-label">{{ view.label }}</label>
<div class="controls">
{{ yield }}
</div>