Skip to content

Instantly share code, notes, and snippets.

View nordringrayhide's full-sized avatar

Nodrin Grayhide nordringrayhide

  • home
  • Worldwide
View GitHub Profile
@nordringrayhide
nordringrayhide / watchr-runner.rb
Created August 9, 2011 06:23 — forked from rud/watchr-runner.rb
watchr for rspec
if __FILE__ == $0
puts "Run with: watchr #{__FILE__}. \n\nRequired gems: watchr rev"
exit 1
end
# --------------------------------------------------
# Convenience Methods
# --------------------------------------------------
def run(cmd)
puts(cmd)
if __FILE__ == $0
puts "Run with: watchr #{__FILE__}. \n\nRequired gems: watchr rev"
exit 1
end
# --------------------------------------------------
# Convenience Methods
# --------------------------------------------------
def run(cmd)
puts(cmd)
<markdown>
## Head1
* List1
* List 2
* List 3
#!ruby
def say
puts "Hello world!!!"
@nordringrayhide
nordringrayhide / ruby-rails.snippets
Created March 8, 2011 19:05
Some Ruby on Rails 3.x, RSpec, Shoulda snippets
# Rails 3.x
snippet vale
validate ${1:method_name}
snippet vals
validates ${1:column}
snippet valsp
validates ${1:column}, :presence => ${$1:true}
# RSpec 2.x
snippet desc
@nordringrayhide
nordringrayhide / nginx.sh
Created February 10, 2011 14:35
/etc/init.d/nginx - script file
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@nordringrayhide
nordringrayhide / snippets.nginx.conf
Created February 10, 2011 13:23
Maintenance mode nginx + capistrano
# cap web:deploy:desable & cap web:deploy:enable
server {
...
if (-f $document_root/system/maintenance.html) { set $maintenance 1; }
if ($request_uri ~* (jpg|jpeg|gif|js|css)$) { set $maintenance 0; }
if ($maintenance) { rewrite ^(.*)$ /system/maintenance.html; break; }
...
}
@nordringrayhide
nordringrayhide / git-timesheet
Created February 10, 2011 08:01
Git based Weekly report
git-timesheet
#!/usr/bin/env ruby
email = `git config --get user.email`
history = `git log --date=iso --since="1 week ago" --format="%ad %s" --no-merges --simplify-merges --reverse --committer=#{email}`
history.split(/\n/).group_by { |event| event[0,10] }.sort.reverse.each do |date, commits|
puts "#{date}\n#{"=" * 10 }"; puts commits.map { |commit| commit[10, 1024] }.sort; puts
end
# Then in your features you'll only need to call the `login_as` or `logout`
# methods. More info here: http://wiki.github.com/hassox/warden/testing
feature "Home page" do
background do
@user = User.create(...) # Or use fixtures, factories or whatever, even a
# stub user
login_as @user
visit home_page
@nordringrayhide
nordringrayhide / node_postgres_test.js
Created February 3, 2011 10:33
Access to Postgres with node.js
var pg = require("pg");
pg.connect('pg://postgres:password@localhost:5432/postgres', function(err, client) {
if (err) { console.log(err) ; } else {
client.query("select tablename from pg_tables;", function(err, result) {
if (err) {console.log(err)} else
{ for (var i=0; i < result.rows.length; i++) { console.log(result.rows[i].tablename) }
}
});
}
})
==begin
def self.options_for_select(story)
options = []
options << ["",""] if story.story_type_id.nil?
all.map{|story_type| options<<[story_type.title,story_type.id]}
options
end
==end
irb(main):021:0> [1,2,5].inject( true ? [nil] : [] ){|a, b| a + [b, 1]}