Skip to content

Instantly share code, notes, and snippets.

View Buslowicz's full-sized avatar

Daniel Busłowicz Buslowicz

View GitHub Profile
@Buslowicz
Buslowicz / polymer-expression-binding-behavior.js
Last active May 17, 2016 23:59
Google Polymer behavior allowing to use simple javascript expressions inside of the templates
(function (global) {
var dynamicFunctionsNames = {};
var cached = {};
function expressBinding(match, p) {
var fun;
var attrs = p
.replace(/&/g, "&") // decode &
.replace(/&lt;/g, "<") // decode <
.replace(/&gt;/g, ">") // decode >
@Buslowicz
Buslowicz / helpers.ts
Last active January 11, 2022 11:49
Helpers
Object.prototype.getPath = function(path) {
return path
.split(".")
.reduce((obj, p) => obj ? obj[p] : undefined, this);
}
Object.prototype.setPath = function(path) {
return path
.split(".")
.reduce((obj, p) => typeof obj[p] === 'object' ? obj[p] : (obj[p] = {}), this);
@Buslowicz
Buslowicz / config
Created October 14, 2016 11:23
Nginx config for wrapping js imports as html5 imports
location ~/html-imports/(.+)$ {
set $path $1;
default_type 'text/html';
content_by_lua 'ngx.say("<script src=\'", ngx.var.path, ".js\'></script>")';
}
@Buslowicz
Buslowicz / oarray.js
Last active December 2, 2016 11:42
Observable Array (POC, very slow)
const mediator = new WeakMap();
const notify = (instance, ev, index, item) => mediator.get(instance)[ev].forEach(listener => listener({index, item}));
class OArray extends Array {
constructor() {
super();
mediator.set(this, {changed: [], added: [], removed: []});
}
push(...items) {
for (let i = 0, tl = this.length, l = items.length; i < l; i++) {
let item = items[i];
@Buslowicz
Buslowicz / transform.js
Created December 8, 2016 15:23
CSS Transform getter and setter from single template
function buildPatterns(order) {
let orderMap = {};
let orderArray = order.split("|");
orderArray.forEach((t, i) => orderMap[ t ] = i);
return (consts, ...vars) => {
const escapePars = [ /(\(|\))/g, "\\$1" ];
const map = {
number: { match: `([\\de.-]+)`, cast: Number },
string: { match: `([\\w.-]+)`, cast: String },
@Buslowicz
Buslowicz / destroyable.js
Created December 20, 2016 14:38
Destroyable web components mixin
const Destroyable = (superclass, destroyTimeout) => class extends superclass {
detachedCallback() {this.__destroying = setTimeout(() => { if (!this.isConnected && this.destroyedCallback) this.destroyedCallback() }, destroyTimeout)},
attachedCallback() {clearTimeout(this.__destroying)}
};
@Buslowicz
Buslowicz / extension.js
Last active October 4, 2017 09:15
Generates a CUID and copies it to clipboard.
const St = imports.gi.St;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Clipboard = St.Clipboard.get_default();
const CLIPBOARD_TYPE = St.ClipboardType.CLIPBOARD;
const namespace = 'cuid';
const blockSize = 4;
const base = 36;
@Buslowicz
Buslowicz / typedModel.ts
Created November 15, 2019 09:44
Rematch Retyped
type TypedDispatcher<R> = R extends (state: any, payload?: infer P, meta?: infer M) => any
? (payload?: P, meta?: M) => Action<P, M>
: R extends (state: any, payload: infer P, meta?: infer M) => any
? (payload: P, meta?: M) => Action<P, M>
: R extends (state: any, payload: infer P, meta: infer M) => any
? (payload: P, meta: M) => Action<P, M>
: null;
type StripUnknown<T> = T extends (payload?: unknown, meta?: unknown) => Action<unknown, unknown>
? () => Action<never, never>