Skip to content

Instantly share code, notes, and snippets.

View jayphelps's full-sized avatar
💭
I may be slow to respond.

Jay Phelps jayphelps

💭
I may be slow to respond.
View GitHub Profile
@jayphelps
jayphelps / IdentifierBuilder.js
Created December 5, 2012 08:37
IdentifierBuilder - build the shortest possible unique names/keys. Helpful for compilers/minifiers/etc
/**
* MIT Licensed (but really, do what you want with it)
*
*
* Usage:
*
* `IdentifierBuilder.create()` === `a`
* `IdentifierBuilder.create()` === `b`
* `IdentifierBuilder.create()` === `c`
* ...
@jayphelps
jayphelps / newApply.js
Last active December 13, 2015 16:39
newApply() - A simple way to combine `foo.apply(context, args)` with `new Foo()` at the same time. (apply an array of arguments to the constructor of the new object instance)
/**
* newApply
* By Jay Phelps
* WTFPL Licensed
*
* Example:
*
* function Foo(first, second) {
* alert(first + ' ' + second);
* }
@jayphelps
jayphelps / index.html
Created July 19, 2013 05:50
Intro to Ember.js - Demo app from the Ember meetup presentation Slides: http://www.slideshare.net/jayphelps/intro-to-emberjs-24409989
<!DOCTYPE html>
<html>
<body>
<script type="text/x-handlebars">
<h1>My Great Web App</h1>
<div>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="index">
@jayphelps
jayphelps / app.js
Created January 15, 2014 06:38
Demo from my Ember.String.interpolate talk @ the Ember.js Southern California Meetup. Library: https://github.com/jayphelps/ember.string.interpolate Slides: https://www.slideshare.net/jayphelps/emberstringinterpolate
this.App = Ember.Application.create();
App.IndexController = Ember.ObjectController.extend({
firstName: null,
lastName: null,
fullName: '$firstName $lastName'.interpolate().readOnly()
});
@jayphelps
jayphelps / resolver.js
Last active September 4, 2020 17:56
Example of using multiple Ember.Namespaces with a custom Ember.Resolver to reuse code between projects. Ember App Kit's resolver as another example: https://github.com/stefanpenner/ember-jj-abrams-resolver DefaultResolver docs: https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/resolver.js
/**
* Super namespace that all our libs and apps will live on. We also extend all
* of the native Ember classes as well and exclusely use them that way so we can
* alter the behavior in one place without needing to reopen the original class.
*
* We call the super namespace PS for Pivotshare, call it what you'd like.
*/
window.PS = Ember.Namespace.create();
// Create our custom resolver so we can have Ember look up classes on multiple
@jayphelps
jayphelps / retry-with-replace.js
Created May 9, 2014 21:40
Common poorly documented Ember.js apis, tasks, conventions, etc. Some of these are private APIs! USE AT YOUR OWN RISK.
// Retry route Transition, but replace the URL state; just like router.replaceWith('route.name');
abortedTransition.retry().method('replace');
@jayphelps
jayphelps / history-scroll.js
Last active April 23, 2016 04:45
Ember router history Location class that keeps scroll position between transitions
var get = Ember.get;
var HistoryScrollLocation = Ember.HistoryLocation.extend({
document: document,
window: window,
_storeScrollPos: function () {
var state = history.state,
window = get(this, 'window'),
doc = get(this, 'document.documentElement');
var isValidURL = (function () {
var input = document.createElement('input');
input.type = 'url';
function isValidURL(url) {
input.value = url;
return input.validity.valid;
}
return isValidURL;
var parseLocation = (function () {
var a = document.createElement('a');
function parseLocation(url) {
a.href = url;
var protocol = (!a.protocol || a.protocol === ':') ? location.protocol : a.protocol;
// IE8 inconsistently returns leading slash
var pathname = (a.pathname.match(/^\//)) ? a.pathname : '/' + a.pathname;
@jayphelps
jayphelps / Object.resolve.js
Last active August 29, 2015 14:16
Resolve property paths
/**
Object.resolve(document, 'body.style')
*/
Object.resolve = function resolve(obj, propPath) {
return [obj]
.concat(propPath.split('.'))
.reduce((prevObj, currKey) => prevObj[currKey]);
};