Skip to content

Instantly share code, notes, and snippets.

View bsodmike's full-sized avatar

Michael de Silva bsodmike

View GitHub Profile
@bsodmike
bsodmike / gist:912747
Created April 10, 2011 21:33
Capistrano-ext puzzling behaviour....
cap deploy:restart
triggering start callbacks for `deploy:restart'
* executing `multistage:ensure'
*** Defaulting to `production'
* executing `production'
* executing `deploy:restart'
[DEPRECATED] `deploy:restart` is going to be changed to Passenger mod_rails' method after 2.5.9 - see http://is.gd/2BPeA
* executing "/home/*******/current/script/process/reaper"
BUT!!
scope :current, where(:current=>true}
validate :only_one_current
protected
def only_one_current
errors.add_to_base("Only one event can be current") if Event.current.reject{|c| c.eql?(self)}.size>0
end
# Setup ruby for rails development. Installs [:rvm, :homebrew, :wget]
echo -e '\n\n###########################################\nThanks! Now grab a beverage...\nThis may take awhile\n###########################################\n\n'
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
brew install wget
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo -e "\n[[ -s '$HOME/.rvm/scripts/rvm' ]] && . '$HOME/.rvm/scripts/rvm' # This loads RVM into a shell session." >> ~/.bash_profile
source ~/.bash_profile
echo -e '\n\n###########################################\nDone!\n###########################################\n\n'
@bsodmike
bsodmike / ssh.conf
Created May 2, 2011 12:31
Update ssh.conf to avoid IP-address binding issue in Ubuntu Server 10.04 LTS
# ssh - OpenBSD Secure Shell server
#
# The OpenSSH server provides secure shell access to the system.
description "OpenSSH server"
# For Media Temple Linux (ve) VPS, use:
# start on filesystem and net-device-up IFACE=venet0:0
start on filesystem and net-device-up IFACE=eth0
stop on runlevel [!2345]
@bsodmike
bsodmike / gist:978493
Created May 18, 2011 12:33
Discrete PI Algorithm as a MATLAB S-file
function [sys,x0,str,ts]=pialg2(t,x,u,flag,k,z1,dt,vmin,vmax)
%discrete PI algorithm
%v(nh)=k*u(nh)-k*z1*u((n-1)h)+v((n-1)h)
% dt sampling time, the same as h.
if abs(flag)==2
sys(1)=k*(1-z1)*u+x(1);
elseif flag==3
v=k*u+x(1);
if v>vmax
v=vmax;
@bsodmike
bsodmike / gist:978979
Created May 18, 2011 16:46
MATLAB S-function m-file template
% low-pass FIR filter code goes like this:
%trialfirS An M-file S-function
function [sys,x0,str,ts] = trialfirS(t,x,u,flag)
h=fir1(32,0.5);
ipv=randn(1,100);
switch flag,
@bsodmike
bsodmike / Gemfile
Created May 19, 2011 22:07
Fancier client_side_validations Callbacks for element validation
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'sqlite3'
# gem 'nifty-generators'
# gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'jquery-rails', '1.0.5'
gem 'client_side_validations'
@bsodmike
bsodmike / gist:988751
Created May 24, 2011 13:59
Adding a textfield programmatically to a view in IOS
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(300, 300, 200, 30);
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textColor = [UIColor blackColor];
textField.font = [UIFont systemFontOfSize:17.0];
@bsodmike
bsodmike / Gemfile
Created May 29, 2011 19:31
Capistrano multistage deployment configuration. This example is deployed from the 'dev' branch.
# Deploy with Capistrano
gem 'capistrano'
gem 'capistrano-ext'
@bsodmike
bsodmike / gist:998095
Created May 29, 2011 20:04
HOWTO: Changing repo url in a Capistrano deployed app
Update the remote's url in the files below:
shared/cached-copy/.git/config
current/.git/config