Skip to content

Instantly share code, notes, and snippets.

@HR
HR / encrypt.js
Last active August 23, 2018 01:19
Node.js AES file encryption with authentication promise
'use strict'
/**
* AES file encryption with authentication (using Promises)
* (C) Habib Rehman 2016
******************************/
const encrypt = function (origpath, destpath, key) {
// decrypts any arbitrary data passed with the pass
return new Promise(function (resolve, reject) {
// readstream to read the (unencrypted) file
@ofaurax
ofaurax / modinverse.py
Created March 30, 2016 15:04
Modular Inverse for RSA in python
#!/usr/bin/env python3
p = 61
q = 53
n = p*q
phi = (p-1)*(q-1)
# Took from SO
def egcd(a, b):
@subfuzion
subfuzion / curl.md
Last active May 13, 2025 18:51
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@srph
srph / oauth.js
Created February 21, 2016 13:50
axios: interceptor which includes your oauth token in every request as an Authorization header
import axios from 'axios';
// You can use any cookie library or whatever
// library to access your client storage.
import cookie from 'cookie-machine';
axios.interceptors.request.use(function(config) {
const token = cookie.get(__TOKEN_KEY__);
if ( token != null ) {
config.headers.Authorization = `Bearer ${token}`;
import random
def gcd(a, b):
a = abs(a)
b = abs(b)
while a:
a, b = b % a, a
return b
@massahud
massahud / Portable Node.js andNPM on windows.md
Last active March 27, 2025 20:21
Portable Node.js and NPM on windows
  1. Get node binary (node.exe) from http://nodejs.org/download/
  2. Create the folder where node will reside and move node.exe to it
  3. Download the last zip version of npm from http://nodejs.org/dist/npm
  4. Unpack the zip inside the node folder
  5. Download the last tgz version of npm from http://nodejs.org/dist/npm
  6. Open the tgz file and unpack only the file bin/npm (without extension) directly on the node folder.
  7. Add the the node folder and the packages/bin folder to PATH
  8. On a command prompt execute npm install -g npm to update npm to the latest version

Now you can use npm and node from windows cmd or from bash shell like Git Bash of msysgit.

@kerimdzhanov
kerimdzhanov / random.js
Last active February 26, 2025 22:12
JavaScript: get a random number from a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
@ozh
ozh / new empty git branch.md
Last active April 8, 2025 20:49
Create a new empty branch in Git
$ git checkout --orphan NEWBRANCH
$ git rm -rf .

--orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

You can then start adding files and commit them and they will live in their own branch. If you take a look at the log, you will see that it is isolated from the original log.

@gtke
gtke / bst
Created January 28, 2013 16:14
Binary Search Tree - JAVA implementation
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* BST
* @author gtkesh
*/
public class BST<T extends Comparable<T>> {
@vindia
vindia / droplet.css
Created August 13, 2012 12:13
CSS 3 Water Droplet
body { padding: 4em; }
#droplet {
background-color: lightblue;
width: 150px;
height: 150px;
-webkit-border-top-left-radius: 0;
-webkit-border-top-right-radius: 75px;
-webkit-border-bottom-right-radius: 75px;
-webkit-border-bottom-left-radius: 75px;
-webkit-transform:rotate(45deg);