Skip to content

Instantly share code, notes, and snippets.

View flazz's full-sized avatar

Franco Lazzarino flazz

View GitHub Profile
import Growl
g = Growl.GrowlNotifier('python', ['highlight'])
g.register()
g.notify('highlight', 'the title', 'the message')
@flazz
flazz / gist:788034
Created January 20, 2011 15:09
function to toggle a setting
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
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'
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
@flazz
flazz / patch.rb
Created December 9, 2010 22:46
fixes sha1#update bug on OSX
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
#!/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
@flazz
flazz / fork-vs-thread.rb
Created November 18, 2010 15:08
sleep in a proc and in a thread
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 }
@flazz
flazz / gist:664168
Created November 5, 2010 13:35
bundle install error on rack-test (0.5.4)
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'
-- http://projecteuler.net/index.php?section=problems&id=5
sol = foldr1 lcm [1..20]
-- 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)