Skip to content

Instantly share code, notes, and snippets.

@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 / .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 / 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">
#!/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 / git-repo-merging.sh
Last active December 14, 2015 22:09
An example of merging 3 git repos into 1, and preserving all the history.
#setting the stage... creating 3 separate repos
mkdir animals; cd animals/; echo "Animals" > README; git init; git add .; git commit -m "Animals readme"; cd ..
mkdir dogs; cd dogs/; echo "Dogs" > README; git init; git add .; git commit -m "Dogs readme"; cd ..
mkdir cats; cd cats/; echo "Cats" > README; git init; git add .; git commit -m "Cats readme"; cd ..
#putting stuff in boxes for the move...
cd cats; mkdir cats #making /cats inside of cats, because in /animals we want /cats to be a subdir
git mv README cats #this line needs to me more appropriate to the contents of your actual child repo
git commit -m "Prepare cats for merge into animals"; cd ..
@dkordik
dkordik / dupeids.js
Created January 21, 2013 21:29
Smoke test for dupe CSS IDs
var dupeIds = [], dupeIdsString;
$('[id]').each(function(){
var ids = $('[id="' + this.id + '"]');
if (ids.length > 1 && ids[0] == this) {
dupeIds.push(this.id);
}
});
dupeIdsString = dupeIds.concat(", ");
@dkordik
dkordik / nowplaying-store.rb
Created December 6, 2012 09:12
Sniff network for iTunes Store updateNowPlaying requests via ngrep. Expand to do interesting things based on what you're playing.
require 'cgi'
match = 'track.updateNowPlaying'
ngrep_command = "ngrep -W byline '#{match}'"
puts "Watching network for iTunes Store now playing previews..."
IO.popen(ngrep_command).each do |line|
if line.match(/\=#{match}/)
@dkordik
dkordik / nowplaying.rb
Created December 6, 2012 08:49
Sniff network for iTunes #nowplaying mDNS announces via ngrep. Requires Ruby 1.9 for the awesome named-group regexes. Expand to do interesting things based on what you're playing.
match = 'nowplaying'
ngrep_command = "ngrep -W byline '#{match}' port 5353"
puts "Watching network for iTunes mDNS #nowplaying announces..."
IO.popen(ngrep_command).each do |line|
if line.match(/\##{match}/)
pattern = /nowplaying-title=(?<title>[\w ]+).+nowplaying-artist=(?<artist>[\w ]+).+nowplaying-album=(?<album>[\w ]+)/
@dkordik
dkordik / .bash_profile
Created November 26, 2012 23:03
Bash profile to set up SSH authentication only once per session for environments like Cygwin that suck at using SSH keys and normally require you to type in your password every time you authenticate
SSH_ENV="$HOME/.ssh/environment"
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
echo succeeded
chmod 600 "$SSH_ENV"
. "$SSH_ENV" > /dev/null
@dkordik
dkordik / ackref.rb
Created November 21, 2012 15:25
Check if each JS file is referenced in our Views, log unreferenced and referenced files - ACK required
#!/usr/bin/env ruby
class String
def -(other)
self.index(other) == 0 ? self[other.size..self.size] : nil
end
end
if ARGV.length < 2
puts