Skip to content

Instantly share code, notes, and snippets.

View tmm1's full-sized avatar

Aman Gupta Karmani tmm1

View GitHub Profile
@mbleigh
mbleigh / Gemfile
Created March 21, 2012 03:14
Non-Rails Rackup with Sprockets, Compass, Handlebars, Coffeescript, and Twitter Bootstrap
source "https://rubygems.org"
gem 'sprockets'
gem 'sprockets-sass'
gem 'sass'
gem 'compass'
gem 'bootstrap-sass'
gem 'handlebars_assets'
gem 'coffee-script'
@authorNari
authorNari / gc-cow.rb
Created March 24, 2012 00:38 — forked from wr0ngway/gc-cow.rb
test to see if GC in ruby 2 is truly copy on write friendly
#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage()
@cypriss
cypriss / action_mailer_no_tmail.rb
Created August 14, 2012 17:32
Use TMail -> Mail gem in Rails 2.3
require 'action_mailer'
require 'mail'
module ActionMailer
class Base
def clean_address(str)
EmailAddress.parse(str, :no_default_name => true).quoted rescue str
end
@alloy
alloy / gist:7527832
Created November 18, 2013 13:39
VIM config to deal with (MRI) Ruby’s C source code indentation.
" These VIM rules match the MRI C indentation rules.
"
" To enable use of this project specific config, add the following to your
" ~/.vimrc:
"
" " Enable per-directory .vimrc files
" set exrc
" " Disable unsafe commands in local .vimrc files
" set secure
anonymous
anonymous / frozen_string.diff
Created November 26, 2013 04:08
diff --git a/compile.c b/compile.c
index 9ff3bf5..306fd80 100644
--- a/compile.c
+++ b/compile.c
@@ -172,10 +172,10 @@ r_value(VALUE value)
(((rb_iseq_t*)DATA_PTR(iseq))->filepath)
#define NEW_ISEQVAL(node, name, type, line_no) \
- new_child_iseq(iseq, (node), (name), 0, (type), (line_no))
+ new_child_iseq(iseq, (node), rb_str_frozen_literal(name), 0, (type), (line_no))

FriendlyId uses Rails's extending method to avoid overwriting your model's find method. Internally this is implemented similar to this:

def self.friendly
  all.extending(friendly_id_config.finder_methods)
end

This however comes with a performance impact, because extending invokes Ruby's extend, which blows away MRI's method cache. To work around this, FriendlyId lets you include a :finders module which overrides your model's find to increase performance.

@protocool
protocool / caveatPatchor.js
Created February 11, 2011 01:00
Sample Propane caveatPatchor.js file
/**
Sample Propane caveatPatchor.js file based on tmm1's avatar hack.
You'll need at least version 1.1.1 to experiment with this:
http://propaneapp.com/appcast/Propane.1.1.1.zip
Once I'm sure exposing this hack-injection point doesn't cause problems
I'll do an official auto-updating version.
As of version 1.1.1, Propane will load and execute the contents of
@tmm1
tmm1 / gist:329682
Created March 11, 2010 21:31
EM Chat Server Demo
require 'rubygems'
require 'eventmachine'
require 'em-http' # gem install em-http-request
require 'yajl' # gem install yajl-ruby
class String
def bold
"\033[1m#{self}\033[0m"
end
end
#import <Foundation/Foundation.h>
@interface KKSimpleAirPlay2Player : NSObject
- (id)initWithURL:(NSURL *)inURL;
- (void)play;
- (void)pause;
@property (readonly, getter=isStopped) BOOL stopped;
@end
@tmm1
tmm1 / bench.rb
Created June 30, 2010 03:12
performance improvements for Bundler and Gem::Version#<=>
require 'rubygems'
# diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb
# index 50d8204..4962ce1 100644
# --- a/lib/rubygems/version.rb
# +++ b/lib/rubygems/version.rb
# @@ -295,12 +295,16 @@ class Gem::Version
# rhsize = other.segments.size
# limit = (lhsize > rhsize ? lhsize : rhsize) - 1
#