Skip to content

Instantly share code, notes, and snippets.

View viebel's full-sized avatar

Yehonathan Sharvit viebel

View GitHub Profile
@viebel
viebel / replace_string_in_files
Last active August 29, 2015 13:56
Replace String in files
find . | xargs grep -wl ugly | xargs sed -i .bak 's/\<ugly\>/nice/g'
@viebel
viebel / nameOfArgs
Created February 27, 2014 15:42
In javascript, retrieve the names of the arguments
function namesOfArgs(fn) {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,
FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m,
FN_ARG_SPLIT = /,/,
fnText = fn.toString().replace(STRIP_COMMENTS, ''),
argDecl = fnText.match(FN_ARGS);
return argDecl[1].split(FN_ARG_SPLIT)
}
@viebel
viebel / get-it.clj
Last active August 29, 2015 13:57
Clojure Macros: get-it, assoc-it
;;First rule of macros: Don't write a macro if you a function can do the job!
(defn assoc-it[obj & more]
(let [path (vec (drop-last 1 more))
val (last more)]
(assoc-in obj path val)))
(assoc-it {:a {:b 6}} :a :b 5 ) ;; {:a {:b 5}}
(defn get-it[obj & path]
@viebel
viebel / js_fun_loop.js
Created August 22, 2012 16:34
javascript: function defined inside a loop
var numbers = [1,2,3];
for (var i = 0, n = numbers.length; i<n; i++) {
var num = numbers[i];
setTimeout(function() {
console.log(num);
}, 0);
}
@viebel
viebel / concatenated_words.clj
Last active November 22, 2015 17:49
given a string, determine whether it is a concatenation of english words
; given a string, determine whether it is a concatenation of english words
; string of digits only is considered an english word
; assume that strings are lower cased
; empty string: don't care
(defn word? [w]
(or (re-matches #"[0-9]" w)
(contains? #{"go" "hi" "my" "cat" "is" "nice" "mymy" "mymymy"} w)))
@viebel
viebel / colums
Last active December 13, 2015 17:59
print columns
column <FILENAME> -ts,
(ns viebel.a8a0349b00689c40571b0faaa36a9ae8.raw.foo)
(defn square [x] (* x x))
(ns viebel.62563c3ad1a09e2fcabe9482972f2ee0.raw.bar
(:require [viebel.a8a0349b00689c40571b0faaa36a9ae8.raw.foo :refer [square]]))
(defn square-square [x] (square (square x)))
@viebel
viebel / color.cljs
Last active May 26, 2016 20:31
color me in red
(ns viebel.gist-368d3bec58d3ec47e935ad488bafb600.raw.color
(:require [viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color :refer [set-bg-color]]))
(set-bg-color "blue")
@viebel
viebel / dump-1464465949284.cljs
Created May 28, 2016 20:05
ClojureScript REPL dump
cljs.user=> (ns my.ns$macros)
nil
my.ns$macros=> (defmacro hello[x] x)
true
my.ns$macros=> (my.ns/hello 19)
19