Skip to content

Instantly share code, notes, and snippets.

View cpetschnig's full-sized avatar

Christoph Petschnig cpetschnig

  • powercloud GmbH
  • Leipzig, Germany
  • 23:57 (UTC +01:00)
View GitHub Profile
def my_haml_helper
haml_tag :div do
haml_tag :span, 'foo'
end
end
would produce:
<div>
<span>foo</span>
# in file helper_test.rb:
def haml_tag_helper_method
haml_buffer.options[:escape_html] = true
haml_tag :div do
haml_tag :span, 'foo'
end
end
def test_haml_tag_with_block
@cpetschnig
cpetschnig / validate_ipv6.rb
Created February 4, 2010 09:19
Regular Expression Validation for IPv6 Addresses in Ruby
# Regular Expression Validation for IPv6 addresses in Ruby
#
# Inspired by (if not to say copied from): http://forums.dartware.com/viewtopic.php?t=452
# Thanks, Dartware!
IPV6_REGEX = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f
@cpetschnig
cpetschnig / create_user_mysql.sql
Created April 14, 2010 07:50
MySQL: Create DB user and set permissions
-- create new user and give permissions to all databases of names starting with "USERNAME_"
CREATE USER 'my_new_user'@'localhost' IDENTIFIED BY '9ixv[jX6g33yD#lZl#T5dV5l882_Y';
GRANT ALL ON `my_new_user\_%`.* TO 'my_new_user'@'localhost';
@cpetschnig
cpetschnig / .irbrc
Created April 28, 2010 08:09
My irb customization file
require 'rubygems'
irb_extensions = []
begin
# load wirble
require 'wirble'
# start wirble (with color)
Wirble.init
@cpetschnig
cpetschnig / .irbrc
Created July 18, 2010 19:30
My .irbrc file: IRB customization
require 'rubygems'
irb_extensions = []
begin
# load wirble
require 'wirble'
# start wirble (with color)
Wirble.init
From e35a6eaef85051163204a1ba5c7fa4facdad6420 Mon Sep 17 00:00:00 2001
From: Christoph Petschnig <[email protected]>
Date: Wed, 21 Jul 2010 09:52:27 +0200
Subject: [PATCH 1/2] Added 'rake test'
---
Rakefile | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/Rakefile b/Rakefile
From d775b59b47c284fe43086772cffe7481b951d36a Mon Sep 17 00:00:00 2001
From: Christoph Petschnig <[email protected]>
Date: Thu, 22 Jul 2010 08:21:35 +0200
Subject: [PATCH] Added tests for start/stop log messages
---
test/daemon_spawn_test.rb | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/test/daemon_spawn_test.rb b/test/daemon_spawn_test.rb
@cpetschnig
cpetschnig / ruby-srtftime
Created September 21, 2010 09:25
Show the possible tokens of Ruby Time#strftime
#!/usr/bin/env ruby
# one line version:
# t = Time.new; puts (65.upto(90).map{|i|s = "%%#{i.chr}: %#{i.chr}"; t.strftime(s).ljust(25) + t.strftime(s.downcase)}.join("\n"))
# Output:
#
# %A: Tuesday %a: Tue
# %B: September %b: Sep
# %C: 20 %c: Tue Sep 21 08:53:35 2010
@cpetschnig
cpetschnig / 0001-Added-config-option-order.patch
Created November 6, 2010 16:44
Patch for oggy/looksee: Added config option 'order'
From 7878ed28ba6bafbe4f90286f4b86ab35e223939e Mon Sep 17 00:00:00 2001
From: Christoph Petschnig <[email protected]>
Date: Fri, 5 Nov 2010 19:10:37 +0100
Subject: [PATCH] Added config option #order
---
lib/looksee.rb | 21 ++++++++++++++++++++-
spec/looksee_spec.rb | 10 ++++++++++
2 files changed, 30 insertions(+), 1 deletions(-)