Skip to content

Instantly share code, notes, and snippets.

View johana-star's full-sized avatar
🕶️

Johana Star johana-star

🕶️
View GitHub Profile
@johana-star
johana-star / euler44.rb
Created June 4, 2011 20:53
Euler Project Problem #044
# Solution to Project Euler's forty-fourth problem
# http://projecteuler.net/index.php?section=problems&id=44
# Find the difference of the pair of pentagonal numbers whose sum and difference are both pentagonal.
def generate_pentagonals(floor = 1, ceiling = 2500)
pentagonals = Array.new
(floor..ceiling).each do |num|
pentagonals << create_pentagonal_number(num)
end
return pentagonals
end
@johana-star
johana-star / euler18.rb
Created June 6, 2011 22:26
Euler Project Problem #018
# Solution to Project Euler's eighteenth problem
# http://projecteuler.net/index.php?section=problems&id=18
# Find the greatest sum of a path in a triangle of integers.
def sum_triangle(sum, cache, triangle, line, index)
if triangle[line] == nil or triangle[line][index] == nil then
return cache
else
left = sum_triangle(sum + triangle[line][index], cache, triangle, line + 1, index)
right = sum_triangle(sum + triangle[line][index], cache, triangle, line + 1, index + 1)
@johana-star
johana-star / Gemfile
Created November 13, 2011 04:41
A Sinatra-based temperature convertor
source 'http://rubygems.org'
gem 'sinatra'
@johana-star
johana-star / config.yml
Created November 16, 2011 23:58
Fixed: my attempt at using a yml file to configure the twitter gem.
:twitter:
:consumer_key: Buncharandomletterssee
:consumer_secret: BuncharandomlettersautogeneratedformebyTwit
:oauth_token: Thisoneh-asadashinthemiddleofittomakeitseemmoreimp
:oauth_token_secret: IgetanilrelatederrorwhenItrytousethiscruftI
@johana-star
johana-star / authenticate.rb
Created November 20, 2011 23:36
Authenticate a twitter session as per the example at http://twitter.rubyforge.org/, but obfuscate the secrets into a YAML config file.
require 'twitter'
require 'yaml'
def authenticate
Twitter.configure do |c|
config = YAML.load(File.read("config.yml"))[:twitter]
c.consumer_key = config[:consumer_key]
c.consumer_secret = config[:consumer_secret]
c.oauth_token = config[:oauth_token]
@johana-star
johana-star / status_of_retweets.rb
Created December 10, 2011 02:36
Using the Twitter gem — looking to fix a truncating url issue.
=begin
I'm using the home_timeline method to get a collection of tweets, and it's giving me problems with tweets which have been retweeted. A retweet will often have a truncated URL in it's text like "http://t.co/V" in "RT @noirinp: The @adainitiative are open for donations! Donate @ http://t.co/T3obm0iQ or see cool stuff they're planning @ http://t.co/V ..."
by the way, you can pull this up in IRB with the following:
require "twitter"
tweet = Twitter.status(144927777588658177)
tweet.text
I'm using the code below to
=end
@johana-star
johana-star / README.md
Created December 26, 2011 22:22
Hungry Academy application part 2

This is part two of my application to Hungry Academy. Part one lives at: http://www.youtube.com/watch?v=-Ze-dcVY05k

Recently I [made a pull request][1] to improve Octopress' pullquote plugin.

The improvement happened in pullquote.rb and _typography.scss. These files allow users to create pullquotes as demonstrated in [the documentation][2]. Pullquotes are by default right-aligned. I wanted to be able to use pullquotes with either left or right alignment. I worked to modify existing code to allow left aligning pullquotes.

I added a condition which assigns a very simple regular expression to the existing initialization which assigns a variable to "left" if the liquid tag contains the word "left", and "right" otherwise. The plugin creates an html tag with alignment indicated in the class.

Then, I edited the Sass to interpret the new class to float left and mirror the margins of its right-aligned counterpart.

@johana-star
johana-star / kindle.awk
Created February 28, 2012 08:55
Kindle to Markdown v0.0001
# The flaw of this method is it assumes that there will be five lines per highlight/bookmark,
# which will not be the case on multiple paragraph highlights.
NR % 5 == 2 { if ($2) {print "> "$0; token = "true"} else {token = "false"} }
NR % 5 == 0 { if (token == "true") {printf "<div align='right'>–" $0 "</div>\n\n"} }
@johana-star
johana-star / fizzbuzz.coffee
Created March 20, 2012 22:19
FizzBuzz in CoffeeScript
for number in [1..100]
if number % 15 is 0
console.log "FizzBuzz"
else if number % 5 is 0
console.log "Buzz"
else if number % 3 is 0
console.log "Fizz"
else
console.log number
@johana-star
johana-star / fizzbuzz.rb
Created March 22, 2012 21:29
FizzBuzz in Ruby
(0..100).each do |number|
case
when number % 15 == 0 then puts "FizzBuzz"
when number % 5 == 0 then puts "Buzz"
when number % 3 == 0 then puts "Fizz"
else puts number
end
end