Skip to content

Instantly share code, notes, and snippets.

@andreyshuster
andreyshuster / gist:7887657
Created December 10, 2013 09:01
get object value by passing string
Object.byString = function(o, s) {
s = s.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
s = s.replace(/^\./, ''); // strip a leading dot
var a = s.split('.');
while (a.length) {
var n = a.shift();
if (n in o) {
o = o[n];
} else {
return;
@andreyshuster
andreyshuster / static_counter.js
Created December 8, 2012 20:14
static counter function
var uniqueID = (function() {
var id = 0; // This is the private persistent value
// The outer function returns a nested function that has access
// to the persistent value. It is this nested function we're storing
// in the variable uniqueID above.
return function() { return id++; }; // Return and increment
})(); // Invoke the outer function after defining it.
@andreyshuster
andreyshuster / enable_pry.rb
Created August 22, 2012 12:41
add this to config/envoronments/development.rb to set pry as default rails console
silence_warnings do
begin
require 'pry'
IRB = Pry
rescue LoadError
end
end
@andreyshuster
andreyshuster / *gists*
Created July 17, 2012 13:50
find diffs in hashes
3425198 2012-08-22 12:41:34 public add this to config/envoronments/development.rb to set pry as default rails console
3129493 2012-07-17 13:50:22 public find diffs in hashes