Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
jtpaasch / standard-in-out-error.php
Created November 6, 2012 23:31
Simple PHP script that can be run from the command line. It illustrates input/output/error usage.
<?php
/**
* If you call this with "$ php standard-in-out-error.php",
* it will print output and error messages to the command line.
*
* To pipe just the error messages into their own file,
* use "$ php standard-in-out-error.php 2> error.log"
*/
<?php
/**
* An SplClassLoader implementation that implements
* the PHP 5.3 standards.
*
* @based on https://gist.github.com/221634
*/
class SplClassLoader {
@jtpaasch
jtpaasch / quicksort.sh
Created July 24, 2013 12:16
A simple implementation of the quick sort algorithm.
#!/bin/bash
# A basic quick sort implementation.
# It takes a list of numbers (separated by spaces),
# and it prints them out in ascending order.
quicksort() {
# The list passed in.
local LIST=($@)
@jtpaasch
jtpaasch / OS.php
Created July 25, 2013 15:57
A simple OS class that helps PHP run commands on the command line.
<?php
/**
* The `OS` class helps run
* commands on the command line.
*
* @author JT Paasch
*/
class OS {
@jtpaasch
jtpaasch / not_duplicated.sh
Last active December 20, 2015 11:09
A bash function to check if an item is duplicated in a list. That is to say, it checks to make sure it is not already in the list.
#!/bin/bash
# A function that checks if an item is not already in a list.
# The first argument is the item to check for, the rest are the list to check in.
# Returns 1 if the item is duplicated in the list, or 0 if it's not.
not_duplicated() {
# The first argument is the item to check for.
local ITEM=$1
@jtpaasch
jtpaasch / filenames.sh
Last active December 20, 2015 11:09
Get all file names (just the basenames) in a directory.
#!/bin/bash
# Get all files in the folder.
FOLDER=/path/to/my/folder/*
# We'll build the list of file names here:
FILES=()
# Add just the basename of each FILE to the list of $FILES.
for FILE in $FOLDER
@jtpaasch
jtpaasch / simple_config_file_parse.sh
Created July 31, 2013 10:58
Reads a file containing an expression of the form KEY=VALUE, and it gets just the VALUE.
#!/bin/bash
# The path to the file.
FILE=/path/to/my/file
# Read the file's contents.
CONFIG_CONTENTS=$(<$FILE)
# Split at the '='.
PARTS=(${CONFIG_CONTENTS//=/ })
@jtpaasch
jtpaasch / repo_has_changed.sh
Created August 14, 2013 14:24
Checks if there are any new changes in a repo.
#!/bin/bash
# The git comamnd `git status --porcelain`
# will return a list of files that have changed.
# We'll redirect the output to /dev/null
# so that the results of the command don't get
# printed to the screen.
CHANGED=no
if git status --porcelain | >/dev/null ; then
@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 / 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):