Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
jtpaasch / loader.js
Created May 1, 2012 15:07
Javascript module for loading scripts asynchronously.
/**
* A module for loading scripts asynchronously in most browsers.
*
* Note: this module uses the script.async attribute (see line 30), which
* tells the browser to load the script asynchronously. Most modern browsers
* support this async functionality, but those that don't will simply
* overlook it without causing problems.
*
* In addition, older versions of IE, Webkit, and Firefox 4+ that don't
* support the async attribute will still load scripts asynchronously
@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 / install_newrelic_plugins
Last active March 24, 2019 10:14
Installs the nginx and logwatcher plugins for newrelic on a CentOS system.
#!/bin/bash
# ----------------------------------------------------------------------
# Prelimenary checks
# ----------------------------------------------------------------------
# Make sure there's a license key file.
KEYFILE="LICENSEKEY"
if [ ! -e $KEYFILE ]; then
echo "No LICENSEKEY found."