Skip to content

Instantly share code, notes, and snippets.

View hughdunne's full-sized avatar

Hugh Dunne hughdunne

  • County Kerry, Ireland
View GitHub Profile
var path = [];
function searchObj(obj,str) {
try {
if (typeof obj === "string") {
if (obj.toLowerCase().indexOf(str.toLowerCase()) >= 0) {
console.log(path.join("/") + " : " + obj);
}
} else if (obj && typeof obj === "object" && obj.constructor.name === 'Object') {
// Note: we want to avoid HTMLElements, circular structures etc. hence check constructor name
for (var k in obj) {
@hughdunne
hughdunne / cycleCreds.sh
Created April 1, 2016 17:34
Script to cycle through a list of files, setting a symlink to the next file in the list
#!/bin/sh
# I had a bunch of credentials files in a directory, and wanted to be able to
# cycle quickly between them so that I could log into a service with different
# identities. This script does the job by creating a symlink:
# credentials => creds.foo
# Every time you call it, it sets the symlink to the next file in the list.
# It's probably way overkill, but it was an interesting learning exercise writing it!
# This may need tweaking to work on your version of Linux.
setlink() {
@hughdunne
hughdunne / expect_js_extensions.js
Last active August 1, 2016 21:16
Some useful extensions for expect.js
// This allows us to assert that an object has the specified key.
// Alternatively we could say expect(obj.key).toExist()
// but the problem is that if the test fails, we only see: "Expected undefined to exist"
// and we don't know which property is missing.
expect.extend({
toHaveProperty(prop){
expect.assert(prop in this.actual, "Expected object to have property %s", prop)
},
});
#!/bin/bash
# Move all keys in Redis db $1 to db $2
if [ $# != 2 ] ; then
echo "Usage: $0 <db1> <db2>"
exit 1
fi
from=$1
to=$2
testarg () {
regex='^(0|[1-9][0-9]*)$'
@hughdunne
hughdunne / scr
Last active February 9, 2016 05:33
Utility for switching between Unix screens.
#!/bin/sh
# Utility for switching between Unix screens. Gives you a warning if you
# try to attach to a screen while already attached.
# Note that when you create a screen, you can give it a name with the -S option.
# Usage:
# scr -- Get a list of existing screens.
# scr foo -- Attach to a screen with name matching "foo" e.g. 23560.myfooscreen.
if [ "$#" -eq 0 ] ; then
# Get a list of existing screens.