Skip to content

Instantly share code, notes, and snippets.

View fables-tales's full-sized avatar
💭
I may be slow to respond.

Fable Tales fables-tales

💭
I may be slow to respond.
View GitHub Profile

#The secret weapon in your refactoring toolbelt: Types

Types. Even saying the word makes most Rubyists run, screaming for their lives. Didn't we do away with all that public static void main nonsense a long time ago? Well yes. Yet: we shouldn't underestimate the importance of thinking about types. Even when building apps in ruby.

In this talk we'll cover:

  • Basic type theory as it applies to ruby
  • How to use types to improve our applications
  • What affects types have on our objects every day
class PlingPlangPlong
def initialize(number)
@number = number
end
def call
has_terms? ? joined_terms : number.to_s
end
private
(1579-cleanup)$ bundle exec ruby hi_spec.rb
No examples found.
Finished in 0.00011 seconds
0 examples, 0 failures
Randomized with seed 41752
No examples found.
arena.init = function() {
srobo.init(function() {
var badCorner = function(cornerDefs) {
var buttonsDiv = document.createElement("div");
var showButtons = function(cornerDefs) {
srobo.competition.arenas(function(arenas) {
if (typeof(arenas) === 'string') {
arenas = JSON.parse(arenas);
}
arenas = arenas.arenas;
RSpec::Matchers.define :be_a_multiple_of do |expected|
match do |actual|
expcted = expected + "hi!"
RSpec::Matchers::BuiltIn::Equal.new(expected).send(:match, expected, actual)
end
end

#Vim ultrahardmode proposal

  • a single of hjklweb and so on is allowed
  • large motions: e.g. 10k and 10j are allowed
  • no insert mode

##Required leaders

  • map <leader>ei :s/^//<left> (insert into current line line)
  • map et :s/// (substitute on this line)
describe "doing things" do
let(:a) { double(:a) }
let(:b) { double(:b) }
let(:c) { [a,b] }
it "works" do
expect(c).to eq([a,b])
end
end
require "faraday"
def test_client(app)
Faraday.new do |conn|
conn.request :url_encoded
conn.adapter :rack, app
end
end
Going on tour is hard. You've got to find someone to tour with. You've got to pick cities and venues. You've got to book hotels, find places to eat and drink. All of this takes far too much time.
This is your Tour automates this process on a per artist basis. By intelligently querying datasets around the internet it's able to save you a bunch of hassle. Get a quick and easy list of all the cities and venues you should visit, as well as the places to go once you're done gigging.
import requests
from bs4 import BeautifulSoup
class YelpRequester:
def find_best_thing(self, category, place):
root_url = "http://www.yelp.co.uk/search?find_desc=" + category + "&find_loc=" + place + "&ns=1&#sortby=rating"
response = requests.get(root_url).text
soup = BeautifulSoup(response)
best_place = soup.findAll(attrs={"class":"biz-name"})[1]
next_url = "http://www.yelp.co.uk/" + best_place.attrs["href"]