This file contains 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/local/bin/php -qC | |
<? | |
/* | |
$Id: phpa.php 2008/04/28 $ | |
David Phillips <[email protected]> | |
*/ | |
__phpa__setup(); | |
__phpa__print_info(); |
This file contains 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
# | |
# Use this in models for status codes etc. Will dynamically create a class constant | |
# for each row in the table. The name of the constant will be based on the field specified. | |
# Typically it would be code, though name might be useful in some cases. | |
# | |
# This will build the constants once on rails startup. It only hits the database once, the find(:all), | |
# so should be reasonably efficient as long as it's used for small tables only. | |
# | |
# Put this in lib/create_id_constants.rb | |
# |
This file contains 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
[Development]>> puts Time.now; (-5..5).each { |w| t = Time.now + w.weeks; puts "now and #{'%2d'%w} weeks: #{t.beginning_of_fortnight} - #{t.end_of_fortnight}" }; nil | |
Wed Oct 06 16:29:52 +1000 2010 | |
now and -5 weeks: Mon Aug 30 00:00:00 +1000 2010 - Sun Sep 12 23:59:59 +1000 2010 | |
now and -4 weeks: Mon Aug 30 00:00:00 +1000 2010 - Sun Sep 12 23:59:59 +1000 2010 | |
now and -3 weeks: Mon Sep 13 00:00:00 +1000 2010 - Sun Sep 26 23:59:59 +1000 2010 | |
now and -2 weeks: Mon Sep 13 00:00:00 +1000 2010 - Sun Sep 26 23:59:59 +1000 2010 | |
now and -1 weeks: Mon Sep 27 00:00:00 +1000 2010 - Sun Oct 10 23:59:59 +1000 2010 | |
now and 0 weeks: Mon Sep 27 00:00:00 +1000 2010 - Sun Oct 10 23:59:59 +1000 2010 | |
now and 1 weeks: Mon Oct 11 00:00:00 +1000 2010 - Sun Oct 24 23:59:59 +1000 2010 | |
now and 2 weeks: Mon Oct 11 00:00:00 +1000 2010 - Sun Oct 24 23:59:59 +1000 2010 |
This file contains 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
# | |
# https://gist.github.com/663503 | |
# | |
# Use this to clean your repo by removing old branches. | |
# It will remove the branch on local and on origin. | |
# | |
# Usage: | |
# $ nuke_branch some_old_branch_you_dont_need | |
# | |
# Note we use -d not -D for teh safety. |
This file contains 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
# | |
# Example 1 | |
# | |
# There are two modules, one for instance methods and one for class methods | |
# Use 'include' and 'extend' separately | |
# | |
module Foo1Instance | |
def foo; "instance foo (#{self.class.name})"; end | |
end |
This file contains 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 'rubygems' | |
require 'haml' | |
# Put a - char on each line in just the right place. | |
# (Need to remove blank lines too, they cause problems) | |
haml_source = File.read($0).gsub(/\n+/,"\n").gsub(/^\s*/,'\&-') | |
begin | |
# Run the file with haml | |
Haml::Engine.new(haml_source).render | |
rescue Exception => e | |
# Spit out the haml source to make it easier to find your error |
This file contains 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
class Date | |
# Going to be lazy here... | |
[:beginning_of_fortnight, :end_of_fortnight, :next_fortnight].each do |method| | |
define_method(method) do |*args| | |
self.to_time.send(method,*args).to_date | |
end | |
end | |
end |
This file contains 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
class Date | |
[:beginning_of_fortnight, :end_of_fortnight, :next_fortnight].each do |method| | |
define_method(method) do |*args| | |
self.to_time.send(method,*args).to_date | |
end | |
end | |
end |
This file contains 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
# Where the magic happens... | |
module RuntimeInclude | |
def get_singleton | |
class << self | |
self | |
end | |
end | |
def runtime_include(the_module) | |
get_singleton.send(:include,the_module) |
This file contains 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
# Dump a mysql database to a gzipped sql file | |
dbdump() { | |
# (adjust defaults as required) | |
GZ_FILE=$1; [ ! -n "$GZ_FILE" ] && GZ_FILE="$HOME/.dbdump.gz" | |
DB_NAME=$2; [ ! -n "$DB_NAME" ] && DB_NAME='fms' | |
echo -n "Dumping database $DB_NAME to $GZ_FILE..." | |
# Add --extended-insert=FALSE to mysql command for more readable but MUCH slower sql | |
mysqldump -u root $DB_NAME | gzip - > "$GZ_FILE" | |
echo ' Done' | |
} |
OlderNewer