Skip to content

Instantly share code, notes, and snippets.

const bcrypt = require('bcryptjs');
const crypto = require('crypto');
const http = require('http');
const querystring = require('querystring');
const { promisify } = require('util');
const randomBytes = promisify(crypto.randomBytes);
const ONE_YEAR_IN_SEC = 365 * 24 * 60 * 60;
const users = [];
@skiano
skiano / interview-snippets.js
Last active March 8, 2018 15:35
Interesting code snippets to talk about
// -------------------------------------------------------------------------------------------------------
// Once (from source of async)
// @see https://github.com/caolan/async/blob/f5d86b80b986c8cad88a224a6f8b3ec154839490/lib/internal/once.js
// -------------------------------------------------------------------------------------------------------
function once(fn) {
return function () {
if (fn === null) return;
var callFn = fn;
fn = null;
@weikinhuang
weikinhuang / php-js-post-checkout-merge-hook
Last active May 2, 2020 12:41
post-checkout/post-merge hook to automate npm/yarn/bower/composer install only when they change
#!/bin/bash
#
# A hook to update files for package managers
# bin/post-checkout-merge-hook
#
# This is a post-merge/post-checkout/post-rewrite hook.
#
#set -x
if [[ "$SKIP_COM_GIT_HOOK" == '1' ]]; then
/**
* Code from:
* https://github.com/expressjs/express/pull/2809
*
* Target Express version: { "express": "^4.14.0 <5.0.0" }
*
* This monkey patch allows to return Promises from middleware and route handlers, rejections will be handled automaticaly.
*
* Please note:
* If you return something from `(...) -> void` callbacks - you shoot your own leg.
@danswick
danswick / index.html
Last active November 4, 2018 15:08
Mapbox.js fallback for Mapbox GL JS
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
#status {
@skevy
skevy / gist:8a4ffc3cfdaf5fd68739
Last active February 4, 2017 04:59
Redux with reduced boilerplate

Note

I would recommend @acdlite's redux-actions over the methods suggested in this Gist.

The methods below can break hot-reloading and don't support Promise-based actions.

Even though 'redux-actions' still uses constants, I've come to terms with the fact that constants can be good, especially in bigger projects. You can reduce boilerplate in different places, as described in the redux docs here: http://gaearon.github.io/redux/docs/recipes/ReducingBoilerplate.html


@krzkaczor
krzkaczor / fme.js
Created May 16, 2015 23:51
Fast modular exponentiation in Java Script
/**
* Fast modular exponentiation for a ^ b mod n
* @returns {number}
*/
var fastModularExponentiation = function(a, b, n) {
a = a % n;
var result = 1;
var x = a;
while(b > 0){
@rastasheep
rastasheep / keyrepeat.shell
Last active January 1, 2020 20:09 — forked from kconragan/keyrepeat.shell
Enable key repeat in Apple Lion for Atom in Vim mode
# Mac OS X Lion introduced a new, iOS-like context menu when you press and hold a key
# that enables you to choose a character from a menu of options. If you are on Lion
# try it by pressing and holding down 'e' in any app that uses the default NSTextField
# for input.
#
# It's a nice feature and continues the blending of Mac OS X and iOS features. However,
# it's a nightmare to deal with in Atom if you're running vim mode,
# as it means you cannot press and hold h/j/k/l to move through your file. You have
# to repeatedly press the keys to navigate.
@nodesocket
nodesocket / bootstrap.flatten.css
Last active April 1, 2021 23:37
Below are simple styles to "flatten" bootstrap. I didn't go through every control and widget that bootstrap offers, only what was required for https://commando.io, so your milage may vary.
/* Flatten das boostrap */
.well, .navbar-inner, .popover, .btn, .tooltip, input, select, textarea, pre, .progress, .modal, .add-on, .alert, .table-bordered, .nav>.active>a, .dropdown-menu, .tooltip-inner, .badge, .label, .img-polaroid {
-moz-box-shadow: none !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
-webkit-border-radius: 0px !important;
-moz-border-radius: 0px !important;
border-radius: 0px !important;
border-collapse: collapse !important;
background-image: none !important;
@arvearve
arvearve / gist:4158578
Created November 28, 2012 02:01
Mathematics: What do grad students in math do all day?

Mathematics: What do grad students in math do all day?

by Yasha Berchenko-Kogan

A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.

The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.

What can you say?