Skip to content

Instantly share code, notes, and snippets.

@jscari
jscari / Luhn.js
Last active November 17, 2020 02:27
Luhn algorithm - generate / validate
var Luhn = {
// length of our number (check digit included)
length: 10,
pow2: [0, 2, 4, 6, 8, 1, 3, 5, 7, 9],
// compute check digit
checksum: function (x) {
var sum = 0;
var n;
var odd = false;
for (var i = x.length - 1; i >= 0; --i) {
@jscari
jscari / gist:9e6d713e0125931699f7
Created December 10, 2015 16:30
Fast inserts with innoDB
SET GLOBAL innodb_flush_log_at_trx_commit=2;
//Make your inserts
SET GLOBAL innodb_flush_log_at_trx_commit=1;
@jscari
jscari / current_auto_increment.sql
Created December 10, 2015 16:23
Get the current auto_increment value for any table in Mysql
SHOW TABLE STATUS FROM `DatabaseName` LIKE 'TableName' ;
@jscari
jscari / clearTimeouts.js
Created November 30, 2015 19:07
Stop all timeouts in Javascript
// Set a fake timeout to get the highest timeout id
var highestTimeoutId = setTimeout(";");
// clear all timeouts with an id between 0 and highestTimeoutId
for (var i = 0 ; i < highestTimeoutId ; i++) {
clearTimeout(i);
}
/**
A pseudo random integer between 0 and MAX_VALUE according to a number n,
returns always the same pseudo random number when giving the same n and MAX_VALUE
*/
function pseudoRandomLCG(n, MAX_VALUE){
var a = 25214903917; var c = 11;
var m = Math.pow(2,32);
var x = 0;
for(var i = 0;i<n;i++){
x = (a+x*c) %m;