Skip to content

Instantly share code, notes, and snippets.

require 'benchmark'
str = "hey there whatever id like to remove e's and i's from this message"
res = Benchmark.measure do
10000.times { str.gsub('i','*').gsub('e','*') }
end
puts res.real
class Integer
def fact
(1..self).inject{ |x,y| x * y }
end
def digits
self.to_s.split(//).map { |x| x.to_i }
end
end
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 1.6.0 (68639)"/><meta name="created" content="2010-01-21 00:17:30 -0800"/><meta name="updated" content="2010-01-21 01:49:18 -0800"/><title>emacs 23 daemon style</title></head><body><div><font color="#000000" size="7"><font size="6">Setting up Emacs daemon on OS X</font></font></div><div><br/></div><div>Tired of waiting for emacs to start on OS X? This step by step guide will teach you how to install the latest version of emacs and configure it to start in the background (daemon mode) and use emacsclient as your main editor.<br/></div><div><br/></div><div><br/></div><div><font size="4"><b>Install Homebrew</b></font></div><div><font size="4"><b/></font>First you'Il need to install the Homebrew package manag
# 2010 Modularity Olympics
# ===
# This is a contest, open to programming languages from all over the world, to write modular and
# extensible code to solve the following problem: Implement a service that can run queries on a database.
# A programmer without control over the source-code of that service must be able to later add
# enhancements such as statistics collecting, timeouts, memoization, and so forth. There are a few
# requirements:
# 1. the "enhancements" must be specified in a configuration object which is consumed at run-time
# (e.g., it could be based on user-input).
# 2. The enhancements are ordered (stats collecting wraps timeouts, not the other way around) but
require 'rubygems'
require 'rmagick'
include Magick
img = Image.read(ARGV[0]).first
puts '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
require 'net/http'
require 'net/https'
if ( ARGV.size < 4 )
print "\nUsage: ruby youtube_upload.rb <DevID> <User> <Pass>
<Filename>\n\n"
exit
end
dev_id = ARGV[0]
The most dangerous thing for the frontpage is stuff that's too easy to upvote. If someone proves a new theorem, it takes some work by the reader to decide whether or not to upvote it. An amusing cartoon takes less. A rant with a rallying cry as the title takes zero, because people vote it up without even reading it.
#!/usr/bin/env ruby
require 'ftools'
EXTS = %w{ jpg gif jpeg png }
DEST = '/Users/capotej/Pictures'
def cleanup?(p)
return true unless EXTS.select { |f| p.to_s.include?(f) or p.to_s.include?(f.upcase) }.empty?
end
a = [1,12,31,2,3,13,2,4,5,15,2,3,1,2,3,14,1,3,6,341,500]
def seq_length(seq, len = 1)
if seq.length > 0
arr = seq.shift
cur,nxt = arr[0],arr[1]
if nxt > cur
len = len + 1
seq_length(seq, len)
else
#ObjectSpace also provides support for object finalizers, procs that will be called when a specific #object is about to be destroyed by garbage collection.
# Example:
# A dog object is lost
class Dog
end
fido = Dog.new
lucky = Dog.new