Skip to content

Instantly share code, notes, and snippets.

View swalberg's full-sized avatar

Sean Walberg swalberg

View GitHub Profile
require 'nokogiri'
require 'open-uri'
def to_minutes(string)
(hr, min) = string.split(/\s?:\s?/)
hr.to_i * 60 + min.to_i
end
doc = Nokogiri::HTML(open('http://www.wrha.mb.ca/wait-times/'))

Before:

mysql> explain SELECT galleryid, COUNT(*) as counter , `options`.`option_value` AS 'custom_post_id', GROUP_CONCAT(CONCAT_WS('@@', meta_key, meta_value)) AS 'extras' FROM `ngg_pictures` LEFT OUTER JOIN `options` ON `options`.option_name = CONCAT('ngg_pictures_', ngg_pictures.pid) LEFT OUTER JOIN `postmeta` ON `postmeta`.`post_id` = `options`.`option_value`  WHERE (`galleryid` IN (1746, 1747, 1749, 1748, 1750, 1751, 1752, 1753, 1745, 1754)) GROUP BY galleryid, ngg_pictures.pid;
+----+-------------+--------------+------+---------------+---------+---------+----------------------------+-------+----------------------------------------------+
| id | select_type | table        | type | possible_keys | key     | key_len | ref                        | rows  | Extra                                        |
+----+-------------+--------------+------+---------------+---------+---------+----------------------------+-------+----------------------------------------------+
|  1 | SIMPLE      | ngg_pictures | ALL  |
bob:tmp $ strace -e trace=file ruby ./test.rb |& grep foo
open("/tmp/foo.rb", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 7
open("/tmp/foo.rb", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 7
lstat64("/tmp/foo.rb", {st_mode=S_IFREG|0644, st_size=20, ...}) = 0
bob:tmp $ echo "require './foo'" >> test.rb
bob:tmp $ strace -e trace=file ruby ./test.rb |& grep foo
open("/tmp/foo.rb", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 7
open("/tmp/foo.rb", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 7
lstat64("/tmp/foo.rb", {st_mode=S_IFREG|0644, st_size=20, ...}) = 0
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://en.wikipedia.org/wiki/List_of_The_Price_Is_Right_pricing_games'))
puts doc.css('h4 span.mw-headline').map(&:inner_text).sample
# perl test.pl | more
Name = root
UID = 0
Comment =
Gcos = root
HOME DIR = /root
Name = root
UID = 0
Comment =
module MyApp
module Database
def connect(pool_size = nil, reap_time = nil)
return unless defined? ActiveRecord::Base
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = reap_time || ENV['AR_DB_REAP_FREQ'] || 10 # seconds
config['pool'] = pool_size || ENV['AR_DB_POOL'] || 5
ActiveRecord::Base.establish_connection(config)
end
require 'active_support/concern'
module NationBuilderApi
extend ActiveSupport::Concern
def token
self.class.token
end
def nationbuilder(to, data)
<?php
// From http://ertw.com/blog/2013/11/05/using-an-ip-phone-with-twilio/
// Connect an incoming call to your SIP phone through Twilio
$called = preg_replace('/sip:1?(.*?)@.*/', '{$1}', $_POST['Called']);
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
# Inside the gem
class ActionController::Base
def self.check_webhook_signature(key, *args)
before_filter lambda { |controller| controller.check_webhook_signature(key, controller)}, *args
end
def check_webhook_signature(key, controller)
# Do the work
end
end
# Before
SeanWalbergsMacBookPro:~ $ dd if=/dev/zero of=testing bs=1m count=1024
1024+0 records in
1024+0 records out
1073741824 bytes transferred in 11.015328 secs (97477062 bytes/sec)
# After
SeanWalbergsMacBookPro:~ $ dd if=/dev/zero of=testing bs=1m count=1024
1024+0 records in
1024+0 records out