Skip to content

Instantly share code, notes, and snippets.

View TomTriple's full-sized avatar

TomTriple TomTriple

  • Germany, near Munich
View GitHub Profile
(defmacro env-is
[ & env-with-action]
`(some #(if (= (first %) "test") (second %) false)
(partition 2 ~env-with-action)))
(println (env-is
"test" #(+ 1 2)
"prod" run-production))
(ns mytwitter.core
(:require [clojure.browser.event :as event]
[clojure.browser.dom :as dom]))
(def button (dom/get-element "button"))
(def profile (dom/get-element "profile"))
(def tweets (dom/get-element "tweets"))
(defn alert [mess]
(.alert js/window mess))
@TomTriple
TomTriple / gist:1031281
Created June 17, 2011 11:56
ActiveRecord::PostgreSQLAdapter#result_as_array
# create a 2D array representing the result set
def result_as_array(res) #:nodoc:
#
# check if we have any binary column and if they need escaping
ftypes = Array.new(res.nfields) do |i|
[i, res.ftype(i), res.fname(i)]
end
rows = res.values
typehash = ftypes.group_by { |_, type| type }
@TomTriple
TomTriple / gist:1001095
Created May 31, 2011 19:17
recursive grep:
recursive grep:
find . -name "*.*" | xargs grep "SEARCH FOR THIS"
# See Mike Perham's proposal on ticket: https://rails.lighthouseapp.com/projects/8994/tickets/6477-activemodel-transformations
# Chainable Transformations API
require "active_support/core_ext/string/inflections"
require "active_support/concern"
module ActiveModel
module Transformers