Skip to content

Instantly share code, notes, and snippets.

View TomTriple's full-sized avatar

TomTriple TomTriple

  • Germany, near Munich
View GitHub Profile
# 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
@TomTriple
TomTriple / gist:1001095
Created May 31, 2011 19:17
recursive grep:
recursive grep:
find . -name "*.*" | xargs grep "SEARCH FOR THIS"
@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 }
(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))
(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))
@TomTriple
TomTriple / gist:1304235
Created October 21, 2011 16:13
java <-> jruby
include Java
include_class "java.util.ArrayList"
list = ArrayList.new
block = Proc.new do
add "entry 1"
add "entry 2"
end
list.instance_eval &block
pp list.get(1)
class ConsoleImage
def initialize(m, n)
@m = m
@n = n
@colors = Array.new(m * n)
clear
end
def clear
def sendPdf(htmlContent: String, filename: String) = {
val os = new java.io.ByteArrayOutputStream
val renderer = new ITextRenderer
renderer.setDocumentFromString(htmlContent)
renderer.layout
renderer.createPDF(os)
val bytes = os.toByteArray()
os.flush()
@TomTriple
TomTriple / combinator_db_results.scala
Created November 12, 2016 14:37
scala combinator library for db results
// 1. combinator library for transforming and combining sql results to query result models
// 2. usage of library resides at the bottom of this gist
package object mapping {
type Mapper[+A] = String => A
type ToValueClass[+A] = Long => A
@TomTriple
TomTriple / combinator_android_validation.scala
Last active November 12, 2016 14:43
combinator library android validation
// the highlevel validation combinators reside at the bottom of this gist e.g. "def crown" or "def trunk"
protected object Validation {
sealed abstract class VRes[+A]
case class Vok[+A](get:A) extends VRes[A]
case class Verr(err:String) extends VRes[Nothing]
type V[+A] = TextView => VRes[A]