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 / index.erb
Created April 2, 2012 06:28
How to create a basic language selector with jQuery that's testable in Cucumber
<!-- in lib/views/index.erb -->
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Strand Beer</title>
</head>
<body>
<a href="" id="en">EN</a> | <a href="" id="zh">ZH</a>
<p class='en' lang='en'>This is English content.</p>
@johana-star
johana-star / fizzbuzz_revised.rb
Created March 25, 2012 08:53
FizzBuzz in Ruby (revised
(0..100).each do |number|
case
when number % 3 == 0 then puts "Fizz" + ("Buzz" if number % 5 == 0).to_s
when number % 5 == 0 then puts "Buzz"
else puts number
end
end
@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
@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 / 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 / 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 / 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 / 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 / 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 / Gemfile
Created November 13, 2011 04:41
A Sinatra-based temperature convertor
source 'http://rubygems.org'
gem 'sinatra'