Skip to content

Instantly share code, notes, and snippets.

View Protonk's full-sized avatar
🗯️
Before the hinge

Adam Hyland Protonk

🗯️
Before the hinge
View GitHub Profile

"He was a seaman, but he was a wanderer, too, while most seamen lead, if one may so express it, a sedentary life. Their minds are of the stay-at-home order, and their home is always with them—the ship; and so is their country—the sea. One ship is very much like another, and the sea is always the same. In the immutability of their surroundings the foreign shores, the foreign faces, the changing immensity of life, glide past, veiled not by a sense of mystery but by a slightly disdainful ignorance; for there is nothing mysterious to a seaman unless it be the sea itself, which is the mistress of his existence and as inscrutable as Destiny. For the rest, after his hours of work, a casual stroll or a casual spree on shore suffices to unfold for him the secret of a whole continent, and generally he finds the secret not worth knowing. The yarns of seamen have a direct simplicity, the whole meaning of which lies within the shell of a cracked nut."

Heart of Darkness, Joseph Conrad.

@Protonk
Protonk / structure.md
Last active August 29, 2015 14:09
draft ideas

Feminism

Establishing feminist critique as pushing against cultural resentment

"Prominent feminist critique — present in every other relevant medium, but new to games — has elicited massive backlash and threats to women working in the field."

By hylang core devs:
Defining Function Arguments in Hy
http://agentultra.com/2013/04/22/defining-function-arguments-in-hy/
Hy a Lisp on Python
http://agentultra.com/2013/04/19/hy-a-lisp-on-python/
Programming Can Be Fun with Hy
http://www.opensourceforu.com/2014/02/programming-can-fun-hy/
d3.quantile = function(values, p) {
  var H = (values.length - 1) * p + 1,
      h = Math.floor(H),
      v = +values[h - 1],
      e = H - h;
  return e ? v + e * (values[h] - v) : v;
};
@Protonk
Protonk / xorshift.js
Created January 2, 2014 16:59
The below is released under the GPL http://www.gnu.org/licenses/gpl.html
//Webkit2's crazy invertible mapping generator
// Theory is here: http://dl.acm.org/citation.cfm?id=752741
var xorshift = (function(seed) {
// We can't reach the maximal period inside JS because numbers above
// 2^53 aren't 'safe'
seed = seed || Math.round(Math.random() * Math.pow(2, 32));
return {
rand : function() {
// creates randomness...somehow...
@Protonk
Protonk / gbm.R
Last active December 31, 2015 22:49
library(jpeg)
library(plyr)
# Read in Girl before a Mirror from somewhere
# readJPEG only accepts a path, so give it one without much tomfoolery
picasso.path <- tempfile('girl_before_a_mirror.jpg')
download.file('http://bobholt.me/images/girl_before_a_mirror.jpg', picasso.path)
gbm <- readJPEG(picasso.path)
@Protonk
Protonk / fxn2json.R
Last active December 25, 2015 00:19
View R function bodies as JSON Objects
## Once you've loaded the dependencies you don't have to load them again in a session
## May have to install them via `install.packages(c('RJSONIO', 'plyr'))` first and only once per device
# Uses C parser for faster results compared to rjson
require('RJSONIO')
# Get a quick non-trivial function example
require('plyr')
# body(x) extracts the function body for x (also could set the function body of x)
ddBody <- as.list(body(ddply))
@Protonk
Protonk / better.R
Created August 16, 2013 18:40
A smarter solution to matching many to many
# For each element, match against the data frame of longer vectors
compSlightlySmarter <- function(element, table) {
matches <- sapply(table, function(x) {
# finds exact matches of element to the 'table' (one column in the longer df)
locations <- match(element, as.character(x))
# if there are no unbroken or unordered sequences, it's a match!
return(!any(is.na(locations)) & !is.unsorted(locations))
})
if(any(matches)) {
# unlike the dumb version, we return matches
@Protonk
Protonk / dumbest.R
Created August 16, 2013 18:00
The dumbest solution to the problem
long <- data.frame(c("foo","qux","baz","quux"),c("baz","bar","foo","corge"))
shrt <- data.frame(c("foo","bar","baz"),c("baz","bar","foo"))
concatDumb <- function(data) {
listed <- sapply(data, function(x) {
# concatenate the character vectors to use substring matching
paste0('$', paste(unname(x), collapse = '$'), '$')
})
return(unname(listed))
}
@Protonk
Protonk / sigdigit.js
Last active December 21, 2015 00:39
find significant digits. Useful for approximate equality tests where you care about orders of magnitude
/*
* sigDigitFind
*
* Determine position of most significant digit
*
* Returns a positive number for significant digits left of the radix
* and a negative number for right of the radix.
*
* @param {String} inputFloat A String (optionally a Number) representing a
* floating point number.