Skip to content

Instantly share code, notes, and snippets.

@ondrek
ondrek / luhn-implementation.js
Last active January 15, 2018 22:51
Luhn Implementation in Javascript
// edited code (origin from http://imei.sms.eu.sk/index.html)
// ach, I hate italic
luhn = {};
luhn.calculate = function(originalStr){
var sum=0, delta=[0,1,2,3,4,-4,-3,-2,-1,0],
deltaIndex, deltaValue;
@ondrek
ondrek / javascript-clever-random.js
Last active December 25, 2015 12:59
Random Uniq Number (only 8-chars)
getRandom = function(){
var date = new Date().getTime();
var random = Math.floor((Math.random()*800)+100);
return(date+random).toString(36);
};
@ondrek
ondrek / gist:7231075
Created October 30, 2013 11:24
Add all deleted files on SVN
# pick all deleted files and remove them
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %
@ondrek
ondrek / mouse-position.js
Created October 31, 2013 15:15
How to get mouse position in Javascript
window.onmousemove = logMouseMove;
function logMouseMove(event) {
e = e || window.event;
mousePos = { x: e.clientX, y: e.clientY };
console.log(mousePos);
}
@ondrek
ondrek / sha512.js
Created November 4, 2013 10:04
Javascript SHA512 implementation
(function () {
// Shortcuts
var C = CryptoJS;
var C_lib = C.lib;
var Hasher = C_lib.Hasher;
var C_x64 = C.x64;
var X64Word = C_x64.Word;
var X64WordArray = C_x64.WordArray;
var C_algo = C.algo;
@ondrek
ondrek / gist:7413434
Created November 11, 2013 13:48
Smallest Base64 image
data:image/gif;base64,R0lGODlhAQABAAAAACw=
@ondrek
ondrek / express.js
Last active October 22, 2019 15:33
How structure big nodejs express application
---------------------------------------------------
Sample of Structure
/express.js
/views/javascript/jquery.js
/views/javascript/mootools.js
/views/stylesheets/resets.css
/views/stylesheets/globals.css
@ondrek
ondrek / s.js
Created November 19, 2013 21:43
terajsia implementacia
vsetkySubory = getFromApi('zoznamVsetkychSuborov');
vsetkySubory.forEach(function(subor, index){
vsetkySubory[index] = parseTemplate(getFromApi(subor));
callback();
})
function callback(){
if (i===vsetkySubory.length) {
downloadZip() } else { i++ }
@ondrek
ondrek / x.js
Last active December 30, 2015 03:28
every nth-second display just one second of array
sequence = ['1st','2nd','3rd','4th','5th','6th'];
function displaySequence(round, callback, i){
var i = i ? i : 0;
if (i===round) { callback(); return; }
console.log(sequence[i] + ' > add');
setTimeout(function(){
console.log(sequence[i] + ' > rmv');
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
o o o o
o o o o
o o
o o o o o o o o o o o o
o o o o o o
o 4 o 5 o o 2 o 3 o
o o o o o o
o o o o o o o o o o o o o o o o o o
o o o o