Skip to content

Instantly share code, notes, and snippets.

View LeipeLeon's full-sized avatar
🕳️

Leon Berenschot LeipeLeon

🕳️
View GitHub Profile
@LeipeLeon
LeipeLeon / WakoopaGrowl.rb
Created January 27, 2009 15:31
Send a growl message with latest updates in your wakoopa feed
#!/usr/bin/env ruby
#
# Send a growl message with latest updates in your feed
#
# edit your crontab (crontab -e) and add this line
# (this checks your feed every 30 minutes)
# */30 * * * * ~/bin/WakoopaGrowl.rb > /dev/null
#
# create a yaml file (mate ~/.wakoopa_growl) within your homedirectory
# username: your_username
@LeipeLeon
LeipeLeon / YodaSpeak.rb
Created February 11, 2009 23:12
Speak like Yoda
# port of http://www.perlmonks.org/?node_id=162190
#
# Please refactor this if necessary
# leonb -at- beriedata -dot- nl
#
class String
def yoda
word = %w{is be will show do try are teach have}.select { |word| self =~ /\b#{word}\b/ }[0]
if word
x = (self =~ /\b#{word}\b/) + word.size
@LeipeLeon
LeipeLeon / find_1500.rb
Created September 23, 2010 00:49
Find tracks from the Kink1500 (http://www.kinkfm.com/kink1500) in your iTunes Library
#!/usr/bin/env ruby
#
# Tracklisting: (c) 2010 KinkFM.com and their listeners
# Code: (c) 2010 Leon Berenschot, Wendbaar.nl
#
# Find the tracks of the Kink1500 in your iTunes library
# Usage:
# - First create a playlist called "Kink 1500-2010"
# - From the commandline execute 'ruby ./find_1500.rb'
#
<%= image_submit_tag "button_volgende_stap.gif", :title=> t('form.submit'), :onclick => "needToConfirm = false;" %>
<% content_for :page_js do %>
<script>
var needToConfirm = false;
window.onbeforeunload = confirmExit;
function confirmExit() {
if (needToConfirm) {
return "U heeft onbewaarde wijzigingen. Doorgaan?";
@LeipeLeon
LeipeLeon / gist:884603
Created March 24, 2011 05:01
Textmate -> preferences -> advanced -> Folder Rerences
File Pattern:
!(/\.(?!htaccess)[^/]*|(swf|mp3|jpeg|gif|png|psd|log|pdf|sql|bz2)|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$
Folder Pattern:
!.*/(\.[^/]*|public/system|server/gems|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$
class AppServer
attr_accessor :admin_password, :port
end
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
def app_server
@app_server ||= AppServer.new
yield @app_server if block_given?
module MyAccessors
@@my_accessors = []
def my_accessor var
attr_accessor var
@@my_accessors << var
end
def my_attributes
# In 1.9 the Time#to_s method doesn't return in the format as outlined in the pickaxe book (PDF page 747):
it "ouput of #to_s is different in 1.8 and 1.9" do
time = Time.at(1289349987)
time.strftime("%a %b %d %H:%M:%S %z %Y").should eql('Wed Nov 10 01:46:27 +0100 2010') # passes
time.to_s.should eql('Wed Nov 10 01:46:27 +0100 2010') # fails
end
# Failure/Error: time.to_s.should eql('Wed Nov 10 01:46:27 +0100 2010')
# expected "Wed Nov 10 01:46:27 +0100 2010"
@LeipeLeon
LeipeLeon / spec_helper.rb
Created May 24, 2011 12:55
capture std in/out/err
def capture(*streams)
require 'stringio'
streams.map! { |stream| stream.to_s }
begin
result = StringIO.new
streams.each { |stream| eval "$#{stream} = result" }
yield
ensure
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
set(:branch) do
if :production == stage
branch = Capistrano::CLI.ui.ask("#{`git branch`}\n\nWhich branch do you want to deploy?: ")
raise "Error: The master branch cannot be deployed to production." if 'master' == branch
else
`git branch | grep ^* | sed s/\\*\\ //`.chomp # use current active branche
end
end