Skip to content

Instantly share code, notes, and snippets.

@gabalafou
gabalafou / hmac-sha1.js
Last active July 30, 2021 04:30
NodeJS: Generating a hard-to-guess password using a master password via HMAC-SHA1
const crypto = require("crypto");
const masterPassword = "opensesame";
const siteTag = "google.com";
const generatedPassword = crypto.createHmac("sha1", masterPassword).update(siteTag).digest("base64");
console.log(generatedPassword);
// Expected result: lr+ErV3uFsDPkep/Th7Xqva8Z4M=
@gabalafou
gabalafou / README
Last active July 30, 2021 15:53
Python and NodeJS: Generating a hard-to-guess password using a master password via HMAC-SHA1
Hi Stephan,
I think you may have been asking a question that I wasn’t sure I totally
understood, but I thought you were asking about being able to recreate the
password generation code in other environments. So maybe this clears things up,
maybe it doesn’t, but I think it’s interesting, either way.
If you have Python and NodeJS already installed on your computer, you should be
able to open up a REPL and paste the code snippets below directly into it and
get the same result in each one, which is what I was expecting, but it's neat to
@gabalafou
gabalafou / test.md
Created March 9, 2020 09:39 — forked from EpokK/test.md
FE Test: Modern Website

FE Test: Modern Website

Design

From this design, create a website using a static site generator like Gatsby or Next. Apply the appropriate CSS style to respect the design. Supporting responsive is optional.

Once done, upload your project on GitHub or GitLab. Then email back the git repository URL or zip the project to the person who sent the task.

Notes

@gabalafou
gabalafou / usage.js
Created December 1, 2015 20:54 — forked from jasonfarrell/usage.js
Checks if a DOM element is visible. Takes into consideration its parents and overflow.
var my_element = document.getElementById('my-element');
//-- Returns true/false
my_element.isVisible(my_element);
/**
* The string hash function from Java.
*
* Borrowed from http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
* @param {String} str
* @return {Number}
*/
function hash(str) {
var hash = 0, i, l, charCode;
if (str.length === 0)
@gabalafou
gabalafou / get-navigation-time.js
Last active August 29, 2015 14:23
Disqus helper functions for client-side generation of session id (see https://gist.github.com/gabalafou/66f04297c0f03dee7d20)
function getNavigationTime() {
var timing = window.performance && window.performance.timing;
// this method is expected to return a big number, so do this in any case
if (!timing)
return 1e5;
var timing = window.performance.timing;
var dns = timing.domainLookupEnd - timing.domainLookupStart;
var connection = timing.connectEnd - timing.connectStart;
@gabalafou
gabalafou / generate-session-id.js
Last active August 29, 2015 14:23
Disqus client-side session id generating function
function generateSessionId() {
// remove 3 most significant digits as they don't change often
var time = +(new Date().getTime().toString().substring(3));
// Doing only arithmetic operations here as bitwise shifts only operate on int32.
// Final number consists of two parts which should be independently random. Each part is
// converted to a number with base 32 in order to minimize overall length of the final number,
// but still keep it very random (14^32 different strings)
var id = Math.abs(time + getNavigationTime() - reduceMiscSessionMetrics()).toString(32);
id += random().toString(32);
@gabalafou
gabalafou / bucket.js
Last active August 29, 2015 14:23
window.crypto random int [0, 99] untested unused function
// Returns a random integer in the range [0, 99]
function getBucketInt() {
try {
var random;
// inside try-block because Uint8Array does
// not have wide browser support
var ab = new Uint8Array(1);
// note: 10 is arbitrary loop limit -