This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var numerator = [1,2,3,4]; | |
| var denominator = [4,3,2,1]; | |
| numerator.map(function(elem, index) { | |
| return elem / denominator[index]; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| for remote in gnarf jugglinmike oconnore protonk rwaldron | |
| do | |
| git remote add $remote git@github.com:$remote/gaia | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function randme(arr) { | |
| var rand = parseInt(Math.random().toString().charAt(3), 10); | |
| return arr[rand % arr.length]; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function intAdd(arr) { | |
| var out; | |
| out = arr.reduce(function(l, r) { | |
| return l + r; | |
| }); | |
| return out.toString(2); | |
| } | |
| intAdd([1,2,3]) | |
| // "110" |