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-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 / $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 / 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 / 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 / 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 / inline-interface.go
Last active January 3, 2016 19:39
Some findings of interest about the Go language.
if f, ok := x.(interface { Foo() }); ok {
f.Foo()
}
@macu
macu / submit13.js
Created December 17, 2013 19:30
Prevent single-input forms from submitting when the user hits Enter, unless the input includes the `submit13` class.
// prevent all forms from submitting on pressing Enter in an input
// unless the input specifies the `submit13` class.
$("input").on("keypress", function(e) {
if (e.which == 13) {
// prevent all first, and trigger manually to bypass the quirk
// where browsers will submit single-input forms on pressing Enter.
// otherwise two submit events would be generated in quirk cases.
e.preventDefault();
if ($(this).is(".submit13")) {
$(this).closest("form").trigger("submit");
@macu
macu / form-includes.html
Created December 15, 2013 18:34
Form fields injection and sanitize number fields on submit.
<form data-includes="#anotherForm,[name=someField]" method="get">
<p>Fields from elsewhere in the document will be included on submit.</p>
<input type="submit" value="Submit!" />
</form>
<form id="anotherForm">
<input type="hidden" name="willBeIncluded" value=":)" />
<input type="number" name="willBeIncludedAndSanitized" min="1" data-sanitize="int" />
<input type="checkbox" name="willBeIncludedIfChecked" value="itWasChecked" />
</form>
@macu
macu / debug.coffee
Last active December 31, 2015 07:29
Minimal set of debug functions for use within jQuery plugins.
dopen = 0
debug = (o...) -> if settings.debug
console.debug o...
debugWarn = (o...) -> if settings.debug
console.warn o...
debugGroup = (o...) -> if settings.debug
console.group o...
dopen++
debugClose = -> if dopen > 0
console.groupEnd()
@macu
macu / activate.js
Last active December 28, 2015 15:29
Add "active" to elements defining ownp attribute specifying a selector matching a parent element. This was written specifically to add "active" to nav elements for the current page in Bootstrap-based templates.
$(function(){
// loop all elements that specify an ownp attribute,
// and activate those in a parent matching the specified selector.
$("[ownp]").each(function(){
if ($(this).closest($(this).attr("ownp")).length) {
$(this).addClass("active");
}
});