Skip to content

Instantly share code, notes, and snippets.

@juliantai
juliantai / UIImage+Resize.swift
Created September 13, 2018 23:01 — forked from bgreenlee/UIImage+Resize.swift
Swift port of UIImage+Resize, UIImage+Alpha, and UIImage+RoundedCorner, from http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/
//
// UIImage+Resize.swift
// Port of UIImage+Resize.m
// from http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/
//
import Foundation
import UIKit
extension UIImage {
@juliantai
juliantai / poppler.rb
Created April 18, 2017 21:17 — forked from mtyaka/poppler.rb
Homebrew formula that installs poppler 0.22.5 with several patches applied to the pdftocairo utility. The patches fix output to stdout and add -jpegquality <int> and -pngcompression <int> command line options.
require 'formula'
class PopplerData < Formula
url 'http://poppler.freedesktop.org/poppler-data-0.4.6.tar.gz'
sha1 'f030563eed9f93912b1a546e6d87936d07d7f27d'
end
class Poppler < Formula
homepage 'http://poppler.freedesktop.org'
url 'http://poppler.freedesktop.org/poppler-0.22.5.tar.gz'
@juliantai
juliantai / 01 capybara.rb
Created April 3, 2017 21:15 — forked from asavin/01 capybara.rb
Gists for the Automated cross-browser testing blogpost
# features/support/capybara.rb
Capybara.app_host = 'http://staging.my-app.com'
function Game(rows, columns) {
this.board = this.buildBoard(rows, columns);
}
Game.prototype.buildBoard = function(rows, columns) {
var arr = [];
for(var i = 0; i < rows; i++) {
arr[i] = new Array(columns);
}
@juliantai
juliantai / reactor.js
Last active August 29, 2015 14:24 — forked from mohsen1/reactor.js
function Event(name){
this.name = name;
this.callbacks = [];
}
Event.prototype.registerCallback = function(callback){
this.callbacks.push(callback);
}
function Reactor(){
this.events = {};

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.