Skip to content

Instantly share code, notes, and snippets.

View tibbon's full-sized avatar

David Fisher tibbon

View GitHub Profile
@tibbon
tibbon / strategy.rb
Created August 15, 2013 23:22
Rails caching strategy
// The parameter for search-name should be sanitized in some way of course
@api_result = Rails.cache.fetch("foursquare-#{search-name}") do
Foursquare.search(search-name)
end
@tibbon
tibbon / gist:6234437
Last active December 21, 2015 02:19
Backbone Temp
var Project = Backbone.Model.extend({
// STEP 5: This is a model of our data that describes its behavior
idAttribute: 'slug',
defaults: {
name: "Default Project",
slug: 'default-project',
github_url: "http://github.com/tibbon/portfolio",
live_url: "http://tibbon.com",
thumbnail_url: "http://github.com/tibbon/portfolio/preview.png",
description: "This is my really awesome portfolio page. Can\'t you see I like making portfolios?"
@tibbon
tibbon / gist:6233764
Last active December 21, 2015 02:18
Backbone start point
<!DOCTYPE html>
<html>
<head>
<title>David Fisher Portfolio</title>
<link href="styles.css" rel="stylesheet" />
</head>
<body>
<script id="project-template" type="x-handlebars-template">
<div class="project">
<h2>{{name}}</h2>
@tibbon
tibbon / gist:6222633
Created August 13, 2013 15:55
Infinite Scroll Logic
$(window).scroll(function() {
// Cache our jQuery selector for window
var win = $(window);
// Infinite scroll math!
if(win.height() + win.scrollTop() >= $(document).height()) {
populateCountries();
}
});
@tibbon
tibbon / stream.rb
Created August 9, 2013 18:35
tweet stream
require 'tweetstream'
TweetStream.configure do |config|
config.consumer_key = 'YOUR-KEY'
config.consumer_secret = 'YOUR-SECRET'
config.oauth_token = 'YOUR-OAUTH'
config.oauth_token_secret = 'YOUR-OAUTH-SECRET'
config.auth_method = :oauth
end
@tibbon
tibbon / gist:6115993
Created July 30, 2013 19:20
ATM Solution
var checkingBalance = 0;
var savingsBalance = 0;
// replace window.onload
$(function() {
$("#checkingDeposit").click(depositChecking);
$("#savingsDeposit").click(depositSaving);
$("#checkingWithdraw").click(withdrawChecking);
$("#savingsWithdraw").click(withdrawSaving);
updateDisplay();
@tibbon
tibbon / gist:6073142
Last active December 20, 2015 04:48
Objects and Prototype
// String literal, string primitive
// This is not an object
// This doesn't have any of its own functions
var schoolName = "General Assembly"
// When I call this, it temporarily makes a String Object around it.
// Slower. I'll talk about why in a second
var upperCaseSchoolName = schoolName.toUpperCase
/*
@tibbon
tibbon / gist:6065875
Created July 23, 2013 20:29
Javascript Scope
function calculateHeight(startPoint, endPoint) {
// This function has access to startPoint and endPoint. Nothing else does.
return Math.abs(startPoint - endPoint)
}
function calculateWidth(startWidth, endWidth) {
// Function arguments act as local. ie. startWidth here is local
// This function has access to startWidth and endWidth. Nothing else does.
// Does this have access to a, b, x, y? No
// Does this have access to q? No
@tibbon
tibbon / gist:5962843
Created July 10, 2013 01:39
Validating uniqueness at the DB/migration level
class AddUniquenessIndexToYears < ActiveRecord::Migration
def change
add_index :years, [:award_id, :book_id], :unique => true
end
end