Skip to content

Instantly share code, notes, and snippets.

View mpenet's full-sized avatar
🪲
breeding bugs

Max Penet mpenet

🪲
breeding bugs
View GitHub Profile
jQuery.format = function(s, args) {
return s.replace(/\{([^}]+)\}/g, function(_, match){return args[match] || '';});
};
>> $.format('Hello {world}, {again}', {world: "universe", again: "testing"});
"Hello universe, testing"
>> $.format('Hello {0}, {1}', ["foo", "bar"]);
"Hello foo, bar"
var T = function(){ this.t = function(){return 't'} };
T.prototype.tp = function(){return 'tp'};
var inst = new T();
console.log(inst.hasOwnProperty('t'), inst.hasOwnProperty('tp'))
console.log(inst.t(), inst.tp())
>> true false
>> t tp
(defun compile-cljs-on-after-save-hook ()
(add-hook 'after-save-hook
'(lambda ()
(interactive)
(let* ((file-name (buffer-file-name))
(file-name-dir (file-name-directory file-name)))
(if (string-match "\.cljs$" file-name)
(async-shell-command
(concat "cljsc " file-name-dir
;; " '{:optimizations :advanced}' > "
@mpenet
mpenet / gist:1308683
Created October 24, 2011 09:42
cql dsl
(select :user
(limit 100)
(using :consistency :quorum)
(columns [:a :b]
:reversed true
:first 100)
(where
;; simple key lookup
(pk 1)
#!upstart
respawn
start on runlevel [2345]
stop on runlevel [!2345]
script
exec/usr/bin/redis-server > /dev/null 2>&1
end script
@mpenet
mpenet / gist:1672548
Created January 24, 2012 20:55
cute java stacktrace
lamina.core.pipeline -
lamina.core.pipelinejava.lang.IllegalArgumentException: No
implementation of method: :take-contiguous-bytes- of protocol:
#'gloss.data.bytes.core/BufferSequence found for class:
clojure.lang.Cons at
clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:471) at
gloss.data.bytes.core$eval4279$fn__4365$G__4258__4372.invoke(core.clj:38) at
gloss.data.bytes.core$take_contiguous_bytes.invoke(core.clj:67) at
clojure.lang.Var.invoke(Var.java:369) at
gloss.data.string.codecs$take_string_from_buf_seq.invoke(codecs.clj:43) at
mpenet@thinkbox:~$ sudo easy_install clojure-py
[sudo] password for mpenet:
Searching for clojure-py
Reading http://pypi.python.org/simple/clojure-py/
Reading https://github.com/halgari/clojure-py
Best match: clojure-py 0.1.0
Downloading http://pypi.python.org/packages/source/c/clojure_py/clojure_py-0.1.0.tar.gz#md5=794da1e8031e2d4f3fbc6484ed51c172
Processing clojure_py-0.1.0.tar.gz
Running clojure_py-0.1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-yOz8Ho/clojure_py-0.1.0/egg-dist-tmp-P06kvb
Traceback (most recent call last):
@mpenet
mpenet / gist:2053633
Created March 16, 2012 23:42
useful bit from cgrand
(defn scaffold [iface]
(doseq [[iface methods] (->> iface .getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
(doseq [[_ name argcount] methods]
(println
(str " "
@mpenet
mpenet / gist:2220275
Created March 27, 2012 21:11
cute regex
/((?:^|$|[^&\/a-z0-9_ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþş\303\277Ѐ-ӿԀ-ԧⷠ-ⷿꙀ-ꚟᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟々〻]))(#|#)([a-z0-9_ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþş\303\277Ѐ-ӿԀ-ԧⷠ-ⷿꙀ-ꚟᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟々〻]*[a-z_ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþş\303\277Ѐ-ӿԀ-ԧⷠ-ⷿꙀ-ꚟᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟々〻][a-z0-9_ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþş\303\277Ѐ-ӿԀ-ԧⷠ-ⷿꙀ-ꚟᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟々〻]*)/gi
@mpenet
mpenet / gist:2479743
Created April 24, 2012 13:39
lamina maybe pipeline (exits if any stage returns nil)
(defmacro maybe-pipeline [& opts+stages]
(let [[options stages] (split-options opts+stages (meta &form))]
`(pipeline ~@(concat options
(interpose #(if (nil? %)
(complete nil)
%)
stages)))))