Skip to content

Instantly share code, notes, and snippets.

View scalp42's full-sized avatar
🪂

Anthony Scalisi scalp42

🪂
View GitHub Profile
@sandro
sandro / threaded_httparty.rb
Created August 27, 2011 01:34
Parallel HTTParty requests using threads
require 'rubygems'
require 'httparty'
require 'benchmark'
require 'thread'
class Google
include HTTParty
base_uri 'http://google.com'
def self.benchmark
@adamhjk
adamhjk / file_provider_copy.rb
Created August 31, 2011 23:16
Stick this in a library file...
class Chef
class Provider
class File
class Copy << Chef::Provider::File
def compare_content
checksum(@current_resource.path) == checksum(@new_resource.content)
end
@ericallam
ericallam / module_function.rb
Created September 12, 2011 23:13
Using module_function instead of extend self
# a lot of people in ruby do this
module Foo
extend self
def bar
'bar'
end
end
Foo.bar
@panthomakos
panthomakos / group.rb
Created September 20, 2011 23:09
Improved Custom Error Messages in Ruby
class Group
module Error
class Standard < StandardError; end
class AlreadyAMember < Standard; end
class NotPermittedToJoin < Standard; end
end
def join user
raise Error::NotPermittedToJoin unless self.permitted?(user)
raise Error::AlreadyAMember if self.member?(user)
@danmcclain
danmcclain / delayed_devise_mailer.rb
Created October 20, 2011 11:52 — forked from robotmay/delayed_devise_mailer.rb
A quick hack to make Devise send its confirmation/password reset/unlock emails via delayed_job. Chuck the following in a file under config/initializers
module Devise
module Models
module Confirmable
handle_asynchronously :send_confirmation_instructions
end
module Recoverable
handle_asynchronously :send_reset_password_instructions
end
@jtai
jtai / parse-tcpdump-udp-port-53.php
Last active January 16, 2019 16:06
Quick and dirty script to parse output of /usr/sbin/tcpdump -vvv -s 0 -l port 53
<?php
// quick and dirty argument parsing
foreach ($argv as $arg) {
if ($arg == '-f') {
define('FOLLOW', true);
}
if ($arg == '-h') {
define('HISTOGRAM', true);
}
@lusis
lusis / motd.erb
Created December 7, 2011 19:12
handy motd erb template for chef
__________________________________________________
|
| Node name: <%= node.name %>
| Node arch: <%= node.kernel.machine %>
<% if node.attribute?('ec2') %>
| EC2 AMI: <%= node[:ec2][:ami_id] %>
| EC2 Instance: <%= node[:ec2][:instance_id] %>
| Size: <%= node[:ec2][:instance_type] %>
| Public IP: <%= node[:ec2][:public_ipv4] %>
| Private IP: <%= node[:ec2][:local_ipv4] %>
@rolo
rolo / gist:1481128
Created December 15, 2011 13:44
Install Postgres 9.1, PostGIS and create PostGIS template on Ubuntu 11.10 Oneiric Ocelot
#!/bin/bash
#
# Install Postgres 9.1, PostGIS and create PostGIS template on a clean Ubuntu 11.10 Oneiric Ocelot box
# http://wildfish.com
# add the ubuntu gis ppa
sudo apt-get -y install python-software-properties
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
@nono
nono / rails_log_stathat.rb
Created December 30, 2011 11:07
Parse a Rails log file and send metrics to stathat
#!/usr/bin/env ruby
require 'net/http/persistent'
require 'uri'
require 'thread'
USAGE = <<EOS
Parse a Rails log file and send metrics to stathat
export EMAIL=email
@onilton
onilton / percolatorbugreproduce.sh
Created January 25, 2012 19:43
Reproduce possible percolator bug
#!/bin/bash
echo ; echo
echo "Create test index"
curl -XPUT localhost:9200/testindex?pretty=true
echo ; echo
echo "Insert doc 1"
curl -XPUT http://localhost:9200/testindex/article/1?pretty=true -d '{