Skip to content

Instantly share code, notes, and snippets.

Yehonathan Sharvit viebel

Block or report user

Report or block viebel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
viebel / js_fun_loop.js
Created Aug 22, 2012
javascript: function defined inside a loop
View js_fun_loop.js
var numbers = [1,2,3];
for (var i = 0, n = numbers.length; i<n; i++) {
var num = numbers[i];
setTimeout(function() {
}, 0);
viebel / to_hash.rb
Last active Jun 20, 2016
ruby array to hash
View to_hash.rb
class Array
def to_hash(&block)
Hash[* {|x|
[1,2,3].to_hash {|x|
viebel / colums
Last active Dec 13, 2015
print columns
View colums
column <FILENAME> -ts,
viebel / regex_as_a_function.cljs
Last active Jun 10, 2016 — forked from alandipert/reinvoke.cljs
Make a regex behave like a function
View regex_as_a_function.cljs
; Make a regex behave like a function
; Inspired by:
(extend-type js/RegExp
(-invoke ([this s] (re-find this s))))
(#"clojure" "clojurescript")
viebel / replace_string_in_files
Last active Aug 29, 2015
Replace String in files
View replace_string_in_files
find . | xargs grep -wl ugly | xargs sed -i .bak 's/\<ugly\>/nice/g'
viebel / nameOfArgs
Created Feb 27, 2014
In javascript, retrieve the names of the arguments
View nameOfArgs
function namesOfArgs(fn) {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,
FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m,
fnText = fn.toString().replace(STRIP_COMMENTS, ''),
argDecl = fnText.match(FN_ARGS);
return argDecl[1].split(FN_ARG_SPLIT)
viebel / get-it.clj
Last active Aug 29, 2015
Clojure Macros: get-it, assoc-it
View get-it.clj
;;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 / concatenated_words.clj
Last active Nov 22, 2015
given a string, determine whether it is a concatenation of english words
View concatenated_words.clj
; 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 / color.cljs
Last active May 26, 2016
color me in red
View color.cljs
(ns viebel.gist-368d3bec58d3ec47e935ad488bafb600.raw.color
(:require [viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color :refer [set-bg-color]]))
(set-bg-color "blue")
View body_color.cljs
(ns viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color)
(defn set-bg-color [c]
(set! (.. js/document -body -style -backgroundColor) c))
(defn set-bg-color-element [e c]
(set! (.. e -style -backgroundColor) c))
You can’t perform that action at this time.