Skip to content

Instantly share code, notes, and snippets.

View richshaw's full-sized avatar

Richard Shaw richshaw

View GitHub Profile
@arnoud999
arnoud999 / MTurk update workerlist.R
Created June 10, 2015 14:28
Excluding MTurk workers who participated in your previous studies: An R solution
############################################################################
# #
# Excluding participants who participated in previous studies #
# By Arnoud Plantinga, based on Gabriele Paolacci's Excel solution #
# #
# Instructions (Note: edit only the non-indented lines): #
# #
# 1. Create a qualification (e.g., "Study 1"; keep in mind that the name #
# will be visible to Workers) in MTurk/Manage/Qualification Types #
# #
@turnersr
turnersr / rs.py
Created April 29, 2014 04:17
Single-pass, parallel statistics algorithms for mean, variance, and standard deviation
class RunningStat(object):
"""
Based on ideas presented in
1. Numerically Stable, Single-Pass, Parallel Statistics Algorithms - http://www.janinebennett.org/index_files/ParallelStatisticsAlgorithms.pdf
2. Accurately computing running variance - http://www.johndcook.com/standard_deviation.html
"""
def __init__(self):
self.m_n = 0
self.m_oldM = 0
@mrdwab
mrdwab / cSplit.R
Last active March 14, 2023 05:03
The faster version of `concat.split` that makes use of `data.table` efficiency.
cSplit <- function(indt, splitCols, sep = ",", direction = "wide",
makeEqual = NULL, fixed = TRUE, drop = TRUE,
stripWhite = FALSE) {
message("`cSplit` is now part of the 'splitstackshape' package (V1.4.0)")
## requires data.table >= 1.8.11
require(data.table)
if (!is.data.table(indt)) setDT(indt)
if (is.numeric(splitCols)) splitCols <- names(indt)[splitCols]
if (any(!vapply(indt[, splitCols, with = FALSE],
is.character, logical(1L)))) {
@dustinlarimer
dustinlarimer / README.md
Last active September 11, 2018 01:38
Keen IO Geo Coordinates in a Google Map
@Pyrolistical
Pyrolistical / functions.js
Last active December 28, 2017 04:10 — forked from RedBeard0531/functions.js
Mongo map reduce functions to calculate sum, min, max, count, average, population variance, sample variance, population standard deviation, sample standard deviation Public Domain License
function map() {
emit(1, {
sum: this.value, // the field you want stats for
min: this.value,
max: this.value,
count: 1,
diff: 0
});
}
@compact
compact / dropzone-directive.js
Last active March 16, 2024 02:55
AngularJS directive for Dropzone.js
/**
* An AngularJS directive for Dropzone.js, http://www.dropzonejs.com/
*
* Usage:
*
* <div ng-app="app" ng-controller="SomeCtrl">
* <button dropzone="dropzoneConfig">
* Drag and drop files here or click to upload
* </button>
* </div>
bigcorPar <- function(x, nblocks = 10, verbose = TRUE, ncore="all", ...){
library(ff, quietly = TRUE)
require(doMC)
if(ncore=="all"){
ncore = multicore:::detectCores()
registerDoMC(cores = ncore)
} else{
registerDoMC(cores = ncore)
}
@goldsky
goldsky / currency.inc.php
Last active December 13, 2015 19:58
ISO-4217 Currency Codes in a PHP array
<?php
header('Content-Type: text/html; charset=utf-8');
/**
* Download the currecy data from the link below, and place it along side this file
* @link http://www.currency-iso.org/en/home/tables/table-a1.html Current currency & funds code list
*/
$xml = file_get_contents( dirname(__FILE__) . '/dl_iso_table_a1.xml');
$currencyArray = json_decode(json_encode((array) simplexml_load_string($xml)), 1);
@haganbt
haganbt / gist:4117429
Created November 20, 2012 11:36
DataSift Push API - PHP HTTP POST Receiver Examples
<?php
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(str_replace("_"," ",substr($key,5))));
$out[$key]=$value;
}
}
return $out;
@jasonfarrell
jasonfarrell / usage.js
Last active February 23, 2021 22:15
Checks if a DOM element is visible. Takes into consideration its parents and overflow.
var my_element = document.getElementById('my-element');
//-- Returns true/false
my_element.isVisible(my_element);