Skip to content

Instantly share code, notes, and snippets.

@hisea
hisea / togglable.html
Created December 30, 2010 23:09
togglable comment box
<a href="javascript:void(0)" class="toggleLink" data-mid="<%= message.id %>">Link to my partial</a>
<div id="add_comment<%=message.id%>" style="display:none">
Comment box
</div>
@hisea
hisea / git pretty log
Created December 22, 2011 05:25
.gitconfig
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
#git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
@hisea
hisea / gist:1548606
Created January 1, 2012 23:08
install node.js
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
@hisea
hisea / nginx
Created January 1, 2012 23:37
ubuntu passenger nginx init.d script
sudo cp nginx /etc/init.d/
sudo update-rc.d nginx defaults
sudo chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
@hisea
hisea / gist:3363163
Created August 15, 2012 20:06
Rake task with param and dependency
require 'resque/tasks'
namespace :ns do
desc "test task accepts param"
task :task, [:param] => [:environment] do |t,args|
abort "Please specify a param!" unless args[:param]
puts args[:param]
end
end
@hisea
hisea / private.xml
Created October 17, 2012 02:46
Happy Hacking Keyboard remap file for Keyremap4macbook
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>PFU</vendorname>
<vendorid>0x0853</vendorid>
</devicevendordef>
<deviceproductdef>
<productname>HHK</productname>
@hisea
hisea / gist:5129394
Created March 10, 2013 16:53
Configure Time Zone on Ubuntu
$ date
Sun Mar 10 12:50:37 EDT 2013
$ more /etc/timezone
America/Toronto
$ sudo dpkg-reconfigure tzdata
$ sudo service cron stop
# lib/tasks/deploy.rake
namespace :deploy do
desc 'Deploy to staging environment'
task :staging do
exec 'mina deploy -f config/deploy/staging.rb'
end
end
@hisea
hisea / max_subarray.rb
Created May 23, 2013 02:03
Get the sub-array with the maximum sum
def find_max_subarray(array)
max_sum = current_sum = current_start = start_idx = end_idx = cursor = 0
while cursor < array.length
current_test = current_sum + array[cursor]
if current_test > 0
if current_sum == 0
current_start = cursor
end
current_sum += array[cursor]
@hisea
hisea / max_subarray_2.rb
Created May 26, 2013 00:14
Max Subarray second version
def find_max_subarray(array)
#initialize all variables to zero
max_sum = current_sum = current_start = start_idx = end_idx = cursor = 0
# Go through individual element
for cursor in 0...array.length
# current_sum is the previous sum plus current element
current_sum += array[cursor]
if current_sum > max_sum # the case where the current sum is greater than the best sum so far.
# we set best sum so far to current sum