Skip to content

Instantly share code, notes, and snippets.

@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 / gist:7413434
Created November 11, 2013 13:48
Smallest Base64 image
data:image/gif;base64,R0lGODlhAQABAAAAACw=
@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 / 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 / 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 / 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 / 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 / luhn.js
Created October 14, 2013 18:04 — forked from ShirtlessKirk/luhn.js
// Variant of Avraham Plotnitzky's String.prototype method mixed with the "fast" version
// see: https://sites.google.com/site/abapexamples/javascript/luhn-validation
function luhnChk(luhn) {
var len = luhn.length,
mul = 0,
prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
sum = 0;
while (len--) {
@ondrek
ondrek / iteration.js
Last active December 22, 2015 04:58
How to iterate array only to first wanted item and finish
function iterateArrayToFirstResult(arr){
loop: {
for (var i=0; i<arr.length; i++) {
if (arr[i]==42) {
console.log('You just found answer to the ultimate question of Life');
break loop;
}
console.log('Your array havent number 42');
}
}
@ondrek
ondrek / removephoto.js
Created September 1, 2013 18:54
remove photo from mongodb and from amazon s3
/* from photo mongo database and s3 */
var removePhoto = function(){
mongoclient.connect(database, function(err, db) {
if (err) throw err;
/* url../remove?98c582c7d329/3b1fa423d917 - album:98c582c7d329 photo:3b1fa423d917 */
var url = require('url').parse(req.url).query;
var album = underscore.words(url, '/')[0];
var photo = underscore.words(url, '/')[1];