Skip to content

Instantly share code, notes, and snippets.

Hraban Luyat hraban

Block or report user

Report or block hraban

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hraban
hraban / pre-commit
Last active Dec 3, 2019
NOCOMMIT git hook — prevent accidentally committing debug code
View pre-commit
#!/bin/sh
# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone:
@hraban
hraban / dialog.html
Last active Dec 1, 2019 — forked from coinsandsteeldev/dialog.html
Google Sheets script to allow multi-select in cells with data-validation (adapted from https://www.youtube.com/watch?v=dm4z9l26O0I)
View dialog.html
<!DOCTYPE html>
<html>
<head>
<script>
// https://github.com/reaxis/mu
(function(d){"object"===typeof exports?module.exports=d():"function"===typeof define&&define.amd?define(d):mu=µ=d()})(function(){function d(){}function m(a){return a.replace(/-(.)/g,function(a,c){return c.toUpperCase()})}function k(a){return"[object Array]"==={}.toString.call(a)}function g(a){return[].slice.call(a)}d.one=function(a){return document.querySelector(a)};d.all=function(a){return g(document.querySelectorAll(a))};d.create=function(a){return document.createElement(a)};var h={one:function(a){return this.querySelector(a)},all:function(a){return g(this.querySelectorAll(a))},each:function(a){a.bind(this)(0);return this},"µAddEventListener":Node.prototype.addEventListener,addEventListener:function(){this.µEventCache=this.µEventCache||[];this.µEventCache.push(arguments);this.µAddEventListener.apply(this,arguments)},on:function(a,b){this.addEventListener(a,b);return this},add:function(){return g(arguments).reduce(function(a,b){k(b)?a.a
@hraban
hraban / index.css
Created Nov 21, 2019
halftone qr codes (backup of Lachlan Arthur's at http://jsfiddle.net/lachlan/r8qWV/ )
View index.css
html, body {
height: 100%;
margin: 0;
}
body {
position: relative;
}
h1, h2 {
@hraban
hraban / leanxml.js
Last active Oct 7, 2019
Lean XML DOM builder compatible with TypeScript's jsxFactory for Reactless .tsx files
View leanxml.js
/**
* Leanxml Runtime: lean TS jsxFactory runner for creating XML doms.
*
* N.B.: Doesn’t work on tagnames with uppercase first letter!
*/
const xmldom = require('xmldom');
function leanxml(tagname, attrs, ...children) {
return function leanxmlBuilder(doc) {
@hraban
hraban / bash log
Last active Aug 9, 2019
Nice new Git feature: detect folder moves
View bash log
$ cd /tmp
$ mkdir test
$ cd test
$ git init
Initialized empty Git repository in /private/tmp/test/.git/
$ git commit --allow-empty -m root
[master (root-commit) 6814cc9] root
$ mkdir foo
$ echo a > foo/a
$ git add foo
@hraban
hraban / interleave.js
Last active Jun 10, 2019
Interleaving two arrays in Javascript (using iterators & generators)
View interleave.js
/**
* interleave([1,2], [8,7,6,5], [], 'abc')
* => [ 1, 8, 'a', 2, 7, 'b', 6, 'c', 5 ]
*/
function* interleave() {
const its = Array.from(arguments).map(x => x[Symbol.iterator]());
let done;
do {
done = true;
for (const it of its) {
@hraban
hraban / workspace.sh
Created Jan 6, 2019 — forked from dixson3/workspace.sh
Create and manage a case-sensitive disk-image on OSX. This is great when you have a need to work with case-sensitive repos on a mac.
View workspace.sh
#!/bin/bash
set -eu -o pipefail
${DEBUGSH+set -x}
# where to store the sparse-image
NAME=civol
SPARSELOC=~/Documents/$NAME.dmg
FSTYPE="APFS"
@hraban
hraban / main.js
Created Nov 22, 2018
child process interruption and signal control
View main.js
const child_process = require('child_process');
const process = require('process');
process.on('SIGINT', () => console.log("ooh this is sigint"));
process.on('SIGUSR1', () => console.log("oh this is sigusr1!!"));
function block4ever() {
setTimeout(() => {} , 1000000);
}
@hraban
hraban / .nvmrc
Last active Sep 24, 2018
exploring signal handling in bash scripts, subshells and pipelines
@hraban
hraban / watch.js
Last active Jul 2, 2018
Simple cross-platform change watcher
View watch.js
// Simplistic directory watcher
//
// example usage:
//
// $ node watch.js | while read line ; do echo compiling ... ; ( while read -r -t 0; do read -r ; done ) ; rm -rf build ; npm run build ; echo done ; done
//
var fs = require('fs');
You can’t perform that action at this time.