Skip to content

Instantly share code, notes, and snippets.

View alexdiliberto's full-sized avatar

Alex DiLiberto alexdiliberto

View GitHub Profile
# 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 / perf_profiling_tips.md
Last active March 25, 2020 11:14
Ember performance profiling tips in Chrome
@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');
@alexdiliberto
alexdiliberto / evented_service.js
Created October 20, 2015 00:12
Pattern for dispatching events from Services in Ember
// app/services/locale.js
export default Ember.Service.extend(Ember.Evented, {
init() {
this._super(...arguments);
// initialize locales from localStorage (or URL string)
},
currentLocale() {
return ...;
@alexdiliberto
alexdiliberto / ember_1x_wierd_tricks.txt
Created October 27, 2015 04:13
Wierd tricks you can stop using in Ember 2.0
Wierd tricks you can stop using in Ember 2.0
{{! Input component with Error handling }}
{{input value=(mut (get model field))}}
{{#each (get model (concat "errors." field)) as |error|}}
{{error}}
{{/each}}
@alexdiliberto
alexdiliberto / patch_jquery.js
Created February 9, 2016 02:50
Fix dat jQuery doe
// Remove jQuery's ability to evaluate code in a global context
// When you go from text -> script, do not execute eval()
// Taken from: https://www.youtube.com/watch?v=vD4G358rEUY&index=8&list=PL4eq2DPpyBbk5hPbX1kSoIpPspYKoeC5V
$.globalEval = function() {};
$.ajaxSetup({
converters: {
'text script': text => text
}
});
@alexdiliberto
alexdiliberto / get_random_bytes.js
Created February 25, 2016 16:57
Get random bytes in Javascript (Browser/Node)
let getRandomBytes = (
(typeof self !== 'undefined' && (self.crypto || self.msCrypto))
? function() { // Browsers
var crypto = (self.crypto || self.msCrypto), QUOTA = 65536;
return function(n) {
var a = new Uint8Array(n);
for (var i = 0; i < n; i += QUOTA) {
crypto.getRandomValues(a.subarray(i, i + Math.min(n - i, QUOTA)));
}
return a;
/*
Best practice in ember to ensure all actions will always fire correctly
*/
[data-ember-action], a, button, input, .link {
cursor: pointer;
}