Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'curb'
require 'webrick'
require 'test/unit'
# keep webrick quiet
class ::WEBrick::HTTPServer
def access_log(config, req, res)
require 'rubygems'
require 'curb'
require 'cgi'
# expand a tiny url to a real large url, use twitter api and the tiny url see who wins
def tiny2real(tiny_url)
# send both in a multi handle the first back wins
mh = Curl::Multi.new
git diff ext/curb.h
diff --git a/ext/curb.h b/ext/curb.h
index c40a5a0..0c04c63 100644
--- a/ext/curb.h
+++ b/ext/curb.h
@@ -42,6 +42,18 @@
#define RHASH_LEN(hash) RHASH(hash)->tbl->num_entries
#endif
+#ifdef HAVE_RUBY_THREAD_BLOCKING_REGION
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
#
# allow users to request an image to be of a specific size
#
# e.g.
#
# /sized/#{siteid}-#{fileId}-x-y.png
#
require 'rubygems'
require 'hpricot'
require 'curb'
require 'uri'
require 'fileutils'
$URLDB = {}
def grab_page(url)
<!DOCTYPE html>
<html>
<head><title><%= @title %></title></head>
<body>
<%= @body %>
</body>
</html>
require 'rubygems'
require 'erubis'
5.times do|i|
eruby = Erubis::Eruby.new(File.read("layout.erb"))
File.open("page#{i}.html","wb") do|f|
f << eruby.evaluate({
:title => "Page #{i}",
:body => "This is the cool page #{i}"
cat lib/smtp_tls.rb
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
<title>Configuration manager</title>
<%= stylesheet_link_tag 'style' %>
<%= yield :head %>
</head>
<body>
mysql> SELECT count(DISTINCT `companies`.id) AS count_all FROM `companies` LEFT OUTER JOIN `contacts` ON `contacts`.contactable_id = `companies`.id AND `contacts`.contactable_type = 'Company' LEFT OUTER JOIN `locations` ON `locations`.locatable_id = `companies`.id AND `locations`.locatable_type = 'Company' LEFT OUTER JOIN `events` ON `events`.eventable_id = `companies`.id AND `events`.eventable_type = 'Company'WHERE ( (`companies`.`type` = 'Prospect' ) );
+-----------+
| count_all |
+-----------+
| 882 |
+-----------+
1 row in set (1.60 sec)
mysql> explain SELECT count(DISTINCT `companies`.id) AS count_all FROM `companies` LEFT OUTER JOIN `contacts` ON `contacts`.contactable_id = `companies`.id AND `contacts`.contactable_type = 'Company' LEFT OUTER JOIN `locations` ON `locations`.locatable_id = `companies`.id AND `locations`.locatable_type = 'Company' LEFT OUTER JOIN `events` ON `events`.eventable_id = `companies`.id AND `events`.eventable_type = 'Company'WHERE ( (`companies`.`type` = 'Prospect' ) );