Skip to content

Instantly share code, notes, and snippets.

View jpablobr's full-sized avatar

Pablo Barrantes jpablobr

View GitHub Profile
@jpablobr
jpablobr / Gemfile
Created November 1, 2011 05:35 — forked from libryder/Gemfile
Config files for integrating adhearsion and rails
source 'http://rubygems.org'
gem 'adhearsion', '>= 1.2.1'
gem 'ahn-restful-rpc'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
@jpablobr
jpablobr / command.sh
Created October 29, 2011 15:55 — forked from felixge/command.sh
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
@jpablobr
jpablobr / dot_irbrc.rb
Created October 20, 2011 05:55
dot_irbrc
begin
require 'irbtools'
rescue LoadError
$stderr.puts "Please install 'irbtools' or add it to your Gemfile"
end
class Object
# Return a list of methods defined locally for a particular object. Useful
# for seeing what it does whilst losing all the guff that's implemented
# by its parents (eg Object).
@jpablobr
jpablobr / subcommand.rb
Created October 17, 2011 15:31
A tiny wrapper over optparse that gives easy subcommand facility.
#!/usr/bin/env ruby -w
######################################
# A tiny wrapper over optparse that gives easy subcommand facility.
# It also neatly prints help for global and subcommands
# as well as summarizes subcommands in global help.
#
# Thanks to Robert Klemme for his idea on lazy loading the subcommand option parsers.
#
# @author Rahul Kumar, Jun 2010
# @date 2010-06-20 22:33
@jpablobr
jpablobr / gist:1286249
Created October 14, 2011 04:32 — forked from dtsato/gist:1285321
Speeding up Rails specs
# Add these lines to your spec_helper.rb to speed up specs:
Sass::Plugin.options[:always_check] = false
Sass::Plugin.options[:always_update] = false
@jpablobr
jpablobr / gist:1269650
Created October 7, 2011 06:59 — forked from parndt/gist:1011435
How to cache pages and clear them in Refinery CMS
# put in config/application.rb
config.to_prepare do
::PagesController.module_eval do
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
end
::Page.module_eval do
after_save :clear_static_caching!
after_destroy :clear_static_caching!
@jpablobr
jpablobr / ruby_gsub.sh
Created September 27, 2011 05:46
ruby gsub one-liner
ruby -i.bak -pe "gsub(/link_to/,'button_to')" *.erb
###
# This is a demonstration of using SQLite3's Virtual File System API in Ruby.
#
# == Synopsis
#
# This program will store its SQLite database after the __END__ line.
#
# === In Detail
#
# SQLite3 uses the DATABase class as a proxy for our IO object. Upon
@jpablobr
jpablobr / development.rb
Created August 1, 2011 23:32 — forked from banister/development.rb
Use Pry as IRB replacement in rails 3 console
# Add this to the end of your development.rb and add
#
# gem 'pry'
#
# to your Gemfile and run bundle to install.
silence_warnings do
begin
require 'pry'
IRB = Pry
@jpablobr
jpablobr / gist:1096279
Created July 21, 2011 00:55 — forked from wayneeseguin/gist:1095634
My thought on improving Ruby construct end syntax.
# I have now programmed in a lot of languages, and one thing I can say for sure
# is that shell scripting does construct end styles very well.
#
# Example from http://redmine.ruby-lang.org/issues/5054
#
# This is indeed also one of my few personal issues with Ruby syntax, the end trail.
#
module MyModule
class MyClass