Skip to content

Instantly share code, notes, and snippets.

View hjc's full-sized avatar

Hayden Chudy hjc

View GitHub Profile
@xeoncross
xeoncross / index.php
Created March 8, 2012 17:31
Tiny, SMTP client in PHP
<?php
/*
This is a very tiny proof-of-concept SMTP client. Currently it's over 320 characters (if the var names are compressed). Think you can build one smaller?
*/
ini_set('default_socket_timeout', 3);
$user = 'you@gmail.com';
$pass = '';
$host = 'ssl://smtp.gmail.com';
@hjc
hjc / add_to_assoc_ordered+numeric.php
Last active October 2, 2015 01:57
PHP: Add a key to an associative array and keep it's key ordering intact and sequential
/**
* Implements add_to_assoc_numeric
*
* Goal of this function is to allow us to modify an associative, numeric array
* (one that uses string numbers as keys, so there is no 0,1,2,3 ordering, but
* rather the ordering is based on when the keys were inserted [they are treated
* like other string keys]). If we modify this array using array_unshift or
* array_shift, we destory this associative, numeric structure (each key is
* destroyed and the array is simply renumbered, with ints, from 0 to num_elems),
* which we don't want. This function will allow us to insert a new value anywhere
@obscurerichard
obscurerichard / README.md
Created September 17, 2012 22:35
Simulates a low bandwidth, high-latency network connection

slow

This bash script offers quick shortcuts to simulate slower network connections. It is useful when you need to simulate a wireless network on a Linux network server, especially when you are using a virtual machine guest on your local machine or in the cloud.

slow 3G                   # Slow network on default eth0 down to 3G wireless speeds
slow reset                # Reset connection for default eth0 to normal
slow vsat --latency=500ms # Simulate satellite internet  with a high latency
slow dsl -b 1mbps         # Simulate DSL with a slower speed than the default

slow modem-56k -d eth0 # Simulate a 56k modem on the eth1 device. eth0 is unchanged.

@hjc
hjc / analyzer.rb
Created January 4, 2013 06:36
Simple Ruby Text Analyzer. Grabs simple document metrics from a text file, such as sentence count, word count, average words per sentence, etc.
#
# TEXT ANALYZER
# BY: Hayden Chudy
#
# basic setup for text analysis
stopwords = %w{the a by on for of are with just but and to the my I has some in}
lines = File.readlines(ARGV[0])
line_count = lines.size
text = lines.join
@satooshi
satooshi / ColorCLI.php
Last active December 12, 2015 09:19 — forked from donatj/ColorCLI.php
<?php
/**
* PHP CLI Colors – PHP Class Command Line Colors (bash)
*
* $str = "This is an example ";
*
* foreach (ColorCLI::$foregroundColors as $fg => $fgCode) {
* echo ColorCLI::$fg($str);
*
@hjc
hjc / bools.php
Created June 25, 2013 23:36
A small and simple array to convert any and all truthy/falsey values into a hard true or false, in PHP.
<?php
//I don't play this mismatched boolean logic bullshit, its true or
// false, never 1 or 0
$bool_replaces = [
'0' => false,
"1" => true,
false => false,
true => true,
0 => false,
1 => true,