Skip to content

Instantly share code, notes, and snippets.

@likwrk
likwrk / fluxi.js
Last active December 1, 2018 23:31
simple Flux implementation inspired by redux refactored with combine reducers and select
function combineReducers(reducers) {
const initState = {};
const finalReducers = Object.keys(reducers).map((key) => {
const reducer = reducers[key];
initState[key] = reducers[key](undefined, { type: null });
return { key, reducer };
});
return (state = initState, action) => {
const newState = {};
let changed = false;

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array): T[] 🔒 ES3
@likwrk
likwrk / watchers.js
Created June 13, 2017 06:44
angular1 watchers counter userscript
// ==UserScript==
// @name watchers
// @namespace *.dev
// @version 1
// @grant none
// @run-at document-end
// ==/UserScript==
(function(){
if (!window.hasOwnProperty('angular')) return;
@likwrk
likwrk / app.ts
Created April 11, 2017 14:46
Let Operator in Angular
//our root app component
import {Component, NgModule, Output, EventEmitter, Input} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {ReactiveFormsModule, FormControl} from '@angular/forms';
import {Observable} from 'rxjs/Rx';
@Component({
selector: 'app-input',
template: `
<input type="text" [formControl]="form" class="form-control">
@likwrk
likwrk / rxflux.js
Last active February 5, 2017 17:46
rxjs flux implementation
// Flux implementation in RxJS
// https://github.com/ryardley/rxjs-as-redux
// http://rudiyardley.com/redux-single-line-of-code-rxjs/
console.clear();
const action$ = new Rx.Subject();
const isObservable = obs => obs instanceof Rx.Observable;
const actionDispatcher = (func) => (...args) =>
action$.next(func(...args));
@likwrk
likwrk / JavaScript NG.sublime-syntax
Created July 9, 2016 11:25 — forked from subhaze/JavaScript NG.sublime-syntax
very start of Angular 2 sublime syntax file
%YAML1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: JavaScript NG
file_extensions:
- js
- ng.js
scope: source.js.ng
contexts:
main:
@likwrk
likwrk / get-watchers.js
Last active May 4, 2016 19:11 — forked from kentcdodds/get-watchers.js
Get Watchers of element and its children
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
@likwrk
likwrk / gist:92a5150ca821a00547e50a20eecb29b8
Created May 4, 2016 12:28 — forked from Mithrandir0x/gist:3639232
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@likwrk
likwrk / introrx.md
Created January 15, 2016 19:45 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@likwrk
likwrk / gpg-import-and-export-instructions.md
Created December 21, 2015 21:24 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...