Skip to content

Instantly share code, notes, and snippets.

@elarkin
elarkin / proof.c
Last active December 13, 2015 18:29
If statements introduce scope.
#include <stdio.h>
int main()
{
int foo = 4;
if(1) {
int foo = 5;
printf("%i", foo);
}
printf("%i", foo);
}
@elarkin
elarkin / gist:4964461
Created February 15, 2013 23:27
ruby 1.9.* does not respect respond_to? :to_ary when calling flatten
def test_config klass
var = klass.new
unless !var.respond_to?(:to_ary) && [var].flatten == [var]
puts "#{klass.name} is misbehaved"
end
end
class RespondToMissingTest
def respond_to_missing? method, *rest
if method.to_sym == :to_ary
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
def render_message(template, phone)
url_split_thang = UrlShrotenerClient.tokenize(template)
url_split_thang.map do |obj|
if obj.url?
template = Liquid::Template.parse(obj.template)
edit(template).render(message_variable_values(phone), filters: [LiquidFilters])
else
Liquid::Template.parse(obj.template).render...
end
@elarkin
elarkin / something.clj
Created July 19, 2013 14:13
answer a question
(ns something.something
[:import [javax.xml.validation SchemaFactory Validator]
[javax.xml.transform.stream StreamSource]])
(defn something []
(let [factory (SchemaFactory/newInstance "http://www.w3.org/2001/XMLSchema")
file (clojure.java.io/file "simple.xsd")
schema (.newSchema factory file)
validator (.newValidator schema )
stream-source (StreamSource. "simple-err.xml")]
@elarkin
elarkin / something2.clj
Created July 19, 2013 14:18
answer a question
(ns something.something
[:import [javax.xml.validation SchemaFactory Validator]
[javax.xml.transform.stream StreamSource]])
(defn something []
(let [factory (SchemaFactory/newInstance "http://www.w3.org/2001/XMLSchema")
file (clojure.java.io/file "simple.xsd")
stream-source (StreamSource. "simple-err.xml"]
(-> (.newSchema factory file)
(.newValidator)
@elarkin
elarkin / defn.clj
Created February 3, 2014 15:08
Clojure defn
(defn foo [a] a)
(defn foo
([a] a)
([a b] a))
'(defn (foo a) a)
'(defn ((foo a) a)
((foo a b) a))
@elarkin
elarkin / OMG.rb
Last active August 29, 2015 14:03
Ruby off the deep end
class Foo
def method_missing(*args)
puts("Called with: #{args.inspect}")
4
end
end
class Bar < Foo
def respond_to?(*args)
super
@elarkin
elarkin / upgrade_mdb.sh
Last active August 29, 2015 14:03
Update MobileDB
#!/bin/bash
#Fill these out, make sure there is no space immediately after the = signs
MOBILEDB_PATH=....
SECURITY_SERVICES_PATH=....
PSQL_USER=....
#Upgrade Security Services
cd $SECURITY_SERVICES_PATH
git pull --ff-only
@elarkin
elarkin / anagrams.clj
Created July 23, 2014 20:21
Anagram Detection in Clojure
(ns clojure-anagram.core
(:use [clojure [string :only [split-lines join]]]))
(def words (-> "/Users/you-will-never-guess/misc-src/anagram-jam/4000words.txt"
slurp
split-lines))
(defn single-word-anagrams-for [word]
(let [normalized-word (sort word)]
(filter #(= (sort %) normalized-word) words)))