Skip to content

Instantly share code, notes, and snippets.

class Friend
def self.service(current_user)
TwitterService.new(current_user)
end
def self.get_friends(current_user)
friends_json = service(current_user).friends
friends = friends_json.map do |friend|
build_object(friend)
end
class TwitterService
attr_reader :connection, :user
def initialize(user)
@user = user
@connection = Faraday.new(url: "https://api.twitter.com/")
end
def friends
response = connection.get do |req|
require 'sinatra/base'
class FakeSuperCool < Sinatra::Base
get "/api/" do
if params[:keywords] == 'ruby'
json_response 200, 'super_cool_ruby_response.json'
elsif params[:keywords] == 'rubular'
json_response 200, 'super_cool_no_results_response.json'
elsif params[:api_key] == '123'
json_response 200, 'super_cool_bad_api_key_response.json'
# spec/spec_helper.rb
RSpec.configure do |config|
config.before(:each) do
stub_request(:any, /supercool.com/).to_rack(FakeSuperCool)
end
end
@bethsecor
bethsecor / require.markdown
Last active March 31, 2016 03:44 — forked from rrgayhart/require.markdown
The Concept of Require

When you start working with WebPack for GameTime, you'll notice that you can't just define a variable in one file and find it in another as easily as you can in Rails.

Read Node.js, Require and Exports and Organize Your Code with RequireJS

Fork this gist and answer the following questions:

  • In the context of Node, what is a module?
  • A module is a piece of your javascript code that could contain a class, or functions, or variables that are common or related to each other and warrant their own file.

JavaScript Functions

I can explain the difference between function declarations and function expressions.

  • Yes!

I can explain what the value of this is in a normal function.

  • global window
<div itemscope itemtype="http://schema.org/Movie">
<h1 itemprop="name">Avatar</h1>
<div itemprop="director" itemscope itemtype="http://schema.org/Person">
Director: <span itemprop="name">James Cameron</span> (born <span itemprop="birthDate">August 16, 1954</span>)
</div>
<span itemprop="genre">Science fiction</span>
<a href="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>
@bethsecor
bethsecor / package-management.markdown
Last active March 24, 2016 19:47 — forked from rrgayhart/package-management.markdown
The Dangers of Using Code You Don't Control

The Dangers of Using Code You Don't Control


Checks for Understanding

  • In broad strokes, summarize the event

    • A guy had created an open source npm package called kik and and a company called Kik asked him if he could change the name of his package. In my opinion neither party handled the situation very professionally so I'm not surprised this happened. The guy who created kik got so upset that he unpublished all of his packages, one of which included left-pad. Apparently many applications depended on this package, so for about 3 hours they were all down until npm "un-unpublished" the package to fix everything.
Discuss Speaking JavaScript, especially following chapters here:

Chapter 3: The Nature of JavaScript

  • "And you can directly create objects, without creating an object factory (e.g., a class) first." I never thought about this until now.
  • "It fails silently." Yikes!
  • "it has no block-scoped variables." I thought let allowed you to declare a variable within the scope of a block?
  • What do you expect for a language that was written in 10 days? It's not perfect!

Respond in the comments of this issue with:

  1. What is something you learned that was particularly surprising/interesting?
  • I didn't know that if you don't specify the var before declaring a variable in javascript, it will be a global variable. That seems a little dangerous if you forget that!
  • I also did not know that $() will always return a jQuery object even if the selector isn't found (so you want to look at the length of the array that's returned to make sure it's not empty)
  • Namespaced events seem incredibly useful.
  • The event object is also very cool.
  1. What was something you already knew?