Skip to content

Instantly share code, notes, and snippets.

View stollcri's full-sized avatar

Christopher Stoll stollcri

View GitHub Profile
@stollcri
stollcri / min.c
Created June 6, 2014 15:11
Minimum Functions for 3 Integers in C
#include <stdio.h>
#include <limits.h>
#include <sys/time.h>
#define TEST_ITTERATIONS 100
#define TEST_LOOPS 100000
static inline int min3a(int a, int b, int c)
{
if (a < b) {
@stollcri
stollcri / min.swift
Created June 6, 2014 15:13
Minimum Functions for 3 Integers (or Variadic) in Swift
import CoreFoundation
let TEST_ITTERATIONS = 100.0
let TEST_LOOPS = 100_000
func min3a(a: Int, b: Int, c: Int) -> Int {
if a < b {
if a < c {
return a
} else {
@stollcri
stollcri / comparableGenerics.swift
Created June 7, 2014 14:38
Protocol type constraints for generics in Apple Swift
/*
* Here the Comparable protocol is used as the type constraint
* For equality testing the Equitable protocol would be needed
* To print a variable it must conform to the Printable protocol
*
* see also:
* https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/SwiftStandardLibraryReference/Equatable.html#//apple_ref/doc/uid/TP40014608-CH17-SW1
*/
func min3a_generics<T: Comparable>(a: T, b: T, c: T) -> T {
if a < b {

Keybase proof

I hereby claim:

  • I am stollcri on github.
  • I am stollcri (https://keybase.io/stollcri) on keybase.
  • I have a public key whose fingerprint is FD0D 1A69 8AD9 F05A 3052 707A 0D01 AA8F 51B2 E3EA

To claim this, I am signing this object:

@stollcri
stollcri / nmon_initd_debian_ubuntu
Last active October 16, 2015 13:39
Ubuntu (Debian) init.d script for nmon
#!/bin/sh
### BEGIN INIT INFO
# Provides: nmon
# Required-Start: $network $named $syslog
# Required-Stop: $network $named $syslog
# Should-Start: nmon
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
#
@stollcri
stollcri / cat_awk_col40.sh
Created October 20, 2015 13:47
Print lines where the date in column 40 is September of 2015
#!/bin/bash
cat WIDE_TAB_DELIMITED.TXT | awk -F\t '$40 ~ /09\/.+?\/2015/' >> MATCH_COL_40_DATE_SEPT.TXT
@stollcri
stollcri / detach_process.txt
Created November 13, 2015 15:14
Detach a running process so that it can run after logout
$ myapp
$ Ctrl-z
[1]+ Stopped myapp
$ disown -h %1
$ bg 1
[1]+ myapp &
$ exit
@stollcri
stollcri / aws_s3_sync.sh
Created December 4, 2015 13:11
Synchronize files to AWS S3
$SRC_DIR=/var/www/htdocs
cd $SRC_DIR/images
DIR_SIZE=$(du . -hS | tail -n1 | awk '{print $1}')
echo "Syncing s3://BUCKET_NAME/images/ ($DIR_SIZE)"
/usr/local/bin/aws s3 sync . s3://BUCKET_NAME/images/ --storage-class STANDARD --exclude '.*' --exclude '*.php'
cd $SRC_DIR/images-old
DIR_SIZE=$(du . -hS | tail -n1 | awk '{print $1}')
echo "Syncing s3://BUCKET_NAME/images-old/ ($DIR_SIZE)"
@stollcri
stollcri / insert_text.sh
Created November 25, 2015 21:02
Insert text into a file at a specified line number
# insert ADDTHISTEXT at line 4 of MYFILE.TXT
sed -i '4i\ADDTHISTEXT\' MYFILE.TXT
#!/bin/bash
#
# Refresh data in AWS RDS database
#
# Add to cron: aws_db_sync.sh &> aws_db_sync.log
# or
# Call by: aws_db_sync.sh &> aws_db_sync.log &
# tail -f aws_db_sync.log
if [ ! -r ~/.my.cnf ]; then