Skip to content

Instantly share code, notes, and snippets.

View dinks's full-sized avatar

Dinesh Vasudevan dinks

View GitHub Profile
@dinks
dinks / gebc.js
Last active December 25, 2015 10:29
Get Elements by Clazz
var getEByClass = function (_) {
var regExp = new RegExp("\\b" + _ + "\\b", ""),
elements = [];
var clazz = function (e) {
return e.className || "";
};
var getAll = function (context) {
var c = clazz(context);
@dinks
dinks / Flip-Clock-Javascript.markdown
Created October 21, 2013 21:20
A Pen by Dinesh Vasudevan.
@dinks
dinks / Public-Gists-Viewer.markdown
Created October 22, 2013 15:07
A Pen by Dinesh Vasudevan.
@dinks
dinks / combined_enumerator_test.rb
Created October 24, 2013 09:38
The aim of this class is to take a number of ordered enumerators and then emit their values in ascending order.
# The aim of this class is to take a number of ordered enumerators and then
# emit their values in ascending order.
#
# Some assumptions:
# * The enumerators passed in emit their values in ascending order.
# * The enumerators emit values which are Comparable[1] with each other.
# * The enumerators can be finite *or* infinite.
#
# This requires Ruby 1.9. The Enumerator[2] documentation might be useful.
#
@dinks
dinks / r_with_mav.txt
Last active December 26, 2015 11:09
Rails with Mavericks
I tried doing a bundle install with rails and had immediate problems like
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/dineshvasudevan/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for random()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
..
@dinks
dinks / test.rb
Created November 2, 2013 14:23
instance_eval -- instance_exec -- class var
# encoding: utf-8
class Person
code = proc { puts self }
code2 = proc { |greet| puts "#{greet} #{self}" }
define_method :name do
self.class.instance_eval &code
@dinks
dinks / black_white.rb
Created November 2, 2013 22:27
Hash Blacklist and Whitelist
class Hash
def except(*blacklist)
reject {|key, value| blacklist.include?(key) }
end
def only(*whitelist)
reject {|key, value| !whitelist.include?(key) }
end
end
@dinks
dinks / monpat_unserialize_active_record.rb
Created November 4, 2013 11:40
Unserialize With Encoding Monkey Patch
# From http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3
class ActiveRecord::Base
def unserialize_attribute_with_utf8(attr_name)
traverse = lambda do |object, block|
if object.kind_of?(Hash)
object.each_value { |o| traverse.call(o, block) }
elsif object.kind_of?(Array)
object.each { |o| traverse.call(o, block) }
else
block.call(object)
@dinks
dinks / .bashrc
Created November 10, 2013 16:50
ssh autocomplete
SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq) )
complete -o default -W "${SSH_COMPLETE[*]}" ssh
@dinks
dinks / production.rb
Created November 14, 2013 16:45
OpenShift for Rails 4 Logging
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(File.join(ENV['OPENSHIFT_RUBY_LOG_DIR'], "production-#{Time.now.strftime('%Y%m%d')}.log")))