This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import oauth2 as oauth | |
import httplib2 | |
import time, os | |
#authenticate | |
api_key = 'XXXXX' | |
api_secret = 'XXXXX' | |
user_token = 'XXXXX' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop | |
x = 0 | |
loop do | |
x += 1 | |
puts x | |
break if x > 4 | |
end | |
puts | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a Proc to use with a Block | |
multiples = Proc.new do |n| | |
n % 5 == 0 || n % 7 == 0 | |
end | |
# turn the Proc into a Block | |
array = (1..99).to_a.select(&multiples) | |
# sum the members of the array | |
array.inject{|sum,x| sum + x } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = (1..10) | |
array1 = numbers.to_a | |
array2 = numbers.to_a | |
# map | |
strings_map = array1.map(&:to_s) | |
# collect | |
strings_collect = array2.collect(&:to_s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num1 = 0 | |
num2 = 1 | |
i = 0 | |
total = 0 | |
while i <= 2000 | |
# add previous two values | |
i = num1 + num2 | |
# if i is odd, add it to the total | |
if i % 2 != 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array = [43, "Foo Fighters", 45.7, "not_true", :beans, 8, 42.34] | |
strings = array.select {|x| x.is_a? String} | |
symbols = array.select {|x| x.is_a? Symbol} | |
integers = array.select {|x| x.is_a? Integer} | |
floats = array.select {|x| x.is_a? Float} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
# initialize fire's up each object in the class | |
def initialize(name) | |
# @ indicates that the variable is attached to the instance of the class | |
@name = name | |
end | |
def name | |
puts "Hi, my name is #{@name}." | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system("clear") | |
socks = Hash.new | |
puts | |
puts "To find your missing sock(s) -" | |
puts " (1) Enter all of your sock colors/patterns." | |
puts " (2) Type \"quit\" when done." | |
puts " (3) Look at the results." | |
puts | |
puts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GuessingGame | |
def initialize(answer) | |
@answer = answer | |
end | |
def guess(guess) | |
@guess = guess | |
if guess > @answer | |
puts "high" | |
return :high |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create an app on https://dev.twitter.com/, make sure you leave Callback URL blank (so that it will return to a page where twitter shows you a PIN, useful during twitCred$handshake below. Don't worry yet, read on.) | |
Run these on R (on separate lines): | |
reqURL <- "https://api.twitter.com/oauth/request_token" | |
accessURL <- "http://api.twitter.com/oauth/access_token" | |
authURL <- "http://api.twitter.com/oauth/authorize" | |
consumerKey <- "yourconsumerkey" | |
consumerSecret <- "yourconsumersecret" | |
twitCred <- OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret,requestURL=reqURL,accessURL=accessURL,authURL=authURL) |
OlderNewer