Skip to content

Instantly share code, notes, and snippets.

View piersadrian's full-sized avatar

Piers Mainwaring piersadrian

View GitHub Profile
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 / 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)
- (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];
{
"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":
[
# 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!
module SessionsHelper
...
def authenticate!
raise ActionController::RoutingError.new("Unauthorized") unless signed_in?
end
end
class SomeController
array = response['equipmentItems'];
parentElement = $('select')[0];
for (var i = 0; i < array.count; i++) {
currentObj = array[i];
newElement = document.createElement('option');
newElement.value = currentObj.someAttribute;
newElement.innerText = "Some Label";
before_filter :validate_request_format
# ...
def send_response data
respond_with(data) do |format|
format.js { render json: data, callback: params[:callback] } # JSONP
format.json { render }
format.xml { render }
end
[self.tabBarController.view setFrame: CGRectMake([[UIScreen mainScreen] applicationFrame].origin.x,
[[UIScreen mainScreen] applicationFrame].origin.y,
[[UIScreen mainScreen] applicationFrame].size.width,
[[UIScreen mainScreen] applicationFrame].size.height - self.tabBarController.tabBar.frame.size.height)];
UIButton *fetchButton = ^(NSString *labelText, CGFloat scalar, UIButtonType type, CGPoint origin) {
UIButton *button = [UIButton buttonWithType:type];
UILabel *label = [[UILabel alloc] init];
[label setText:labelText];
CGSize buttonFrameSize = CGSizeMake([label.text sizeWithFont:label.font].width * scalar * 0.66f,
[label.text sizeWithFont:label.font].height * scalar);