Skip to content

Instantly share code, notes, and snippets.

View mdp's full-sized avatar

Mark Percival mdp

View GitHub Profile
@mdp
mdp / luhn.java
Created March 21, 2014 17:38
Luhn algorithm (mod10) in Java
/**
* Luhn Class is an implementation of the Luhn algorithm that checks validity of a credit card number.
*
* @author <a href="http://www.chriswareham.demon.co.uk/software/Luhn.java">Chris Wareham</a>
* @version Checks whether a string of digits is a valid credit card number according to the Luhn algorithm. 1. Starting with the second to last digit and
* moving left, double the value of all the alternating digits. For any digits that thus become 10 or more, add their digits together. For example,
* 1111 becomes 2121, while 8763 becomes 7733 (from (1+6)7(1+2)3). 2. Add all these digits together. For example, 1111 becomes 2121, then 2+1+2+1 is
* 6; while 8763 becomes 7733, then 7+7+3+3 is 20. 3. If the total ends in 0 (put another way, if the total modulus 10 is 0), then the number is valid
* according to the Luhn formula, else it is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while 8763 is valid (as shown
* above, it comes ou
@mdp
mdp / cleanup.sh
Created September 30, 2011 23:36
Git branch cleanup
# This must be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
git branch --merged master | grep -v 'master$' | xargs git branch -d
# Show remote fully merged branches
echo "The following remote branches are fully merged and will be removed:"
git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$'
@mdp
mdp / README.md
Last active May 22, 2021 07:53
Magically watermark your PDF's in bulk

Requirements

_Assumes you are on OSX (sorry, I didn't have time to test it on linux)

Usage

./watermark.sh mydoc.pdf &lt; recipients.txt

@mdp
mdp / README.md
Last active March 24, 2021 15:32
Clone/Sync all gists

Clone all your gists

Stolen from mbostok and improved upon

node cloneAllGists.js username token [outputDir]

@mdp
mdp / csp_middleware.js
Created October 13, 2015 17:23
Node.js CSP
let sources = {
'default-src': ['\'self\''],
'script-src': ['\'self\'','https://*.myexternalcdn.com'],
'frame-src': ['https://someexternalframesource.com'],
'img-src': ['\'self\'', 'https:', 'data:'],
'style-src': ['\'self\'', 'https:'],
'font-src': ['\'self\'', 'https:'],
'connect-src': ['\'self\''],
}
### Keybase proof
I hereby claim:
* I am mdp on github.
* I am mdp (https://keybase.io/mdp) on keybase.
* I have a public key whose fingerprint is 3977 96B0 0D37 D95B 3FDC F12F 32FC E8AB 7513 4EF9
To claim this, I am signing this object:
package com.dotp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
// http://www.shamrock-software.eu/erlang.htm
// Erlang B Equation
// Javascript: Percentage of busy
// calls with a=traffic and n lines
function erl(a,n)
{ u=1;
for(i=1;i<=n;i++) u+=pow(a,i)/fak(i);
return((pow(a,n)/fak(n))/u+0.005)*100
}
function fak(i) // Get factorial of i
@mdp
mdp / env-to-ssm.sh
Created January 8, 2018 21:33
.env to SSM
#!/bin/bash
# Usage: ./env-to-ssm.sh prefix envfile
# Ex: ./env-to-ssm.sh prod.app .env
AWS_SSM_PREFIX=$1
ENV_FILE=$2
cat aws/.env | grep -v ^# | grep -v -e '^$' | while read line
@mdp
mdp / openvpn.sh
Created November 21, 2017 21:41
OpenVPN setup on docker
#!/bin/bash
arg=$1
host=$2
OVPN_DATA="ovpn-data"
set -x
if [ "$arg" == "setup" ]; then