Skip to content

Instantly share code, notes, and snippets.

View piersadrian's full-sized avatar

Piers Mainwaring piersadrian

View GitHub Profile
module SessionsHelper
...
def authenticate!
raise ActionController::RoutingError.new("Unauthorized") unless signed_in?
end
end
class SomeController
# routes.rb
constraints format: "html" do
get "*path", to: "angular#index", as: "angular"
end
# angular_controller.rb
class AngularController < ActionController::Base
VALID_PATHS = %w(/community /store /challenges /admin/health /admin/activities /admin/challenges /admin/budget)
before_action :verify_path!
{
"auto_complete_commit_on_tab": true,
"auto_complete_delay": 50,
"bold_folder_labels": true,
"caret_style": "phase",
"color_scheme": "Packages/tomorrow-theme/textmate/Tomorrow-Night.tmTheme",
"create_window_at_startup": false,
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (! cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
cell = [self addLabelsToCell:cell];
}
NSDictionary *client = [[clientTypes objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
@piersadrian
piersadrian / seed_data.rb
Created November 24, 2013 23:55
Rails 4 seed data dumper/loader
class SeedData
class << self
FILE_EXT = "json".freeze
MODEL_DIR = "#{ Rails.root }/db/models".freeze
# Dumps the contents every model into pretty-formatted JSON in the given
# directory. This lets us just make quick changes to the JSON structure and
# reimport the data (using #load) directly into the database.
def dump!(output_dir = MODEL_DIR)
class GameOfLife
def initialize(size)
@size = size
@grid = make_grid(true)
@next_grid = make_grid(false)
@grid_hash = nil
# Create offset masks excluding [0, 0], which is the cell in question. The
# masks look like [-1, 0] or [1, 1] and represent the offset from the
@piersadrian
piersadrian / index.jade
Created February 26, 2014 19:04
yeoman, bower, h5bp, angular-compatible index.jade
doctype html
| <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
| <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
| <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
| <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
head
meta(charset='utf-8')
meta(http-equiv='X-UA-Compatible', content='IE=edge')
title
meta(name='description', content='')
@piersadrian
piersadrian / Gruntfile.js
Last active August 29, 2015 13:56
Gruntfile with coffeescript, rails proxy, and jade
// Generated on 2014-02-26 using generator-angular 0.7.1
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
'use strict'
app = angular.module('ngContentApp')
class BaseCtrl
@$inject: ['$scope', '$location', '$route']
constructor: (dependencies...) ->
# Construct a map of injected dependencies.
deps = {}
'use strict';
var BaseCtrl, ConditionEditCtrl, ConditionsListCtrl, EditCtrl, app,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
app = angular.module('ngContentApp');
BaseCtrl = (function() {