Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hinc
hinc / script-template.sh
Created December 23, 2020 14:48 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@hinc
hinc / Infrastructure.js
Created April 9, 2019 09:26 — forked from sebmarkbage/Infrastructure.js
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@hinc
hinc / slim-redux.js
Created December 26, 2018 03:30 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
#!/usr/bin/env ruby
# Requires that you have ./bin/dcpTool from https://sourceforge.net/projects/dcptool/
require 'rubygems'
require 'bundler/setup'
require 'nokogiri'
input_camera_model = ARGV[0] || "LEICA Q (Typ 116)"
output_camera_model = ARGV[1] || "LEICA M10"
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person
@hinc
hinc / scrat-cache-bookmarklet.js
Last active August 29, 2015 14:01
计算 scrat.js 缓存资源大小 bookmarklet
javascript:alert("Cached: "+Object.keys(localStorage).reduce(function(e,t){return~t.indexOf(require.options.prefix)?e+localStorage.getItem(t):e},"").length/1e3+"KB")
@hinc
hinc / qrcode.js
Created January 12, 2014 06:12 — forked from justan/qrcode.js
//a qrcode bookmarklet(二维码小书签)
//javascript:(function(d){var b=d.createElement("textarea"),c,f=!!d.all,a,e="http://qrcode.kaywa.com/img.php?s=5&d=%s";(c=d.getElementById("_qrcode__"))?(b=c,a=b.style,a.display=""):(a=b.style,b.id="_qrcode__",d.body[f?"attachEvent":"addEventListener"]((f?"on":"")+"click",function(){a.display="none"},!0),a.zIndex=9999,a.position="fixed",a.top=0,a.left=0,a.width="100%",a.height="100%",d.body.appendChild(b));c=function(){var a,b=d.selection,c=d.activeElement,e=top.getSelection,f=c&&c.selectionEnd;f?a=c.value.substring(c.selectionStart, f):e&&(a=e()+"");b&&(a=b.createRange().text);return a=a||location.href}();b.title=c;e=e.replace("%s",encodeURIComponent(c));a.color='#fff';a.background="rgba(0, 0, 0, 0.3) url("+e+") no-repeat center";b.select()})(document);
//original code
(function(doc){
var qrcode = doc.createElement('textarea'), tmp,
ie = !!doc.all, style, txt,
qrimage = 'http://qrcode.kaywa.com/img.php?s=5&d=%s',
id = '_qrcode__';
@hinc
hinc / differ.js
Last active July 21, 2020 10:29
Simple List Change Detection (Diffing)
function diff(source, target) {
source = JSON.parse(JSON.stringify(source)).map(JSON.stringify);
target = JSON.parse(JSON.stringify(target)).map(JSON.stringify);
var changes = [];
while (source.length && target.length) {
var oldVal = source.shift();
var newVal = target.shift();