Skip to content

Instantly share code, notes, and snippets.

View leonadler's full-sized avatar

Leon Adler leonadler

View GitHub Profile
@leonadler
leonadler / post-merge
Created December 15, 2015 16:17 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed. In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed. Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@leonadler
leonadler / gulpfile.js
Created May 24, 2016 13:47
Minimal TypeScript + Gulp4 setup
'use strict';
const gulp = require('gulp');
gulp.task('clean', clean);
gulp.task('build', build);
gulp.task('default', gulp.series(clean, build, watch));
function clean() {
const del = require('del');
const os = require("os");
const fs = require("fs");
const Emitter = require('events');
var wslNetworkInterfaces = function() {
console.log("WSL has no idea what interfaces are available.");
return {
"Loopback Pseudo-Interface 1": [
{
"address": "::1",

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@leonadler
leonadler / depthClone
Last active January 13, 2017 10:40
DepthClone - Object cloning algorithm for TypeScript & JavaScript
.
@leonadler
leonadler / is.ts
Last active January 23, 2017 14:27
Example for TypeScript type assertions
type Validator<T> = (value: any) => value is T;
const is = {
boolean(value: any): value is boolean {
return typeof value === 'boolean';
},
string(value: any): value is string {
return typeof value === 'string';
},
number(value: any): value is number {
@leonadler
leonadler / 1-zoo.ts
Last active February 1, 2017 18:28
TypeScript: Typed Strings
type Animal = string & { __isAnimal__: any };
type Cat = Animal & { __isCat__: any };
type Dog = Animal & { __isDog__: any };
type SmallDog = Dog & { __isSmallDog__: any };
function getCatName(): Cat {
return 'Garfield' as Cat;
}
@leonadler
leonadler / es3.js
Created March 3, 2017 13:28
Comparison of asynchronous JavaScript code in ES3 vs ES7
var combineFiles = require('./combine-files-callback');
var fs = require('fs');
var http = require('http');
// Warning: Error handling omitted for simplicity
var server = http.createServer(function (req, res) {
var files = [
'./files/1.txt',
'./files/2.txt',
'./files/3.txt'
@leonadler
leonadler / tasks.json
Created June 20, 2017 08:38 — forked from aeinbu/tasks.json
Visual Studio Code task for running mocha tests with problem matcher
{
"version": "0.1.0",
"command": "mocha",
"isShellCommand": true,
"showOutput": "silent",
"args": [
"--reporter",
"tap",
"--colors"
],
@leonadler
leonadler / create-mock.ts
Created February 26, 2018 14:09 — forked from michaelbromley/create-mock.ts
Automatic component mocking in Angular
import {Component, EventEmitter, Type} from '@angular/core';
type MetadataName = 'Input' | 'Output';
interface PropDecoratorFactory {
ngMetadataName: MetadataName;
bindingPropertyName: string | undefined;
}
interface PropMetadata { [key: string]: PropDecoratorFactory[]; }