Skip to content

Instantly share code, notes, and snippets.

View TehShrike's full-sized avatar
Shiny.

Josh Duff TehShrike

Shiny.
View GitHub Profile
@TehShrike
TehShrike / gist:3925018
Created October 20, 2012 22:15
Knowing when a recursion tree is finished
var functionThatCallsItselfMultipleTimes = function(starting_number) {
if (starting_number === 1) {
console.log("THING DONE!")
} else {
var roughly_half_the_number = Math.floor(starting_number / 2)
functionThatCallsItselfMultipleTimes(starting_number - roughly_half_the_number)
functionThatCallsItselfMultipleTimes(roughly_half_the_number)
}
}
@TehShrike
TehShrike / gist:4122000
Created November 20, 2012 23:30
Being silly
var variable = function() {
console.log(this.var || "NO U")
}
variable.variable = variable
variable.var = "lol"
variable()
variable.variable.variable.variable.variable()
@TehShrike
TehShrike / gist:4334955
Created December 19, 2012 06:58
Two ways to find out when all your async stuff is done
// Imagine that this is somebody else's async tool that you're using
var doAsyncThing = function(thing, cb) {
cb(thing + '!')
}
// So you have this utility function
var callThisWhenTheThingsAreDone = function(callback, number_of_things_to_do) {
var things_done = 0
return function() {
things_done++
@TehShrike
TehShrike / gist:5201022
Created March 19, 2013 23:15
A maybe marginally better way to build where clauses
var encloseifNecessary = function(value) {
if (typeof value === 'string') {
return "'" + escape(value) + "'"
} else {
// TODO: add further handling for arrays or whatever maybe
return value
}
}
var escape = function(value) {
@TehShrike
TehShrike / gist:499f133dfcdf449c3456
Last active August 29, 2015 14:04
Store two numbers inside one number
function singleNumberToXY(number, boardWidth) {
var x = number % boardWidth
var y = (number - x) / boardWidth
return {
x: x,
y: y
}
}
function test(number, width) {
@TehShrike
TehShrike / keybase.md
Created August 15, 2014 00:11
keybase.md

Keybase proof

I hereby claim:

  • I am tehshrike on github.
  • I am tehshrike (https://keybase.io/tehshrike) on keybase.
  • I have a public key whose fingerprint is 3B94 CC2A 2C46 7B35 2F61 F71F 545D 7CD7 3324 13D2

To claim this, I am signing this object:

@TehShrike
TehShrike / .gitconfig
Created August 25, 2014 23:06
Beyond Compare gitconfig
[diff]
tool = bcomp
[difftool]
prompt = false
[difftool "bcomp"]
trustExitCode = true
cmd = "/usr/local/bin/bcomp" "$LOCAL" "$REMOTE"
[merge]
tool = bcomp
[mergetool]
@TehShrike
TehShrike / escape.js
Last active August 29, 2015 14:05
JS quine
function escape(str) {
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\n/g, "\\n")
}
console.log(escape(require('fs').readFileSync('index.js', { encoding: 'utf8' })))
@TehShrike
TehShrike / row-to-objects
Created November 8, 2014 23:20
Parsing multiple objects from a single row
function getNames(key) {
var parts = key.split('_')
return {
type: parts.shift(),
property: parts.join('')
}
}
function rowToObjects(obj) {
@TehShrike
TehShrike / .bash_profile
Last active April 10, 2019 16:48
.bash_profile gives me pretty colors and git and node shortcuts
source /Users/josh/scripts/git-completion.bash
C_DEFAULT="\[\033[m\]"
C_WHITE="\[\033[1m\]"
C_BLACK="\[\033[30m\]"
C_RED="\[\033[31m\]"
C_GREEN="\[\033[32m\]"
C_YELLOW="\[\033[33m\]"
C_BLUE="\[\033[34m\]"
C_PURPLE="\[\033[35m\]"