Skip to content

Instantly share code, notes, and snippets.

@eladmeidar
eladmeidar / example.rb
Last active August 29, 2015 14:04 — forked from anonymous/example.rb
link "http://api.plnkr.co/catalogue/packages?"
95.times do |i|
page = i + 1
# use page here in the request
end
# ever use while like that again and i'll come over there and kill you
<form action="http://localhost:3001/" method="get">
<input name="adam[][date][][day]"/>
<input name="adam[][date][][month]"/>
<input name="adam[][date][][day]"/>
<input name="adam[][date][][month]"/>
<input type="submit"/>
</form>
# timeit { sleep 20 }
# => {:weeks=>0, :days=>0, :hours=>0, :minutes=>0, :seconds=>20}
def timeit(&block)
mul = [604800, 86400, 3600, 60, 1]
values = [:weeks, :days, :hours, :minutes, :seconds]
units = []
started = Time.now.to_i
yield block
ended = Time.now.to_i
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
class Enum < Hash
def initialize(*members)
super()
@rev = {}
members.each_with_index {|m,i| self[i] = m }
end
def [](k)
super || @rev[k] # || raise ArgumentError, "#{k} is not a member of this enum"
end
def []=(k,v)
@eladmeidar
eladmeidar / faraday_typh_default.rb
Created November 30, 2012 11:26 — forked from ezkl/faraday_typh_default.rb
Parallel Requests w/ Faraday + Typhoeus
require "faraday"
require 'typhoeus'
conn = Faraday.new(:url => 'http://httpstat.us') do |builder|
builder.request :url_encoded
builder.response :logger
builder.adapter :typhoeus
end
conn.in_parallel do
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
@eladmeidar
eladmeidar / gist:4011162
Created November 4, 2012 10:14 — forked from fastjames/gist:2725983
Patch to get content_for working with action caching and fragment caching in Rails 3.1
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@eladmeidar
eladmeidar / api.js
Created October 10, 2012 10:34 — forked from fwielstra/api.js
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@eladmeidar
eladmeidar / default.vcl.pl
Created April 29, 2012 14:21 — forked from bmarini/default.vcl.pl
A good varnish config for a Rails app
# https://www.varnish-cache.org/docs/2.1/tutorial/vcl.html
# https://www.varnish-cache.org/trac/wiki/VCLExamples
# Summary
# 1. Varnish will poll the backend at /health_check to make sure it is
# healthy. If the backend goes down, varnish will server stale content
# from the cache for up to 1 hour.
# 2. Varnish will pass X-Forwarded-For headers through to the backend
# 3. Varnish will remove cookies from urls that match static content file
# extensions (jpg, gif, ...)