Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
#
# This script will make WinMerge your default tool for diff and merge.
# It must run inside git bash (on Windows)
#
# If your WinMerge is in other place then this one, please edit
WINMERGE_SCRIPT="~/winmerge-merge.sh"
@dkordik
dkordik / app.html
Last active December 21, 2015 11:18
can.js mustache declarative bindings for value, visible, class, and click. working jsfiddle: http://jsfiddle.net/dkordik/ZjZ8s/13/
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.1/jquery.js"></script>
<script src="http://canjs.us/release/latest/can.jquery.js"></script>
<script src="http://canjs.com/release/latest/can.view.mustache.js"></script>
<script src="can.mustache.defaultBindings.js"></script>
<script id="template" type="text/mustache">
<h1>Knockout-esque <code>value</code> binding</h1>
{{#newAnimal}}
<input type="text" {{value name }} placeholder="Name of animal">
<input type="text" {{value favoriteFood}} placeholder="Favorite food">
@dkordik
dkordik / .displaysleep
Last active December 21, 2015 20:39
SleepWatcher setup for Hue lights to turn off and on when my screen does. SleepWatcher lets you run arbitrary commands on wake/sleep/displaydim/displayundim. It can be found here: http://www.bernhard-baehr.de/ - get an API key for your Hue by following these steps: http://developers.meethue.com/gettingstarted.html
#!/bin/bash
APIKEY="newdeveloper"
function turnOff {
curl -X PUT -d"{\"on\": false }" http://192.168.2.142/api/$APIKEY/lights/$1/state
}
turnOff 1
turnOff 3
@dkordik
dkordik / w3schoolsdatebyexample.js
Created September 13, 2013 15:46
w3schools to/get date methods, by example... which it should be in the first place. JS console to the rescue!
anchors=document.querySelectorAll("table a");
for (i=0; i < anchors.length; i++) {
if (anchors[i].innerText.match(/(to|get).*\(\)/) ) {
var method = anchors[i].innerHTML;
method=method.substring(0, method.length-2);
console.log(method, " -- ", new Date()[method]()); }
}
@dkordik
dkordik / bubble_error_events.js
Created October 3, 2013 20:02
Image error events don't bubble, (see http://www.w3.org/TR/DOM-Level-3-Events/#event-type-error ) which can be pretty annoying when you're trying to handle them with any modern event-delegation-y technique. This uses event capturing on supported browsers to trigger a standard bubble-friendly event on the element in question, so you can handle th…
//image error events don't bubble, so we use
// native event capturing, where supported
if (document.addEventListener && !document.bubbleErrors) {
document.addEventListener('error', function (event) {
jQuery(event.target).trigger(event); //bubble it ourselves!
}, true); //true = use event capturing (not bubbling)
document.bubbleErrors = true;
}
@dkordik
dkordik / fightthefuture.js
Last active December 28, 2015 13:19
Better Meteor async. Man, futures can be confusing! This is how I clean things up a little bit in my actual methods.
var Future = Npm.require('fibers/future'); //npm install fibers
var async = function (callback) { //let's tuck away some of the nastyness in here
var future = new Future();
var returnFunc = function () {
future["return"].apply(future, arguments);
}
callback(returnFunc);
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-field/core-field.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-input/core-input.html">
<link rel="import" href="../core-icons/core-icons.html">

Keybase proof

I hereby claim:

  • I am dkordik on github.
  • I am dkordik (https://keybase.io/dkordik) on keybase.
  • I have a public key ASCAO4KMq8wsMpPZ5vs5rGvZlxNk75PYkdjOGO1nlafjFwo

To claim this, I am signing this object:

@dkordik
dkordik / time_command.sh
Last active March 22, 2017 02:42
Print out the execution time of a specified terminal command, 10 times
# Usage:
# ./time_command.sh "sleep 2"
# (or a command you actually care about timing, in quotes)
COMMAND="$1"
for N in {1..10}
do
printf "$N: "
( time `eval $COMMAND` ) 2>&1 | grep real | awk '{ printf $2 }'
@dkordik
dkordik / set_git_diff_aliases.sh
Created June 20, 2017 21:36
git diff aliases
#uses showlinenum.awk from: https://github.com/jay/showlinenum (needs gawk, brew install gawk)
alias gd='git diff --color=always | ~/showlinenum.awk color_line_number=90 color_separator=37 | less -r'
alias gds='git diff --staged --color=always | ~/showlinenum.awk color_line_number=90 color_separator=37 | less -r'