Skip to content

Instantly share code, notes, and snippets.

View christiaanwesterbeek's full-sized avatar

Christiaan Westerbeek christiaanwesterbeek

View GitHub Profile
@WebReflection
WebReflection / i18n-noop.js
Created October 22, 2017 15:49
A template literal tag function that does nothing.
function i18n(t) {
for (var o = [t[0]], i = 1, l = arguments.length; i < l; i++)
o.push(arguments[i], t[i]);
return o.join('');
}

Aligning images

This is a guide for aligning images.

See the full Advanced Markdown doc for more tips and tricks

left alignment

@skeggse
skeggse / crypto-pbkdf2-example.js
Last active April 17, 2024 21:04
Example of using crypto.pbkdf2 to hash and verify passwords asynchronously, while storing the hash and salt in a single combined buffer along with the original hash settings
var crypto = require('crypto');
// larger numbers mean better security, less
var config = {
// size of the generated hash
hashBytes: 32,
// larger salt means hashed passwords are more resistant to rainbow table, but
// you get diminishing returns pretty fast
saltBytes: 16,
// more iterations means an attacker has to take longer to brute force an
@maephisto
maephisto / Javascript ISO country code to country name conversion
Last active November 3, 2023 21:05
ISO 3166-1 alpha-2 country code to country name conversion with a simple Javascript implementation, an array and a function.
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',
anonymous
anonymous / gist:4427822
Created January 1, 2013 14:20
Array#slice returns an array with the seleted range of items. Because a new array is created every time you use this method, however, all these arrays are in memory, which means the JavaScript GC (Garbage Collection) has to collect up all of these unused arrays and throw them away. In performance-critical situations, such as in a game-loop that …
Array.prototype.slice_mutate = (function () {
var i;
return function slice_mutate(from, to) {
// first we set the array's length to the item at the "to" position
this.length = to;
// any items that were after the "to" position will be discarded
// from the first item...
i = 0;
@tobitailor
tobitailor / get_barcode_from_image.js
Created June 1, 2010 19:33
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',