Skip to content

Instantly share code, notes, and snippets.

View joecannatti's full-sized avatar

Joe Cannatti joecannatti

View GitHub Profile
@joecannatti
joecannatti / conflictiingprince.rb
Created July 8, 2011 06:59
conflicting prince
class SessionsController
def create
user = log_in_user
user.send_current_notifications!
end
def log_in_user
account = #sign in with params
UserFactory.user_for_account(account)
end
RED="\[\033[1;31m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[1;32m\]"
NOCOLOR="\[\033[1;0m\]"
function parse_git_branch {
ref="$(git branch 2> /dev/null | sed -n "/*/ p" | awk '{ print $2 }')"
if [ -n "$ref" ]; then
echo "("${ref#refs/heads/}")"
fi
syntax enable
syntax on
set cursorline
set expandtab
set ts=2
set shiftwidth=2
set autoindent
set number
set background=dark
set nobackup
@joecannatti
joecannatti / prr.sh
Created July 26, 2011 18:33
pretty rake routes
function prr {
bundle exec rake routes | fgrep :action | \
\
awk '{
method="";
for(i=1;i<=NF;i++){
if ($i ~ /^\//){
example_url=$i;
}
else if($i ~ /[GET|PUT|POST|DELETE]/){
@joecannatti
joecannatti / makeuser.rb
Created August 23, 2011 15:20
creates a user who needs an invite
class MakeUserToInvite
def self.make(community_id=55,first_name=nil,last_name=nil,email=nil)
p = Person.new
p.first_name = first_name || random_string
p.last_name = last_name || random_string
e = EmailAddress.create(:person => p,
:email_address => (email || "#{random_string}@aoeuaoue.com"),
:confirmed_status => "confirmed",
:is_primary => true)
e.save
@joecannatti
joecannatti / splitsmod.sh
Created August 24, 2011 13:52
Open modified files in splits in Vi
vi -o $(git status | grep modified | awk '{print $3}')
@joecannatti
joecannatti / epub_permission.sh
Created November 2, 2011 01:53
epub_permission.sh
function kk {
echo ""
echo "The epubs on your desktop are:"
cd ~/Desktop;
index=0
FILES=()
for i in $(find . -name \*epub); do
@joecannatti
joecannatti / count.sh
Created November 8, 2011 16:09
One liner, count your CTO's code
count=0; for i in $(find . -name \*.rb); do count=`expr $count + $(git blame $i | grep "Anthony Broad" | wc -l)`; done; echo "ABC wrote $count lines of code";
@joecannatti
joecannatti / schema.sh
Created November 15, 2011 15:12
print a table from the schema in a rails project
schema ()
{
sed -n "/table \"$1\"/,/^ *end/ p" db/schema.rb
}
@joecannatti
joecannatti / euler67.r
Created December 28, 2011 02:13
euler67
#!/usr/bin/env Rscript
triangle <- read.table("padded_triangle.txt")
size <- 100
for(r in (size-1):1){
for(c in r:1){
max_value = max(triangle[r+1,c],triangle[r+1,c+1])
triangle[r,c] <- triangle[r,c] + max_value
}
}
print(triangle[1,1])