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:4f156d0a6122b6d0c74f5843cf19f388
Last active March 23, 2024 21:26
PCI and USB power management in linux
# If usb hdd is made sleeping using hdparm or unbind. The usb device still consumes about 1W.
# This power consumtpion could be spared removing whole usb hub from pci bus
# Make sleep using hdparm
##########################################
hdparm -y /dev/sdb
# Connect / disconnect usb device
###########################################
@janmisek
janmisek / get-spring-data-repository-by-entity-class.java
Created May 2, 2019 11:25
Get spring data repository by entity class
private Repository getRepository() {
String domain = ((Unique) annotation).domain();
try {
Repositories repositories = new Repositories(listableBeanFactory);
Class domainClass = Class.forName(domain);
Optional repo = repositories.getRepositoryFor(domainClass);
if (repo.isPresent()) {
return (Repository) repo.get();
} else {
throw new RuntimeException("Repository for " + domain + " not found");
// get computed properties descriptors - eg: for clonning
const metal = Ember.__loader.require('ember-metal');
EmberObject.eachComputedProperty(key => {
const descriptor = metal.descriptorFor(Model.prototype, key);
// console.log(descriptor._getter.toString());
// now we can take descriptor._getter or descriptor._getter to create computed property on target object
})
@janmisek
janmisek / include-from-ember-internals.js
Last active December 14, 2018 14:37
Import from ember internals
// to import
const metal = Ember.__loader.require('ember-metal');
// to review registry
const registry = Ember.__loader.registry
console.log(registry);
@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();
@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 / 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 / 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: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: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();
}