Skip to content

Instantly share code, notes, and snippets.

View weppos's full-sized avatar

Simone Carletti weppos

View GitHub Profile
@weppos
weppos / gist:9461565
Created March 10, 2014 08:49
RoboWhois + C# example: get the WHOIS record for a domain.
public string WhoIs(string domainName, string myApiKey)
{
string url = "http://api.robowhois.com/whois/" + domainName;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.Credentials = new NetworkCredential(myApiKey, "X");
try
{
WebResponse response = request.GetResponse();

Keybase proof

I hereby claim:

  • I am weppos on github.
  • I am weppos (https://keybase.io/weppos) on keybase.
  • I have a public key whose fingerprint is C7F3 8EE9 2951 BB47 501A 63B1 420D A82A 9893 98DF

To claim this, I am signing this object:

@weppos
weppos / capistrano_passenger_deploy.rb
Created July 29, 2008 14:59
Provides tasks for deploying a Rails application with Passenger (aka mod_rails).
#
# = Capistrano Passenger deploy tasks
#
# Provides tasks for deploying a Rails application with Passenger (aka mod_rails).
#
# Category:: Capistrano
# Package:: Passenger
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
@weppos
weppos / capistrano_fastcgi_deploy.rb
Created July 29, 2008 15:37
Provides tasks for deploying a Rails application with FastCGI.
#
# = Capistrano FastCGI deploy tasks
#
# Provides tasks for deploying a Rails application with FastCGI.
#
# Category:: Capistrano
# Package:: FastCGI
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
@weppos
weppos / title_helper.rb
Created August 3, 2008 20:46
Provides helpers for managing page title.
#
# = Rails Title Helper
#
# Provides helpers for managing page title.
#
# Category:: Rails
# Package:: Helpers
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !^id=([0-9]*)$
RewriteRule .* - [env=send_x_robot:true]
Header set X-Robots-Tag "noindex" env=send_x_robot
#
# = SuperStruct
#
# SuperStruct is an enhanced version of the Ruby Standard library <tt>Struct</tt>.
#
# Compared with the original version, it provides the following additional features:
# * ability to initialize an instance from Hash
# * ability to pass a block on creation
#
# You can read more at http://www.simonecarletti.com/blog/2010/01/ruby-superstruct/
require 'ipaddr'
require 'benchmark'
class IPAddr
def self.valid_ipv4?(addr)
if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ addr
return $~.captures.all? {|i| i.to_i < 256}
end
false
end
require 'rubygems'
require 'benchmark'
require 'nokogiri'
TIMES = 50_000
doc = Nokogiri::XML(File.new("test.xml"))
node = doc.at_xpath("./strategies")
Benchmark.bmbm do |x|
module CacheKey
extend self
def expirable(range = :minute, time = ::Time.current)
key = case range
when :always
::Time.current
when :never
nil
when :second