Skip to content

Instantly share code, notes, and snippets.

@jlinoff
jlinoff / aes_example.py
Created December 11, 2015 17:43
Python example that shows how to use the pycrypto (Crypto) module to do AES encryption and decryption.
#!/usr/bin/env python
'''
Simple example of how to use the crypto library for AES encryption and
decryption.
Make sure that the Crypto (pycrypto) module is installed:
$ pip-2.7 install pycrypto
$ pip-3.5 install pycrypto
@jlinoff
jlinoff / progress.sh
Created January 27, 2016 17:42
Bash example to report the progress of dealing with n items that also has an estimate of time remaining.
#!/bin/bash
#
# Function to measure and report progress.
# A bit like PV but for general things like copying N files.
# Use it as a starting point to created your own.
#
# License: MIT Open Source
# Copyright (c) 2016 Joe Linoff
# Show the progress of N items with an estimate of the time remaining.
@jlinoff
jlinoff / fix-img-parts.sh
Created March 18, 2016 21:19
Bash script to automatically find and fix the partitions in an image file on linux using losetup, fdisk, mke2fs and fsck.
#!/bin/bash
#
# This image will fix all of the partitions in a disk image.
#
# Usage:
# fix-image.sh test.img
#
# License: MIT Open Source
# Copyright (c) 2016 by Joe Linoff
#!/usr/bin/env python
'''
Report the first caller that is not part of the Foo class.
Tested in Python 2.7.11, 3.4 and 3.5.
License: MIT Open Source
Copyright (c) 2016 Joe Linoff
'''
@jlinoff
jlinoff / Primes.java
Last active April 21, 2016 17:37
Get primes in range using java 8 streams.
// This code example shows how to use java 8 streams to quickly
// determine primes in a range. It is NOT production code. It
// is only for reference.
// MIT License
// Copyright (c) 2016 - Joe Linoff
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@jlinoff
jlinoff / commaize.py
Created April 29, 2016 18:19
Add thousands separator to the integer portion of a string of digits.
#!/usr/bin/env python
'''
Add thousands separator to the integer portion of a string of digits.
It will handle a leading minus sign and a fraction.
Examples:
1234 --> 1,234
-1234 --> -1,234
@jlinoff
jlinoff / TestLogging.java
Last active September 12, 2016 21:38
custom log format example in java
package com.jlinoff;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.*;
/**
* Test logging.
*/
@jlinoff
jlinoff / ListClassMethods.java
Last active September 16, 2016 14:42
Java8 tool that performs introspection on java classes using reflection like javap. Useful for analyzing 3rd party classes.
/*
This class implements a CLI tool that does run time class introspection
using reflection. It is similar to javap. See the help (-h) for more details.
MIT License.
Copyright (c) 2016 Joe Linoff
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@jlinoff
jlinoff / exec.go
Last active October 30, 2016 16:18
Go program to execute arbitrary shell commands using exec and a simple, custom shell lexer.
//
// This simple program accepts linux commands from the command line and
// executes them using the exec package.
//
// The one tricky thing about this is that Go does not provide any way to
// tokenize the command strings because that process is shell dependent.
//
// The lexer I have written is pretty dumb but it works for most common
// use cases.
//
@jlinoff
jlinoff / lcsdiff.go
Last active October 31, 2016 16:35
Go program that implements the LCS algorithm to run a side by side diff of two files for educational purposes.
// Program to diff to files to find mismatches using the
// longest common subsequence (LCS) algorithm.
// See the help (-h) for more information.
// To build it:
// $ go build -o lcsdiff lcsdiff.go lcsdiff_options.go
/*
License: The MIT License (MIT)
Copyright (c) 2016 Joe Linoff