This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recursive grep: | |
find . -name "*.*" | xargs grep "SEARCH FOR THIS" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConsoleImage | |
def initialize(m, n) | |
@m = m | |
@n = n | |
@colors = Array.new(m * n) | |
clear | |
end | |
def clear |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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] |
OlderNewer