Skip to content

Instantly share code, notes, and snippets.

View jaggedsoft's full-sized avatar
Productive

jagged jaggedsoft

Productive
View GitHub Profile
@photonstorm
photonstorm / gist:5300530
Created April 3, 2013 11:49
array shuffle
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
@alexspeller
alexspeller / base64encode.js.coffee
Last active December 21, 2015 04:38
Ember Table Extensions
# So, this is pretty horrible. If we just encode using btoa, any UTF-8 chars cause an error.
# If we use either of the workarounds on MDN[1], the £ sign is encoded wrong. I suspect
# Excel totally sucking at encodings is the reason why. So, the workaround is, to use
# the MDN workaround on chars with values > 255, and allow chars 0-255 to be encoded
# as is with btoa. Note that if you use either of the workarounds on MDN, chars
# 128-255 will be encoded as UTF-8, which includeds the £ sign. This will cause excel
# to choke on these chars. Excel will still choke on chars > 255, but at least the £
# sign works now...
# [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
@tcjr
tcjr / messages.json
Last active December 25, 2015 06:59
Basic pagination with Ember
// The API accepts the page parameter and returns the pagination info in meta
{
"messages": [ ... ],
"meta": {
"pagination": {
"total_pages": 3,
"current_page": 1,
"total_count": 55
}
@RobinBressan
RobinBressan / digestBomb.js
Last active April 15, 2016 15:14
Angular $digest bomb. Like fork bomb but with $digest.
function digestBomb() {
var $rootScope = angular.injector(['ng']).get('$rootScope');
function $digest() {
$rootScope.$$postDigest($digest);
$rootScope.$digest();
}
$digest();
}
@shripadk
shripadk / gist:562270
Created September 2, 2010 13:16
Google Closure XPC demo
goog.require('goog.Uri');
goog.require('goog.events');
goog.require('goog.json');
goog.require('goog.net.xpc.CrossPageChannel');
goog.global.initOuter = function(url) {
goog.events.listen(window, 'load', function() { xpcdemo.initOuter(url); });
};
goog.global.initInner = function() {
goog.events.listen(window, 'load', function() { xpcdemo.initInner(); });
@DTrejo
DTrejo / top3stories.js
Created January 21, 2011 22:41
Gets top three articles from frontpage and newpage of Hacker News. Blog post on scraping: http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga
// Scraping Made Easy with jQuery and SelectorGadget
// (http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga)
// by David Trejo
//
// Install node.js and npm:
// http://joyeur.com/2010/12/10/installing-node-and-npm/
// Then run
// npm install jsdom jquery http-agent
// node numresults.js
//
@dhoko
dhoko / countWatcher.js
Created September 22, 2015 09:42
[Bookmarklet] Debug AngularJS
// Version without jQuery
javascript:(function () { var root = angular.element(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) { if (element.data() && element.data().hasOwnProperty(scopeProperty)) { angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) { watchers.push(watcher); }); } }); angular.forEach(element.children(), function (childElement) { f(angular.element(childElement)); }); }; f(root); var watchersWithoutDuplicates = []; angular.forEach(watchers, function(item) { if(watchersWithoutDuplicates.indexOf(item) < 0) { watchersWithoutDuplicates.push(item); } }); console.log(watchersWithoutDuplicates.length); })();
// Version with jQuery
javascript:(function () { var root = $(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { if (element.data().hasOwnProperty('$scope')) { angular.forEach(element.data().$scope.$$watchers, function (watche
@andrewrk
andrewrk / bench.js
Last active January 14, 2018 03:11
faster, more random, and simpler than the node uuid module. 27 bytes of randomness instead of 16, yet still encoded into a string of length 32
var uuid1 = require('uuid');
var crypto = require('crypto');
testOne("uuid module", uuid1);
testOne("my code", uuid2);
function testOne(name, fn) {
process.stdout.write(name + ": ");
var start = new Date();
var s = "";
@vega113
vega113 / check-balances.js
Created September 29, 2016 07:31
Check balances in bittrex
var bittrex = require('./node.bittrex.api.js');
bittrex.options({
'apikey': '',
'apisecret': '',
'stream': false,
'verbose': false,
'cleartext': false
});
const setTimeout = require('timers').setTimeout;
const clearTimeout = require('timers').clearTimeout;
const WebSocket = require('ws');
const Bluebird = require('bluebird');
const Queue = require('promise-queue');
const binance = require('../node-binance-api.js');
binance.options({
APIKEY: '<api key>',
APISECRET: '<api secret>',