This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Growl | |
g = Growl.GrowlNotifier('python', ['highlight']) | |
g.register() | |
g.notify('highlight', 'the title', 'the message') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stickynote_cmd(data, buffer, args): | |
if args in ['on', 'off', 'toggle']: | |
newState = None | |
if args == 'toggle': | |
currentState = weechat.config_get_plugin('sticky') | |
newState = { 'on' : 'off', 'off' : 'on' }[currentState] | |
else: | |
newState = args |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'data_mapper' | |
require 'dm-zone-types' | |
class Thing | |
include DataMapper::Resource | |
property :id, Serial | |
property :stamp, ZonedTime | |
end | |
DataMapper.setup :default, 'postgres://localhost/franco' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/sha1' | |
def buf_sha file, buf_size | |
d = Digest::SHA1.new | |
buf = String.new | |
open(file) do |io| | |
d.update buf while io.read(buf_size, buf) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/sha1' | |
# this patch fixes SHA1#update on OSX | |
class Digest::SHA1 | |
def update s | |
buf_size = 1024 ** 2 | |
if s.size > buf_size | |
io = StringIO.new s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'digest/sha1' | |
s = ARGV.shift || 512 | |
f = 'data' | |
`dd if=/dev/random of=#{f} bs=1048576 count=#{s}` | |
rsha = Digest::SHA1.new.update(File.read(f)).hexdigest | |
fsha = Digest::SHA1.file(f).hexdigest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rs = 157.times.map &:rand # max forks for darwin, linux is waaaaaaay more | |
ps = rs.map do |r| | |
fork { sleep r } | |
end | |
ps.each { |p| Process.wait p } | |
ts = rs.map do |r| | |
Thread.new { sleep r } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Installing rack-test (0.5.4) /Library/Ruby/Site/1.8/rubygems/installer.rb:519:in `initialize': Permission denied - /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/.document (Errno::EACCES) | |
from /Library/Ruby/Site/1.8/rubygems/installer.rb:519:in `open' | |
from /Library/Ruby/Site/1.8/rubygems/installer.rb:519:in `extract_files' | |
from /Library/Ruby/Site/1.8/rubygems/installer.rb:500:in `each' | |
from /Library/Ruby/Site/1.8/rubygems/installer.rb:500:in `extract_files' | |
from /Library/Ruby/Site/1.8/rubygems/installer.rb:196:in `install' | |
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.3/lib/bundler/source.rb:100:in `install' | |
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.3/lib/bundler/installer.rb:55:in `run' | |
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each' | |
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://projecteuler.net/index.php?section=problems&id=5 | |
sol = foldr1 lcm [1..20] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://projecteuler.net/index.php?section=problems&id=4 | |
import Data.List | |
import Data.Maybe | |
isPalindrome "" = True | |
isPalindrome s = let f = head s | |
l = last s | |
m = take ((length s) - 2) (tail s) | |
in f == l && (isPalindrome m) |