This file contains 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
# http://railstips.org/blog/archives/2009/08/07/patterns-are-not-scary-method-missing-proxy/ | |
class BasicObject #:nodoc: | |
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval/ } | |
end unless defined?(BasicObject) | |
class Proxy < BasicObject | |
def initialize(subject) | |
@subject = subject | |
end |
This file contains 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 Seq | |
def self.unfold(*initial_state, &producer) | |
self.new(*initial_state, &producer) | |
end | |
def take_while(&condition) | |
current, state = @producer.call(@initial_state) | |
seq = [current] | |
while condition.call(current) do |
This file contains 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
resources: { | |
'messages' : { | |
'list' : function(req, resp) { ... } // GET til /messages | |
'get' : function(req, resp, id) { ... } // GET til /messages/id | |
'save' : function(req, resp, id) { ... } // POST til /messages | |
'update' : function(req, resp, id) { ...} // POST til /messages/is | |
} | |
} |
This file contains 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
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> | |
</head> | |
<body> | |
<script language="javascript"> | |
var code = 'var a = c * 3;\nvar b = a + c;'; | |
var script = $('<script />'); | |
script.append('try { ' + code + ' } catch (e) { handleError(e); }'); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
#box { | |
background: green; | |
height: 200px; | |
margin: 20px; | |
width: 200px; | |
-moz-transform: scale(2); /* OK */ |
This file contains 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
require 'parslet' | |
class SimpleExpressionParser < Parslet::Parser | |
rule(:space) { match['\s'].repeat(1) } | |
rule(:space?) { space.maybe } | |
rule(:integer) { match('\d').repeat(1).as(:int) >> space? } | |
rule(:identifier) { match('\w').repeat(1).as(:id) >> space? } | |
rule(:lparan) { str('(') >> space? } |
This file contains 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
final String relevantSkillz = "java, thrift, NoSQL, cassandra, hadoop, voip, TCPIP, SSO, ..."; | |
if (relevantSkillz.contains(developer_skill) | |
&& developer_skill_level >= 31337 | |
&& developer_wants_position_in == DEV_CORE_TEAM | |
&& developer_wants_to == KICK_ASS) { | |
final String improvementsToThisCode = System.in.readLine(); | |
final String subject = "31337 - Elites wanted."; | |
mailto("[email protected]", subject, improvementsToThisCode); |
This file contains 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
# | |
# Wraps the given files inside the following Javascript code for use with | |
# knockout.js: | |
# | |
# $('body').append("<script id=\"<templateId>\" type=\"text/html\"><templateContent></script>"); | |
# | |
# - <templateId> the filename without the extension | |
# - <templateContent> the content of the file, with quotes escaped | |
# | |
for file in "$@"; do |
This file contains 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 fizzbuzz (:use clojure.test)) | |
(defn fizzbuzz [n] | |
(let [ret (str (when (= (rem n 3) 0) "Fizz") | |
(when (= (rem n 5) 0) "Buzz"))] | |
(if (empty? ret) n ret))) | |
(deftest fizzbuzz-test | |
(is (= (fizzbuzz 1) 1)) | |
(is (= (fizzbuzz 2) 2)) |
This file contains 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 chop (:use clojure.test)) | |
(defn chop [n nums] | |
(loop [nums nums offset 0] | |
(if (empty? nums) | |
-1 | |
(let [i (int (/ (count nums) 2)) x (nth nums i)] | |
(cond | |
(= x n) (+ offset i) | |
(> x n) (recur (take i nums) offset) |
OlderNewer