Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
@deepak
deepak / rakefile_extract_fixtures.rb
Created February 3, 2011 08:59
generate fixtures from actual data in database
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
@deepak
deepak / how-typescript-won.md
Created January 30, 2024 09:44
How/Why did TypeScript beat Flow
@deepak
deepak / logging.rb
Created July 6, 2010 08:47
benchmarking logging in ruby using syslog and bufferredlogger
#!/usr/bin/env ruby
# NOTE: does not make sense to measure for large iterations, only as
# much as the logging being done on rails request, it is not as if on
# on a request 10K logging is done. With 50 logging statements i would
# prefer syslog
# NOTE: Also in buffered and syslog the
# log can get lost but logger is more reliable
# TODO: measure IO perf, if syslog logs on remote the io cost will be
@deepak
deepak / gist:5933685
Created July 5, 2013 10:40
Set ENV in Dockerfile with string interpolation
# DOCKER-VERSION 0.4.8
FROM ubuntu:12.04
# install essentials
RUN apt-get install -y -q git
# Install rbenv
RUN git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv
RUN echo '# rbenv setup' > /etc/profile.d/rbenv.sh
@deepak
deepak / get all constants in a rails project.rb
Created October 11, 2012 11:46
get all constants in a rails project
require 'pp'
Dir["#{RAILS_ROOT}/app/models/*.rb"].each { |model_path| require model_path }
models = Module.constants.select do |constant_name|
begin
constant = eval constant_name.to_s
next if constant.nil?
match = (constant < ActiveRecord::Base) rescue nil
if match
@deepak
deepak / install-mit-schema-for-SICP.md
Last active May 10, 2021 19:51
installing MIT-scheme for doing SICP

installing MIT Schema

The SICP page recommends MIT scheme,
so that is what we will use

to install it, on Apple OSX using Homebrew:

  brew tap x11
  brew cask install xquartz
@deepak
deepak / wget-list.sh
Created January 24, 2011 06:48
wget-list: manage the list of downloaded files
#!/bin/sh
# wget-list: manage the list of downloaded files
# invoke wget-list without arguments
# http://www.linux.com/feature/59457
# http://ubuntuforums.org/showthread.php?t=672074
# http://www.lifehack.org/articles/lifehack/make-your-idle-computer-work-for-you.html
# http://decafbad.net/projects/scripts
# http://www.google.co.in/search?q=wget+queue&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a
@deepak
deepak / Dockerfile
Last active March 6, 2020 06:01
Dockerfile for installing ruby using rbenv
# DOCKER-VERSION 0.4.8
# am facing issue
# https://github.com/dotcloud/docker/issues/1123
FROM ubuntu:12.04
MAINTAINER Deepak Kannan "deepak@codemancers.com"
RUN apt-get -y install python-software-properties
@deepak
deepak / ruby_thread_parent.rb
Created November 1, 2010 11:30
keep track of the parent of a ruby thread.rb
T0 = Thread.main
t1 = Thread.new(Thread.current) { |x| Thread.current[:parent] = x; sleep 1_00_000; }
t2 = Thread.new(Thread.current) { |x| Thread.current[:parent] = x; sleep 1_00_000; }
(t1[:parent] == t2[:parent]) && (t1[:parent] == T0)
__END__
# to find out the parent of a thread, ie. was spawned by which thread
@deepak
deepak / ruby_ping.rb
Last active May 6, 2019 01:47
ruby ping
# let us say you want to check if a host is reachable
# sometimes you need to be behind a private VPN or the host is just down
# and you want to do this on your local-machine and on Heroku
# can open your terminal and use ping on your local
# And can get a bash shell on Heroku as well - by `heroku run bash`
# but there is no `ping` binary there
# ```bash