Skip to content

Instantly share code, notes, and snippets.

View janmisek's full-sized avatar

Jan Míšek janmisek

View GitHub Profile
@janmisek
janmisek / gist:068d36b46ff4fdd850cc
Last active August 29, 2015 14:19
Hook worker in ember-cli building process

Hello

It is already possible to hook workers scripts into ember-cli build process (including watching) even it is not straightforward.

Option 1: workers does not need to reuse routines from application

Its possible to include own building tree in Brocfile.js

var webpackify = require('broccoli-webpack');
@janmisek
janmisek / gist:14d5b473ddc1cfdd0ca7
Last active August 29, 2015 14:19
Broccoli filter to get output from spawned process

Package.json

{
  "name": "broccoli-aglio",
  "version": "0.1.0",
  "description": "Broccoli filter to get output from spawned process",
  "author": "Jan Misek <jan.misek@rclick.cz> (https://github.com/janmisek)",
  "license": "MIT",
  "devDependencies": {
    "aglio": "^1.18.0",
@janmisek
janmisek / gist:7f743a9360c89fbbc10f
Created April 20, 2015 07:52
Watch files and execute command upon change
pip install watchdog
watchmedo shell-command \
--patterns="*.rst" \
--ignore-pattern='_build/*' \
--recursive \
--command='make html'
@janmisek
janmisek / gist:0a730e44c43317609667
Created April 28, 2015 11:06
Clear indexed dbs in chrome
indexedDB.webkitGetDatabaseNames().onsuccess = function (dbs) {
dbs = dbs.target.result;
for (var i=0; i<dbs.length; i++) {
console.log('removing indexedDB', dbs[i]);
indexedDB.deleteDatabase(dbs[i]);
}
};
@janmisek
janmisek / gist:e88c33dade3773b2b352
Last active August 29, 2015 14:21
Ember current route name when transitioning
if (this.get('router.router.activeTransition.targetName') === 'credentials.signin') {
return Ember.RSVP.resolve();
}
@janmisek
janmisek / gist:63bd49106e27eea771f4
Created May 21, 2015 08:02
Search for value in object
var walked = [];
var searchHaystack = function(haystack, needle, path, exactEquals) {
//dumb truthiness handling
exactEquals = exactEquals ? true : false;
if(typeof haystack != "object") {
console.warn("non-object haystack at " + path.join("."));
return [false, null];
@janmisek
janmisek / gist:e74f333283bb508d0e76
Created May 21, 2015 09:20
Get router handlers in emberjs
// returns infos with model and parameters for each route
getRouterInfos: function() {
var router = this.get('router');
var infos = router.router.currentHandlerInfos.slice();
// normalize latest. because it is e.g. 'streams.index'
var latest = infos[infos.length-1];
var names = latest.name.split('.');
latest.name = names[names.length-1];
@janmisek
janmisek / gist:bebfd584ce3382a67ce2
Last active August 29, 2015 14:22
run function once
once

There are times when you prefer a given functionality only happen once, similar to the way you'd use an onload event. This code provides you said functionality:

function once(fn, context) { 
	var result;
@janmisek
janmisek / ember-cli-build.js
Created November 30, 2016 07:30
Solution to use pods based components in in-repo addon (working on ember 2.8 and 2.9 probably since 2.5)
/**
There is no support for pod based components in addons as of ember 2.9. Also as ember is moving to https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md
pods are being discontinued (no longer supported). But for better organization of large in-repo addons pods are a must.
This gist provides solution how to use pods based components in in-repo addon. Even components.js based in pods of addon works problem is that template is not
being compiled. Following adjustments provides also compilation of template. Its only solution I found because of private
anonymous function in ember-cli which handles template compilation of addons.
To use pods in addon
@janmisek
janmisek / meta.js
Last active February 22, 2017 10:36
Ember computed property meta - Set the meta, get the meta
//Usage of metas: http://emberjs.com/api/classes/Ember.ComputedProperty.html#method_meta
const o = Ember
.Object
.extend({
prop: Ember.computed(function(key) {
console.log(this.constructor.metaForProperty(key));
}).meta({key: 'value'})
}).create();