Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
jtpaasch / argparse.rb
Created August 12, 2015 11:26
A simple Ruby argument parsing loop.
#!/usr/bin/env ruby
if ARGV.empty?
puts "No arguments provided."
end
until ARGV.empty? do
case ARGV[0]
when '-q'
ARGV.shift
@jtpaasch
jtpaasch / amazonctl.py
Created October 26, 2015 12:47
A collection of functions commonly used to do AWS stuff.
# -*- coding: utf-8 -*-
"""A simple tool to document how to control AWS resources.
AWS AUTHENTICATION
-------------------
In order to run any of the code below, you need a profile with AWS credentials
set up on your computer. It's very easy to do this. Google how to configure
your profile with boto3, or visit the docs:
@jtpaasch
jtpaasch / cli.py
Last active July 17, 2016 12:13
Helps build command line tools in Python.
# -*- coding: utf-8 -*-
"""A simple tool for making command line tools in python."""
import os
import sys
class CLI(object):
@jtpaasch
jtpaasch / nginx.conf
Last active February 10, 2016 20:48
Logging with nginx
# An events block is required for Nginx to run, even if it's empty.
events {}
# HTTP processing.
http {
# Note: log formats only apply to access_logs, not error_logs.
# Error logs always start with time stamp and then the level,
# e.g., [emerg] or [alert] or whatever.
@jtpaasch
jtpaasch / brickwalls.py
Created March 23, 2017 22:40
Find the number of ways to build a wall with 3x1 and 4.5x1 sized bricks.
# -*- coding: utf-8 -*-
"""Find the number of ways to build a wall with different sized bricks.
Command line usage:
python brickwalls.py <width> <height>
Examples:
python brickwalls.py 12 3
python brickwalls.py 27 5
@jtpaasch
jtpaasch / argparse.bash
Created May 11, 2017 05:22
Declare allowed arguments, parse args, and auto-generate help.
#!/usr/bin/env bash
#
# Utility for parsing command line arguments.
#
# To use it, declare the allowed flags, options, and arguments,
# then run the `parse_args()` function.
#
# To declare flags, e.g., `--verbose` and `--fail-fast`:
#
# flag__id__0="--verbose"
@jtpaasch
jtpaasch / simpleproc.ml
Created April 19, 2018 17:33
Simple process runner (Ocaml)
(** Compile with:
[ocamlc -c simpleproc.ml]
[ocamlc -o simpleproc.byte unix.cmo simpleproc.cmo]
Run it:
[./simpleproc.byte "ls -la"]
*)
@jtpaasch
jtpaasch / simpletimer.ml
Last active April 21, 2018 01:18
Times function running time (OCaml)
(* Compile with unix.cma(x). *)
type timetrial = {
time : float;
result : string;
}
let time_one f x =
let start = Unix.gettimeofday () in
let result = f x in
@jtpaasch
jtpaasch / simplepsshell.ml
Created April 25, 2018 23:01
A simple shell executor (OCaml)
let int_of_status s =
match s with
| Unix.WEXITED n -> n
| Unix.WSIGNALED n -> n
| Unix.WSTOPPED n -> n
let psshell ?exe:(exe="/bin/sh") cmd =
match Unix.fork() with
| 0 -> Unix.execvp exe [| exe; "-c"; cmd |]
| child_pid -> child_pid
@jtpaasch
jtpaasch / simpleproc2.ml
Last active April 27, 2018 21:46
Another process runner (OCaml)
module Proc = struct
let int_of_status s =
match s with
| Unix.WEXITED n -> n
| Unix.WSIGNALED n -> n
| Unix.WSTOPPED n -> n
let shell cmd out err =
match Unix.fork () with