Skip to content

Instantly share code, notes, and snippets.

View jakelazaroff's full-sized avatar
🎸
rocking out

Jake Lazaroff jakelazaroff

🎸
rocking out
View GitHub Profile
@jakelazaroff
jakelazaroff / path.js
Last active August 29, 2015 14:14
Returns the value of a nested property if it exists, or undefined if it doesn't.
function nested(entity, path) {
path.split('.').some(function (property) {
entity = entity[property];
return typeof entity === 'undefined';
});
return entity;
};
@jakelazaroff
jakelazaroff / backboneconf2013
Last active December 20, 2015 11:19
BackboneConf 2013 notes! http://backboneconf.com/ Disclaimer: sorry for anything I may have missed!
code delimiters: <% %>
# keynote
- your business logic will live longer than your interface
- stateless
- no "spaghetti state"
- application should be able to reflect any combination of data
- views should transparently reflect models
- backbone patterns
- custom model methods
@jakelazaroff
jakelazaroff / require_module.js
Last active December 20, 2015 12:29
RequireJS module example. This is how I keep my dependency list organized!
define([
// models
'models/someModel', 'models/someOtherModel',
// collections
'collections/someCollection',
// views
'views/someView', 'views/someOtherView',
// templates
'text!templates/someTemplate.html', 'text!templates/someOtherTemplate.html',
@jakelazaroff
jakelazaroff / sublime_newline
Last active December 21, 2015 07:08
Ensures a newline at end of files while saving in Sublime. This should be in everyone's preferences!
{
"ensure_newline_at_eof_on_save" : true
}
@jakelazaroff
jakelazaroff / prettylog.js
Created September 23, 2013 20:11
Allows you to pass an arbitrary number of CSS properties in a JavaScript object to style a console log. Example: prettyLog('Hello world!', { 'font-weight' : 'bold' });
var prettyLog = function (message, styles) {
var rule = '';
for (var property in styles)
rule += property + ':' + styles[property] + ';';
console.log('%c' + message, rule);
};
@jakelazaroff
jakelazaroff / mad.js
Created October 10, 2013 06:41
Adapt non-AMD compliant code.
// make sure AMD is available
if (typeof define !== "undefined")
// define a module for the library
define([], function(){
// create a local copy
var EvilNonAmdSupportingLibrary = window.EvilNonAmdSupportingLibrary;
// remove the copy in the global namespace
window.EvilNonAmdSupportingLibrary = undefined;
// return the local copy to AMD library
return EvilNonAmdSupportingLibrary;
@jakelazaroff
jakelazaroff / cleanup.sh
Last active December 25, 2015 16:39
Removes all unused jpgs and pngs from a directory recursively.
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in `find . -name "*.png" -o -name "*.jpg"`; do
file=`basename -s .jpg "$i" | xargs basename -s .png | xargs basename -s @2x`
result=`grep -r $file .`
if [ -z "$result" ]; then
git rm "$i"
fi
@jakelazaroff
jakelazaroff / .screenrc
Created November 6, 2013 21:11
Nice simple .screenrc file
startup_message off
caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= %c"
vbell off
function propertyExists (target, path) {
if (typeof path === 'string')
path = path.split('.');
try {
return path.length ? path[0] in target && propertyExists(target[path.shift()], path) : true;
} catch (e) {
return false;
}
}
@jakelazaroff
jakelazaroff / grid.scss
Last active January 3, 2016 14:19
small SASS grid.
$column-width: 60px;
$gutter-width: 20px;
$line-height: 20px;
@function columns ($columns: 1) {
@return $columns * ($column-width + $gutter-width) - $gutter-width;
}
@function rows ($lines: 1) {
@return $line-height * $lines;