Skip to content

Instantly share code, notes, and snippets.

View ctrochalakis's full-sized avatar

Christos Trochalakis ctrochalakis

View GitHub Profile
#!/bin/bash
#
# Reject non-fastforward updates per branch
# Place it at hooks/update and make it executable
ref=$1
old=$2
new=$3
# Debug
@ctrochalakis
ctrochalakis / backup.sh
Created March 13, 2012 14:08 — forked from karussell/backup.sh
Backup ElasticSearch with rsync
# TO_FOLDER=/something
# FROM=/your-es-installation
DATE=`date +%Y-%m-%d_%H-%M`
TO=$TO_FOLDER/$DATE/
echo "rsync from $FROM to $TO"
# the first times rsync can take a bit long - do not disable flusing
rsync -a $FROM $TO
# now disable flushing and do one manual flushing
@ctrochalakis
ctrochalakis / gist:1669023
Created January 24, 2012 09:08 — forked from brainopia/gist:1661877
ruby-build definition for falcon patch - https://gist.github.com/1658360 (works)
patch_url=https://raw.github.com/gist/1658360/afd06eec533ad0140011bdaf652e6cd82eedf7ec/cumulative_performance.patch
yaml_url=http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
ruby_url=http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
build_package_falcon_patch() {
echo 'applying falcon patch'
curl $patch_url | patch -p1
build_package_standard $1
}
@ctrochalakis
ctrochalakis / jekyll_generate.rb
Created October 19, 2010 12:19
Rake task to generate an html branch for jekyll
desc "Commit website to html branch"
task :html do
system <<-GITFOO
test -e 'for_html' && rm -rf for_html
test -e '.git/html.index' && rm .git/html.index
jekyll --no-auto for_html
export GIT_INDEX_FILE=.git/html.index
git add -f for_html
tree_id=$(git write-tree --prefix=for_html/)
@ctrochalakis
ctrochalakis / bench_sinit.rb
Created October 17, 2010 07:06
Benchmarking redis sinit command
require 'redis'
require 'benchmark'
$redis = Redis.new
#$redis.flushall
array_size = Integer(ARGV.first)
a = Array.new(array_size) { rand(1_000_000) }
a = a.uniq
@ctrochalakis
ctrochalakis / exception_notify_helper.rb
Created August 26, 2010 09:31
Using exception_notifier for rake tasks or scripts
# Exception notifier (rails3) only works as a rack middleware,
# but what if you need notifications inside a rake task or a script?
# This is a quick hack around that.
#
# Wrap your code inside an exception_notify block and you will be notified of exceptions
#
# exception_notify { clear_payments }
def exception_notify
yield
rescue Exception => exception
@ctrochalakis
ctrochalakis / deploy.rb
Created July 28, 2010 06:33
Bundler rc capistrano recipe
# Bundler-rc deploy recipe
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
desc "Install gem bundle if needed"
require 'action_controller/test_process'
# Paperclip attachments in factories, made easy based on technicalpickles
Factory.class_eval do
def attach(name, path, content_type = nil)
if content_type
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}", content_type)
else
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}")
end
class Apiv2::MainController < ApplicationController
before_filter :lazy_developer
def lazy_developer
redirect_to params.merge(:host => 'localhost', :port => 3000) if params.key? :devel
redirect_to params.merge(:host => 'skroutz.gr', :port => 80) if params.key? :prod
end
@ctrochalakis
ctrochalakis / ruby-debug + rvm + 1.9.2
Created July 2, 2010 09:01
ruby-debug + rvm + 1.9.2
#
gem install ruby-debug19 -- --with-ruby-include=/home/belbo/.rvm/src/ruby-1.9.2-head/