Skip to content

Instantly share code, notes, and snippets.

View michaelrkn's full-sized avatar

Michael Kaiser-Nyman michaelrkn

View GitHub Profile
@michaelrkn
michaelrkn / scripts.js
Last active July 11, 2021 23:51
JavaScript for Pig Dice
var Player = {
setNumber: function(number) {
this.number = number;
},
addPoints: function(points) {
this.score += points;
},
score: 0
};
@michaelrkn
michaelrkn / setup.sh
Last active April 6, 2019 16:29
to do: figure out how to clear databases and files nightly; make everybody save their code in a code folder or something, and don't let them write to other folders (except .gem, homebrew, etc)
# run this block as root to avoid typing password
sudo rm -rf /Applications/GarageBand.app/ /Applications/iMovie.app/ /Applications/iPhoto.app/ /User\ Information
mkdir /usr/local
curl -L https://github.com/Homebrew/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
sudo chown -R epicodus /usr/local
xcode-select --install
# manually click to start command line tools install, then run everything else as current user
class Triangle
def initialize(sides)
@sides = sides
end
def type
@sides.sort!
if @sides[0] + @sides[1] <= @sides[2]
:invalid
else
@michaelrkn
michaelrkn / stubs.rb
Created March 20, 2013 19:49
twitter oauth stubs
stub_request(:post, "https://api.twitter.com/oauth/request_token").
to_return(:body => "oauth_token=t&oauth_token_secret=s")
stub_request(:post, "https://api.twitter.com/oauth/access_token").
to_return(:body => "oauth_token=at&oauth_token_secret=as&screen_name=sn")
@michaelrkn
michaelrkn / twitter_oauth.rb
Created March 20, 2013 17:18
command line oauth for twitter
require 'oauth'
require 'launchy'
CONSUMER_KEY = 'your_consumer_key'
CONSUMER_SECRET = 'your_consumer_secret'
CALLBACK_URL = 'oob'
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => "https://api.twitter.com/")
request_token = consumer.get_request_token(:oauth_callback => CALLBACK_URL)
@michaelrkn
michaelrkn / instagram.rb
Created March 20, 2013 05:41
getting the access token for instagram from the command line
require 'launchy'
CLIENT_ID = 'a3506a51a28b4d639ca680123c43f88d'
REDIRECT_URI = 'http://www.epicodus.com/'
puts 'To use InstaCommandLine, you need to grant access to the app.'
puts 'Press enter to launch your web browser and grant access.'
gets
Launchy.open "https://instagram.com/oauth/authorize/?client_id=#{CLIENT_ID}&redirect_uri=#{REDIRECT_URI}&response_type=token"
@michaelrkn
michaelrkn / twilio.rb
Last active December 15, 2015 04:09
twilio auth
TEST_ACCOUNT_SID = 'whatever'
TEST_AUTH_TOKEN = 'ha'
require 'faraday'
require 'base64'
post_response = Faraday.post do |request|
request.url "https://api.twilio.com/2010-04-01/Accounts/#{TEST_ACCOUNT_SID}/SMS/Messages.json"
request.headers['Authorization'] = "Basic " + Base64.strict_encode64("#{TEST_ACCOUNT_SID}:#{TEST_AUTH_TOKEN}")
request.body = URI.encode_www_form({'From' => '+15005550006', 'To' => '+14155551212', 'Body' => 'hello world!'})
@michaelrkn
michaelrkn / foo.rb
Last active December 15, 2015 03:59
active model validations
require 'active_model'
class Foo
include ActiveModel::Validations
attr_accessor :name
validates :name, :presence => true
def initialize(options={})
@michaelrkn
michaelrkn / gist_spec.rb
Last active December 15, 2015 02:39
webmock stub example
require 'spec_helper'
describe Gist do
context '.create' do
it 'POSTs a new Gist to the user\'s account' do
gist = {:public => 'true',
:description => 'a test gist',
:files => {'test_file.rb' => {:content => 'puts "hello world!"'}}}
stub = stub_request(:post, "https://#{GITHUB_USERNAME}:#{GITHUB_PASSWORD}@api.github.com/gists").with(:body => gist.to_json)
Gist.create(gist)
@michaelrkn
michaelrkn / factorial.rb
Last active December 11, 2015 16:48 — forked from pjlowry/factorial.rb
def factorial(n)
if n < 0
raise "You can't take the factorial of a negative number."
elsif n == 0
1
else
(1..n).inject(:*)
end
end