Skip to content

Instantly share code, notes, and snippets.

View joecannatti's full-sized avatar

Joe Cannatti joecannatti

View GitHub Profile
@joecannatti
joecannatti / euler36.rb
Created December 28, 2011 02:49
euler36
#!/usr/bin/env ruby
results = []
(1..1000000).each do |value|
if((value.to_s == value.to_s.reverse) && (value.to_s(2) == value.to_s(2).reverse))
results << value
end
end
p results.inject(&:+)
@joecannatti
joecannatti / euler29.rb
Created December 28, 2011 02:38
Euler29
#!/usr/bin/env ruby
START=2
STOP=100
pairs_without_repeats = []
(START..STOP).each { |outer|
(START..outer).each{ |inner|
pairs_without_repeats << [outer,inner]
}
}
@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])
@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 / 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 / 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 / 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 / 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 / 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]/){
syntax enable
syntax on
set cursorline
set expandtab
set ts=2
set shiftwidth=2
set autoindent
set number
set background=dark
set nobackup