Skip to content

Instantly share code, notes, and snippets.

View leomao10's full-sized avatar

leo liang leomao10

  • Atlassian
  • Sydney
View GitHub Profile
# Reference http://stackoverflow.com/a/18490935/2037928
# Login as root
# Install needed packages
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
# Download appropriate ruby version https://www.ruby-lang.org/en/downloads/
@leomao10
leomao10 / Config.xml
Created October 25, 2010 05:11
typeAlias in Spring.xml
<!-- in spring config xml file-->
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="program" type="Prog" />
<object id="myTypeAlias" type="Spring.Objects.Factory.Config.TypeAliasConfigurer, Spring.Core">
<property name="TypeAliases">
<dictionary>
<entry key="Prog" value="MyNs.Program, MyLibrary"/>
@leomao10
leomao10 / XPathWithNamespace.cs
Created October 31, 2010 00:28
How to use XPath to search an element with namespace
XDocument d = XDocument.Parse("<p:root xmlns:p='P'><p:e/></p:root>");
XmlNamespaceManager r = new XmlNamespaceManager(new NameTable());
r.AddNamespace("p", "P");
XElement e = d.XPathSelectElement("//p:e", r);
Console.WriteLine(e);
@leomao10
leomao10 / sample.sql
Created November 1, 2010 06:55
Accessing the Windows File System from SQL Server
--Extended Stored Procedure - xp_cmdshell - Ability to execute any DOS command line code.
EXEC master.dbo.xp_cmdshell 'dir c:\'
GO
--Extended Stored Procedure - xp_fixeddrives - Ability to capture the free drive space in megabytes.
EXEC master.dbo.xp_fixeddrives
GO
--Extended Stored Procedure - xp_subdirs - Ability to capture the sub directories, but not files
EXEC master.dbo.xp_subdirs 'c:\'
GO
@leomao10
leomao10 / rvm.sh
Created November 5, 2010 03:53
common command for rvm
#it is always a good pratice to update and reload RVM itself
rvm update --head
rvm reload
#install different version of ruby
rvm install 1.8.7
rvm install 1.9.2
#create different gemsets
rvm --create 1.8.7@rails2
@leomao10
leomao10 / ReflectionConstructor.cs
Created November 9, 2010 02:29
How to Construct a class with Reflection
value = (IZType)property.PropertyType.GetConstructor(new Type[] { typeof(object) }).Invoke(new object[] { value });
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
@leomao10
leomao10 / gist:1390317
Created November 24, 2011 00:13 — forked from freshtonic/gist:1390291
Run Postgres Specs in Ramdisk
  • This creates a 560mb ramdisk. Adjust the size accordingly. I think the number at the end of the command is the number of disk blocks. They are 2kb in size for me.
  • Restarting postgres is not necessary; you can create the ramdisk and tablespace while postgres is running.
  • You will lose all data in the ramdisk tablespace when you shut your machine down

  $ diskutil erasevolume HFS+ "postgres_ramdisk" `hdiutil attach -nomount ram://1165430`
  Started erase on disk1
  Unmounting disk
  Erasing
 Initialized /dev/rdisk1 as a 569 MB HFS Plus volume
source "http://rubygems.org"
gemspec
group :development do
gem 'combustion', '~> 0.3.0'
end
group :development, :test do
gem "rspec-rails"
@leomao10
leomao10 / resque.sh
Created February 28, 2012 03:17 — forked from cwise/resque.sh
Rewritten /engineyard/bin/resque
#!/bin/bash
#
# This script starts and stops the Resque daemon
# This script belongs in /engineyard/bin/resque
#
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
CURDIR=`pwd`
usage() {