Skip to content

Instantly share code, notes, and snippets.

View stevecass's full-sized avatar

Steven Cassidy stevecass

  • 13:52 (UTC -04:00)
View GitHub Profile
@stevecass
stevecass / gist:586957197295028635d6
Created June 1, 2015 19:32
Using twitter-typeahead-rails
<input class="typeahead">
<script>
var substringMatcher = function(states) {
return function findMatches(q, cb) {
var matches, substringRegex;
// an array that will be populated with substring matches
matches = [];
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
</head>
<body id="body">
<button>Click me and watch the console</button>
<script>
function f() {
(function(){
var loadFirstNumber = function(){
return new Promise(function(resolve, reject){
var request = $.ajax({
method: 'get',
url:'/first.json',
})
request.done(function(result){
resolve(result.value);
@stevecass
stevecass / using-ar-extensions.md
Last active January 18, 2016 22:52
Using ActiveRecord associations to select and order data sets

##Letting Your ActiveRecord Associations Help

Suppose you have the following models:

class User < ActiveRecord::Base
  has_many :blogs
  has_many :posts, through: :blogs
  has_many :received_comments, through: :posts, source: :comments
  has_many :expressed_comments, class_name: 'Comment', foreign_key: 'user_id'
@stevecass
stevecass / notes.js
Last active February 13, 2016 17:32
Some notes on Javascript
//variables declared in global scope become properties of the window in browser environments
var a = 123;
console.log('a', window.a);
// functions introduce scope. A variable declared inside a function is not visible outside
function f() {
var b = 456;
console.log('b', b);
// inside the function we can still see the global a. We don't need "window." - it's implied
console.log('a', a);
// ES 6 basics
setTimeout(() => {
console.log('Hello');
console.log('Goodbye');
}, 200);
// One - liners can omit the { }
// and implicitly return the value of their statement
setTimeout(() => 5, 200)
# Model files
class Match < ActiveRecord::Base
belongs_to :source, foreign_key: 'from_id', class_name: Personality
belongs_to :target, foreign_key: 'to_id', class_name: Personality
end
class Person < ActiveRecord::Base
belongs_to :personality
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>