Skip to content

Instantly share code, notes, and snippets.

View sweetpalma's full-sized avatar

Paul Marlow sweetpalma

View GitHub Profile
@sweetpalma
sweetpalma / crypto.ec.pem.js
Created July 13, 2018 16:43 — forked from canterberry/crypto.ec.pem.js
Export PEM-encoded EC key pair (ECDH, ECDSA)
// (Buffer is available in Node.js as a global, but we require it this way for compatibility)
// See: https://nodejs.org/api/buffer.html#buffer_buffer
const { Buffer } = require('buffer');
const crypto = require('crypto');
const keyPair = crypto.createECDH('secp256k1');
keyPair.generateKeys();
// Print the PEM-encoded private key
@sweetpalma
sweetpalma / recursive_permutations.py
Last active April 11, 2018 20:49
Recursive permutations in Python.
# Recursive permutations in Python? Easy!
def permutation(arr):
if len(arr) > 1:
perms = []
for i in range(0, len(arr)):
for variation in permutation(arr[:i] + arr[i + 1:]):
variation.append(arr[i])
perms.append(variation)
return perms
else: return [arr]
@sweetpalma
sweetpalma / fizzbuzz.py
Created June 30, 2016 05:12
Precalculated FizzBuzz in Python
# Obvious code:
N, F, B = False, 'Fizz', 'Buzz'
seq = [N, N, F, N, B, F, N, N, F, B, N, F, N, N, F + B]
[print(seq[x % 15 - 1] or x) for x in range(1, 101)]
# How does it work? Just take a look at sample output, see that rhytm?
# 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
# 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz
# 31 32 Fizz 34 ... ZZZZ
# And so on. It's being repeated each 15 steps. So I've just precalculated