Skip to content

Instantly share code, notes, and snippets.

View ruzli's full-sized avatar

Ruzli ruzli

  • Russian Federation, Moscow
View GitHub Profile
@dsetzer
dsetzer / Array.prototypes.js
Last active September 25, 2022 05:15
A set of Array utils which I use (It should be noted that some are dependent on others)
// Calculates the sum of the items in the array.
// The sum is the result of adding all the items together.
Array.prototype.sum = function(){
return this.reduce((a, b) => a + b);
}
// Checks whether the specified item is present in the array.
Array.prototype.contains = function (item) {
return this.find(x => x === item) !== undefined;
}
@dsetzer
dsetzer / daffie-v4.0-stable.js
Last active December 7, 2021 01:39
bustadice script
const DEBUG = !0
const BET_BALANCE = 0.03 // max bankroll available to bet with
const MAX_CUT_OFF = 1.5
const MIN_CUT_OFF = 1.08
const BET_SPEED = 300
const iskips = 20
const hmrsv = 3
let prevresults = [];
let previous_losses = [];
let loseStreak = 0;
@Prateek479
Prateek479 / async.js
Created March 20, 2016 16:43
Async parallel forEach and async forEach
function asyncParForEach(array, fn, callback) {
var completed = 0;
if (array.length === 0) {
callback(); // done immediately
}
array.forEach(function(data) {
fn(data, function() {
completed++;
if (completed === array.length) {
@ScottKaye
ScottKaye / HandyDandyPrototypes.js
Last active July 10, 2023 19:16
A collection of potentially useful prototypes to make some things easier. Each of these should be crushable with http://www.iteral.com/jscrush/ . "Don't modify objects you don't own" is completely thrown out the window here in favour of coolness.
//Get a range of numbers between two numbers
//Usage: [1, 10].range returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Object.defineProperty(Array.prototype, "range", {
get: function () {
var range = [this[0]], i;
for (var i = this[0], len = this[1]; i < len; range.push(++i));
return range;
}
});
// Golfed TypeScript: