Skip to content

Instantly share code, notes, and snippets.

(function(console) {
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
];
if (!console.log) {
console.log = function() {};
@gordonkristan
gordonkristan / set.js
Created March 14, 2016 00:43
Functions as sets in Javavscript
const emptySet = () => false;
const addElement = (set, element) => {
return (item) => (item === element ? true : set(item));
};
const removeElement = (set, element) => {
return (item) => (item === element ? false : set(item));
};
@gordonkristan
gordonkristan / FIRST.md
Last active May 11, 2018 21:53
Ember.js Optional Route Parameters

Ember.js Optional Route Parameters

A topic that comes up quite often in Ember.js discussion forums is optional route parameters. Unfortunately for those who have this problem, there's no built-in way to achieve this functionality. But there is a very nice little hack that will emulate optional route parameters for most sitautions. The actual method is pretty simple, it just requires combining a few tricks. I'll describe the high-level deatils here, and you can find working example code below.

What's needed to pull this off:

  1. You'll need a resource with a sub-route. The sub-route is the 'real' route that you're going to use. All of your logic should be declared in the controller and template for this route. (Also remember that using a resource generates an implicit index route.)
  2. The implicit index route is where you should redirect to if you have no model to provide. It's also where you end up if you go to a URL without providing the parameter. This route immediately redirects to your other sub-r
@gordonkristan
gordonkristan / resolver.js
Last active August 29, 2015 14:04
Ember ES6 Module Resolver
let camelizeModuleName = (moduleName) => moduleName.replace(/\//g, '_').camelize();
let findModule = (resolvedName) => {
let moduleNames = window.getModuleNames();
for (let name of moduleNames) {
if (camelizeModuleName(name) === resolvedName) {
return window.require(name);
}
}
var fs = require('fs');
var sh = require('execSync');
var FULL_RELEASE = [
'normalize-css',
'jquery',
'jquery-cookie',
'jquery.autoellipsis',
'pickadate',
'handlebars',
@gordonkristan
gordonkristan / JsonHelper.scala
Created November 5, 2013 02:24
Small batch of JSON helper functions for Scala and the Google GSON library.
object JsonHelper {
def JSON(props: (String, JsonElement)*): JsonObject = {
props.foldLeft(new JsonObject)((json, pair) => {
json.add(pair._1, pair._2)
json
})
}
implicit def string2json(s: String) = new JsonPrimitive(s)
implicit def number2json(n: Number) = new JsonPrimitive(n)