Skip to content

Instantly share code, notes, and snippets.

Jeffrey Pratt clementi

Block or report user

Report or block clementi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@clementi
clementi / App.java
Created Jun 19, 2019
Secure Password Generator
View App.java
package net.jeffreypratt.edu.security;
import java.security.NoSuchAlgorithmException;
public class App {
public static void main(String[] args) {
var count = 1;
if (args.length > 0) {
count = Integer.parseInt(args[0]);
@clementi
clementi / entropy
Last active Jun 11, 2019
Naive string entropy calculator
View entropy
#!/usr/bin/env python3
import os
import fileinput
import string
import math
def get_string():
return fileinput.input()[0]
View ppgen
#!/usr/bin/env python3
import secrets
import string
import sys
import os
def generate_passphrase(word_index, size):
words = []
View pwgen
#!/usr/bin/env python3
import secrets
import string
import sys
def generate_password(chars, size):
return ''.join(secrets.choice(chars) for _ in range(size))
@clementi
clementi / kaprekar.rkt
Last active May 20, 2019
Kaprekar's Routine
View kaprekar.rkt
#lang racket
(define (kaprekar n)
(letrec [(digits (zero-pad n))
(diff (- (high digits) (low digits)))]
(cond [(= n 6174) 0]
[(< n 0) (error "n must be nonnegative")]
[(< (length (distinct digits)) 2) (error "n must be composed of at least two distinct digits")]
[(> (length digits) 4) (error "n must be four digits in length or less")]
[else (+ 1 (kaprekar diff))])))
@clementi
clementi / pwgen.zsh
Last active May 10, 2019
Generate random string from /dev/urandom
View pwgen.zsh
function pwgen() {
head -c 1024 /dev/urandom \
| LC_CTYPE=C tr -dc 'a-zA-Z0-9~!@#$%^&*_-/\\(){}[]:;<>\?\+=|.,"' \
| fold -w ${1:-20} \
| head -n 1;
}
@clementi
clementi / stuff.sml
Last active Mar 8, 2019
Standard ML Stuff
View stuff.sml
#!/usr/bin/env poly --script
fun rev xs =
let
fun revAcc acc xs =
case xs of
[] => acc
| (y :: ys) => revAcc (y :: acc) ys
in
revAcc [] xs
View stuff.idr
rev : List a -> List a
rev xs = revAcc [] xs where
revAcc : List a -> List a -> List a
revAcc acc [] = acc
revAcc acc (x :: xs) = revAcc (x :: acc) xs
even : Nat -> Bool
even Z = True
even (S k) = odd k where
odd Z = False
View pointfree-cli.rb
#!/usr/bin/env ruby
require 'json'
require 'net/http'
def success?(status_code)
status_code[0] == '2'
end
begin
@clementi
clementi / fizzbuzzhaskell.hs
Last active Feb 26, 2019
FizzBuzz in Haskell (one way to do it)
View fizzbuzzhaskell.hs
module Main where
import Control.Monad (forM_)
import System.Environment (getArgs)
printFizzBuzz :: Integral a => a -> IO ()
printFizzBuzz n
| n `mod` 3 == 0 && n `mod` 5 == 0 = putStrLn "FizzBuzz"
| n `mod` 3 == 0 = putStrLn "Fizz"
| n `mod` 5 == 0 = putStrLn "Buzz"
You can’t perform that action at this time.