Skip to content

Instantly share code, notes, and snippets.

View alexdiliberto's full-sized avatar

Alex DiLiberto alexdiliberto

View GitHub Profile
@alexdiliberto
alexdiliberto / ember-presentation-logic-location.md
Created July 7, 2014 18:47
Where to put your presentation logic for Ember

controller: page-specific

model: if the business object as a canonical representation

helpers, components: generic configurable elements

@alexdiliberto
alexdiliberto / simple-css-negater.js
Last active August 29, 2015 14:03
Simple CSS Negater. Reads input as a rawCSS file. Writes output as a minified and negated CSS file. This is great for quickly negating some third party CSS which you don't have full control over.
/**
Readme
1. Copy & paste the input file into third-party.css as raw CSS
2. $ node css-negator.js
3. When finished, the final copy will be in the file named: negated-output.css
*/
var css = require('css');
var fs = require('fs');
var colors = require('colors');
@alexdiliberto
alexdiliberto / rovarspraket.js
Created July 26, 2014 03:11
rövarspråket
/*
Double every consonant and place an occurrence of "o" in between.
For example, translate("this is fun") should return the string "tothohisos isos fofunon".
translate('this is fun')
=> "tothohisos isos fofunon"
*/
function translate(str) {
var arr = str.split(''),
out = "";
@alexdiliberto
alexdiliberto / copy_git_to_svn.txt
Created September 5, 2014 16:56
Copy existing Git reposity to SVN
//Simply make a temporary directory as a SVN sandbox
mkdir temp; cd temp;
//Checkout the latest Jefferson SVN
svn co <svn-url> .
//Wipe the current directory to a clean slate
svn delete *
//Manually copy all the files to the current SVN directory
@alexdiliberto
alexdiliberto / promise_race_timout.js
Last active August 29, 2015 14:15
How to timeout a long-running promise
/**
Credit: Kyle Simpson
https://github.com/getify/You-Dont-Know-JS/blob/master/async%20&%20performance/ch3.md#never-calling-the-callback
*/
// A utility for timing out a Promise
function timeoutPromise(delay) {
return new Promise( function(resolve,reject) {
setTimeout( function() {
reject( "Timeout!" );
@alexdiliberto
alexdiliberto / select_by_id.js
Created July 16, 2015 03:32
Ember QUnit Test Helper: selectById()
export function selectById(selectId, optionLabel) {
return function() {
const option = findWithAssert(`#${selectId} option:contains('${optionLabel}')`);
fillIn(`#${selectId}`, option.attr('value'));
return find(selectId).focusout();
};
}
# Set up a listener
nc -l 1234
# spawn ember-cli that proxies to the listener
ember s --proxy http://localhost:1234
# curl "as ajax"
curl -H 'X-Requested-With: XMLHttpRequest' -H 'Accept: application/json' localhost:4200/api/foo
#result in the listener tab:
@alexdiliberto
alexdiliberto / map_obj.js
Created August 21, 2015 23:34
Converting a string Map to and from an object
// The following two function convert string Maps to and from objects:
// http://www.2ality.com/2015/08/es6-map-json.html
function strMapToObj(strMap) {
let obj = Object.create(null);
for (let [k,v] of strMap) {
// We don’t escape the key '__proto__'
// which can cause problems on older engines
obj[k] = v;
}
@alexdiliberto
alexdiliberto / simple_component_init.js
Created October 7, 2015 22:11
Include _setup and _teardown methods on your initial component
export default Ember.Component.extend({
_setup: Ember.on('init', function() {
//do stuff in this method
}),
_teardown: Ember.on('willDestroyElement', function() {
//if you need a spot to tear down ...
})
});
@alexdiliberto
alexdiliberto / css-negator.js
Last active October 8, 2015 22:46
Mini CSS negator
/**
README.md
1. Copy & paste the input file into third-party.css as raw CSS
2. $ node css-negator.js
3. When finished, the final copy will be in the file named: negated-output.css
*/
var css = require('css');
var fs = require('fs');
var colors = require('colors');