Skip to content

Instantly share code, notes, and snippets.

View we4tech's full-sized avatar

Hossain Khan we4tech

View GitHub Profile
@mvidaurre
mvidaurre / fibo_tail_recursion.rb
Created April 17, 2014 19:30
Calculate the nth Fibonacci number, f(n). Using invariants for https://github.com/RayHightower/fibonacci
# Calculate the nth Fibonacci number, f(n). Using invariants
def fibo_tr(n, acc1, acc2)
if n == 0
0
elsif n < 2
acc2
else
return fibo_tr(n - 1, acc2, acc2 + acc1)
end
end
@reidmorrison
reidmorrison / collection.rb
Last active September 28, 2015 21:19
Mongo Reconnect logic for Connection Failures. Deprecated, moved to: https://github.com/reidmorrison/mongo_ha
#
# NOTE: This gist is now deprecated and has been moved into a gem: https://github.com/reidmorrison/mongo_ha
#
require 'mongo/collection'
module Mongo
class Collection
alias_method :find_one_original, :find_one
def find_one(*args)
@dqminh
dqminh / applause_formatter.rb
Last active December 18, 2015 04:59
rspec formatter that applause you when your tests pass
require "rspec/core/formatters/progress_formatter"
class ApplauseFormatter < RSpec::Core::Formatters::ProgressFormatter
def initialize(output)
super(output)
unless File.exists? "/tmp/applause.mp3"
p "Downloading applause for awesomeness"
system "wget http://www.soundjay.com/human/applause-1.mp3 -O /tmp/applause.mp3"
end
end
@mrrooijen
mrrooijen / deploy.rb
Created June 26, 2011 02:37
Capistrano with Foreman Capfile
# encoding: utf-8
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :application, "hirefireapp"
set :repository, "git@codeplane.com:meskyanichi/myapp.git"
set :branch, "develop"
set :rvm_ruby_string, "1.9.2"
@wxmn
wxmn / embedded_documents.rb
Created November 6, 2010 20:04
Examples of Atomic Operations on Embedded Documents in MongoMapper
#Stories are embedded docs in a Feed
class Feed
include MongoMapper::Document
many :stories
end
class Story
include MongoMapper::EmbeddedDocument
key :title, String
@surjikal
surjikal / prediction-io-ubuntu-precise.md
Last active March 24, 2017 11:33
Prediction IO Install Notes on Ubuntu Precise (12.04)
@clay-whitley
clay-whitley / export_processor.md
Last active April 5, 2017 04:53
km-export-processor Documentation

km-export-processor gem

The purpose of this gem is to consume the JSON that KISSmetrics exports to an S3 bucket, and transform it in a variety of useful ways.

The core features are:

  • JSON compiler : Aggregates all KISSmetrics JSON files in a directory, into a single (nonstandard) file.
  • JSON to JSON converter : Converts a nonstandard JSON file into standard format.
  • JSON to CSV converter : Converts a nonstandard JSON file into a CSV file, where each row is an event/property/alias.
  • Reimporter : Takes a nonstandard JSON file, and an API key, and sends the data in the JSON file to the product using the KMTS gem.
@5v3n
5v3n / spec_helper.rb
Created April 13, 2011 15:39
in order to make spork reload routes & any rb file in the app folder:
Spork.each_run do
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
end
@hisea
hisea / nginx
Created January 1, 2012 23:37
ubuntu passenger nginx init.d script
sudo cp nginx /etc/init.d/
sudo update-rc.d nginx defaults
sudo chmod +x /etc/init.d/nginx
/etc/init.d/nginx start