Skip to content

Instantly share code, notes, and snippets.

@arkiver
arkiver / regex_indian_simple_mobile_number
Last active December 14, 2015 09:09
Regex for JS validation of Indian mobile number (without country code prefixed)
/^[0]?[789]\d{9}$/
Matches
09878767656
or
9878767656
or
7898987656
@arkiver
arkiver / git_filter_branch_change_author_email
Created May 18, 2013 16:22
Snippet to change git author name and email (In case you commit using your work credentials)
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "akshay.khole@work-email-address.com" ]
then
cn="Akshay Khole"
@arkiver
arkiver / ruby_em_pub_sub.rb
Last active December 19, 2015 17:49
A simple pub sub system in ruby. Using event machine
# server.rb
require 'eventmachine'
# An event can be anything, rss feed, tweet, etc
class Event
attr_reader :event_attributes
def initialize(event = [])
@event_attributes = event
end
@arkiver
arkiver / ruby_pub_sub.rb
Last active December 19, 2015 17:58
Simple ruby pub sub system
# server.rb
require 'socket'
require 'debugger'
# An event can be anything, rss feed, tweet, etc
class Event
attr_reader :event_attributes
def initialize(event = [])
@event_attributes = event
end
@arkiver
arkiver / rename_file_extensions.rb
Created October 2, 2013 17:03
Change extensions of all files in a directory
require 'fileutils'
Dir.glob("#{Dir.pwd}/path/to/folder/*.html.erb").map{|f| FileUtils.mv f, f.gsub('.erb', '') + '.haml'}
@arkiver
arkiver / stop_words.rb
Created October 7, 2013 11:12
Common stop words(/characters)
STOP_WORDS = ["the", "be", "and", "of", "a", "in", "to", "have", "to", "it", "I", "that", "for", "you", "he", "with", "on", "do", "say", "this", "they", "at", "but", "we", "his", "from", "that", "not", "n't", "n't", "by", "she", "or", "as", "what", "go", "their", "can", "who", "get", "if", "would", "her", "all", "my", "make", "about", "know", "will", "as", "up", "one", "time", "there", "year", "so", "think", "when", "which", "them", "some", "me", "people", "take", "out", "into", "just", "see", "him", "your", "come", "could", "now", "than", "like", "other", "how", "then", "its", "our", "two", "more", "these", "want", "way", "look", "first", "also", "new", "because", "day", "more", "use", "no", "man", "find", "here", "thing", "give", "many", "well", "only", "those", "tell", "one", "very", "her", "even", "back", "any", "good", "woman", "through", "us", "life", "child", "there", "work", "down", "may", "after", "should", "call", "world", "over", "school", "still", "try", "in", "as", "last", "ask", "need", "too", "
@arkiver
arkiver / spreadsheet.js
Created November 14, 2013 06:30
Spreadsheet program in under 30 lines of JavaScript
//Written by: http://ondras.zarovi.cz/
//http://jsfiddle.net/ondras/hYfN3/
// <p>Inspired by <a href="http://thomasstreet.net/blog/spreadsheet.html">http://thomasstreet.net/blog/spreadsheet.html</a>. Features:</p>
// <ul>
// <li>Under 30 lines of vanilla JavaScript</li>
// <li>Libraries used: <strong>none</strong></li>
// <li>Excel-like syntax (formulas start with "=")</li>
// <li>Support for arbitrary expressions (=A1+B2*C3)</li>
@arkiver
arkiver / unicorn_redis_rescue_heroku.rb
Created November 25, 2013 07:55
Unicorn, Redis, Rescue config for Heroku
# /initializers/redis.rb
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
# /initializers/resque.rb
Resque.redis = REDIS
# unicorn.rb
@arkiver
arkiver / header_for.rb
Last active December 31, 2015 03:08
Header for method devise invitable
User.invite!({:email => "new_user@example.com", :name => "name one"}, User.first)
def headers_for(action)
headers = {}
case action
when :invitation_instructions
headers.merge!({
:subject => self.invited_by ? self.invited_by.name.titleize + " invited you to MyApp" : "Invitation",
:reply_to => self.invited_by ? self.invited_by.to_e : "",
:from => self.invited_by ? "#{self.invited_by.name.gsub(/\W/, ' ').titleize} via MyApp <info@myapp.com>" : "MyApp <info@myapp.com>"
(rdb:1) @filter
{:grid_id=>8, :from=>Mon, 16 Dec 2013 10:27:58 UTC +00:00, :to=>Tue, 24 Dec 2013 10:27:58 UTC +00:00, :completed=>false}
(rdb:1) @filter[:completed].present?
false
(rdb:1) @filter[:to].present?