Skip to content

Instantly share code, notes, and snippets.

@dtsn
dtsn / 0_reuse_code.js
Last active February 27, 2017 11:29
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dtsn
dtsn / standard-deviation.js
Created May 26, 2016 08:34
How to get the mean and standard deviation from an array in JavaScript
var arr = [1,1,1,2,3,4,5,3,3,3,4,5,6,3,2,4,6];
// first work out the mean
var mean = arr.reduce(function (p, c) {
return p + c;
}) / arr.length;
// now the stanard deviation
var standardDeviation = Math.sqrt(arr.map(function (l) {
return Math.pow(l - mean, 2);
@dtsn
dtsn / deepOmit.js
Created October 22, 2013 10:49
Omit keys from an object
/**
* Omit keys from an object by an Array
*
* @param Object Obj The original object
* @param [[string, ....] The array of blacklisted keys
*
* @returns a clone of the obj with the keys removed
*/
var deepOmit = function (obj) {
var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
@dtsn
dtsn / instagram_tweetdeck.js
Last active December 24, 2015 21:38
A first stab at a instagram loader for the web version of TweetDeck. It needs to be run on a loop and also needs to keep a record of all the links it has gathered.
// ==UserScript==
// @name TweetDeck Instagram
// @description Adds instagram to Tweetdeck
// @include https://tweetdeck.twitter.com/*
// @include chrome-extension://hbdpomandigafcibbmofojjchbcdagbl/*
// @version 0.1
// ==/UserScript==
var func = function () {
$callback = $_GET['callback'];
$posts = [];
if (have_posts()) {
while(have_posts()) {
array_push(the_post());
}
}
print $callback . '(' . json_encode($posts) . ')';
@dtsn
dtsn / twitterEmbed.js
Created November 2, 2012 10:02
Twitter Embed - Using the oEmbed format this piece of code will fetch the oEmbed object from twitter for a given status ID and will call your callback with the data
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true,
unused:true, curly:true, browser:true, indent:4, maxerr:50, globalstrict:false */
/**
* Will fetch the Twitter embed object
*
* See https://dev.twitter.com/docs/embedded-tweets for more information
*
* @param {Int} id Twitter status ID
* @param {Function} callback The callback function when this is successful
@dtsn
dtsn / clone.js
Created October 19, 2012 10:11
JavaScript Shallow Clone
Object.prototype.clone = function () {
var obj = {};
for (var prop in this) {
obj[prop] = this[prop];
}
return obj;
};
@dtsn
dtsn / hack.sh
Created April 2, 2012 08:23 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2281636/hack.sh | sh
#
@dtsn
dtsn / blink.js
Created December 5, 2011 16:12
This is a very very bad thing .......
@dtsn
dtsn / CrawlObject.js
Created November 9, 2011 15:03
If you wanted to retrieve the object window.frames.url when you only have a array of string parts ['frames', 'url']
/**
* Will give you the object from a set of arrays
*
* If you wanted to retrieve the object window.frames.url when you only have a array of string parts ['frames', 'url']
*/
function crawl(obj, keys) {
var key = keys.shift();
return keys.length == 0 ? obj[key] : crawl(obj[key], keys);
}