Skip to content

Instantly share code, notes, and snippets.

@jackcallister
jackcallister / gist:599a5de9eefbc41bc33f
Created November 7, 2014 03:41
Webpack Component Config
module.exports = {
entry: './example/main.js',
output: {
filename: './build/bundle.js'
},
module: {
loaders: [
{test: /\.js$/, loader: 'jsx-loader'}
]
}
@jackcallister
jackcallister / avatar.rb
Created August 24, 2014 03:36
Default avatars
require 'net/http'
class Avatar
attr_accessor :email, :response
def initialize(email)
@email = email
end
def self.default_urls
App.Router.map ->
@resource 'schedules', ->
@resource 'schedule', { path: '/:schedule_id' }, ->
@resource 'events'
App.EventsRoute = Ember.Route.extend
model: ->
@modelFor('schedule').get('events')
App.Schedule = DS.Model.extend
@jackcallister
jackcallister / base_controller.rb
Created April 29, 2014 12:13
API Base Controller
class API::BaseController < ApplicationController
respond_to :json
before_action :set_default_format, :assert_valid_format!, :authenticate_from_token!, :authenticate_client!
protected
def authenticate_from_token!
token = request.headers['X-Authentication-Token']
id = request.headers['X-Authentication-Id']
@jackcallister
jackcallister / build.rake
Created April 23, 2014 10:53
Turn Rails into a SPA generator
namespace :app do
desc "Build static distrubution"
task :build do
puts "Building..."
# Shell out for now...
`bundle exec rake assets:clean`
puts "Compiling"
`bundle exec rake assets:precompile`
puts "Starting web get"
@jackcallister
jackcallister / ViewController.m
Created December 17, 2013 21:13
Tim, help me. Animating with Objective-C
-(void)animateButton:(UIButton *)sender
{
CGRect originalFrame = sender.frame;
CGRect newFrame = CGRectMake(originalFrame.origin.x - 3, originalFrame.origin.y - 3, originalFrame.size.width + 6, originalFrame.size.height + 6);
[UIView animateWithDuration:0.4 delay:0 options:(UIViewAnimationOptionAutoreverse)
animations:^{
sender.frame = newFrame;
}
completion:^(BOOL finished){
@jackcallister
jackcallister / publishable.rb
Created November 12, 2013 04:29
Pending changes
def pending_changes?
return false if !status.published?
original_attributes = Product.last.attributes.symbolize_keys.except(*publish_excluded_attributes)
published_attributes = Product.last.published_record.attributes.symbolize_keys.except(*publish_excluded_attributes)
original_attributes == published_attributes ? false : update_attribute(:published_status, 'changed')
end
@jackcallister
jackcallister / model.rb
Created August 9, 2013 01:18
Model method delegation
# Delegate in a block to set up multiple delegations
with_options allow_nil: true do |product_delegate|
product_delegate.delegate :fields, to: :product_type
end
# Delegate as a method call
delegate :fields, to: :product_type, allow_nil: true
@jackcallister
jackcallister / spaces.css.scss
Created August 7, 2013 02:26
Spaces utility
// Should be used to modify the default spacing between objects (not between nodes of * the same object)
// p,m = padding,margin
// a,t,r,b,l,h,v = all,top,right,bottom,left,horizontal,vertical
// x,s,m,l,n = extra-small($x),small($s),medium($m),large($l),none(0px)
$x: 3px;
$s: 5px;
$m: 10px;
$l: 20px;
.ptn, .pvn, .pan {
@jackcallister
jackcallister / define_method.rb
Created August 7, 2013 01:58
Generatively defining a method
self.markdownable_columns.each do |markdown_column|
define_method :"#{markdown_column}_html" do
if value = send(markdown_column)
<Application>::Application.config.markdown_renderer.render(value).html_safe
end
end
end