Skip to content

Instantly share code, notes, and snippets.

View macu's full-sized avatar

Matt Cudmore macu

  • Halifax, NS
View GitHub Profile
@macu
macu / ember-naming.html
Created March 5, 2014 15:12
Ember naming conventions, compiled points (as of Ember v1.4.0)
<script type="text/x-handlebars">
The application template (outer scaffold) has no name, or has the name "application".
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="dashboard">
This template embeds another view/controller/template combo with a hyphenated name.
{{render "users-list" visibleUsers}}
</script>
@macu
macu / ember-notes.md
Last active August 29, 2015 13:57
Compiled notes on Ember, things to be aware of

Ember Data

  • this.store.find('modelType'); always hits the server, because no ID is given, and there may be new records on the server. Use find in the application route, and all in other places to avoid polling the server every time.
  • this.store.find('modelType', model_id); only hits the server if the model with the given type and ID is not already in the cache.
@macu
macu / vslice.py
Created March 13, 2014 02:29
Simplifies using avconv to slice out part of a video
#!/usr/bin/env python
import sys
from operator import sub
from subprocess import call
def parseTime(s):
parts = s.split(':')
if len(parts) == 2:
parts.insert(0, 0)
@macu
macu / $children.js
Created March 27, 2014 02:22
Like jQuery's "closest" but for children, depending on a selector that matches the desired parent.
var $container = $(this);
var $children = $this.find('.some-criteria').filter(function() {
return $(this).closest('.my-criteria').is($container);
});
@macu
macu / ember-cucumber.rb
Last active August 29, 2015 14:01
Helpers for testing Ember applications using Cucumber and Watir
# coding: UTF-8
module PatientlyHelper
def patiently(seconds=5, &block)
start_time = Time.now
begin
block.call
rescue Exception => e
raise e if (Time.now - start_time) >= seconds
sleep(0.05)
@macu
macu / ember-generate-properties.html
Created June 13, 2014 17:36
Example of dynamically generating properties on objects, demonstrating that the bindings work as expected.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>EmberJS demo</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ember.js/1.5.1/ember.min.js"></script>
@macu
macu / ember-model-clone.js
Last active August 29, 2015 14:03
Reopen the Model class, to allow cloning records with overrides.
import Ember from 'ember';
import DS from 'ember-data';
/**
* Returns the model class name, dasherized, which can be used to find
* and create new models of the same type through the store.
*/
export function getClassName(model) {
// typeKey introduced in Ember Data 1.0.0.beta.3
var typeKey = model.constructor.typeKey;
@macu
macu / pluralize.js
Created August 11, 2014 19:19
Ember pluralize helper
import { Handlebars } from 'ember';
// Thanks for the inspiration: https://coderwall.com/p/ryo_3w
Handlebars.registerBoundHelper('pluralize', function(number, options) {
var phrase = options.hash.phrase || '{|s}';
return phrase.replace(/\{(.*?)\|(.*?)\}/, function(match, singular, plural) {
return number == 1 ? singular : plural;
});
});
@macu
macu / RWSync.swift
Last active August 29, 2015 14:05
Simple utility for executing synchronous code in concurrent read/write blocks. Thanks to "Mastering Grand Central Dispatch" from WWDC 2011: https://developer.apple.com/videos/wwdc/2011/?id=210
/// RWSync provides methods for executing read/write blocks through the Grand Central Dispatch.
/// Multiple reads may execute concurrently, but a write will block all other executions in the queue.
class RWSync {
private let queue: dispatch_queue_t
/// Instantiates RWSync with a new concurrent queue.
init() {
let queueName = "rwsync.\(mach_absolute_time())"
self.queue = dispatch_queue_create(queueName, DISPATCH_QUEUE_CONCURRENT)
class AtomicBoolean {
private var val: Byte = 0
/// Sets the value, and returns the previous value.
/// The test/set is an atomic operation.
func testAndSet(value: Bool) -> Bool {
if value {
return OSAtomicTestAndSet(0, &val)
} else {