Skip to content

Instantly share code, notes, and snippets.

use Benchmark qw(cmpthese);
use Getopt::Long;
use strict;
my $short = 0;
my $long = 0;
my $iterations = 3000000;
GetOptions(
"long" => \$long,
" Scott's vimrc file
set autoindent " auto indent the next line when you hit enter
set backspace=2 " Backspace over everything in insert mode
set tabstop=4 " Tabs display as three spaces
set shiftwidth=4 " Shiftwidth is X for < and > moves
set softtabstop=4 " Soft tab stop
set noexpandtab " Don't expand tabs in insert mode
set ruler " Show what line/char you're on
set t_Co=256 " use 256 colors
set exrc " Enable reading .vimrc in the current dir to complement global one
@scottchiefbaker
scottchiefbaker / prng.php
Created March 16, 2015 22:32
Initial work on a userland implementation of the Easy User-land CSPRNG RFC
<?php
if (!function_exists("random_bytes")) {
function random_bytes($bytes = 16)
{
$ret = '';
if (function_exists("mcrypt_create_ivz")) {
$ret = mcrypt_create_iv($bytes);
@scottchiefbaker
scottchiefbaker / qw.php
Created March 20, 2015 16:55
PHP version of Perl's qw
function qw($str,$return_hash = false) {
$str = trim($str);
// Word characters are any printable char
$words = str_word_count($str,1,"!\"#$%&'()*+,./0123456789-:;<=>?@[\]^_`{|}~");
if ($return_hash) {
$ret = array();
$num = sizeof($words);
@scottchiefbaker
scottchiefbaker / php-array-tests.php
Created March 20, 2015 16:59
PHP functions to test if an array is associative or numeric (hash vs array)
/**
* Returns boolean if a function is an associative array
*
* @param array $array An array to test
*
* @return boolean
*/
public static function is_assoc_array($array) {
if (!is_array($array)) { return false; }
// $array = array() is not associative
@scottchiefbaker
scottchiefbaker / argv.php
Last active August 29, 2015 14:22
PHP $argv processor - add support for single char arguments
function args($item = '') {
// Throw away the first one (name of script)
$args = array_slice($GLOBALS['argv'],1);
$ret = array();
for ($i = 0; $i < sizeof($args); $i++) {
// If the item starts with "-" it's a key. Ignore items that are single dash words (-debug)
if (preg_match("/^--?([a-zA-Z_]\w*)/",$args[$i],$m) && !preg_match("/^-\w\w/",$args[$i])) {
$key = $m[1];
// If the next item does not start with "--" it's the value for this item
@scottchiefbaker
scottchiefbaker / snmp_int_watch.pl
Created August 30, 2015 05:03
Monitor port bandwidth via SNMP
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Time::HiRes qw(time sleep);
use Net::SNMP;
#use Data::Dump::Color;
my $debug = 0;
my $delay = 3; # Default delay is 3 seconds
package JSON::RPC::Client::Lite;
use HTTP::Tiny;
use vars '$AUTOLOAD';
use JSON;
#use Data::Dump::Color;
sub new {
my ($class,$url,$opts) = @_;
@scottchiefbaker
scottchiefbaker / term_test.pl
Created October 18, 2013 18:35
Test terminal color detection.
my $depth = terminal_color_depth();
print "My terminal has " . $depth . " colors\n";
sub terminal_color_depth {
# If we're not attached to an STDOUT don't go any further
if (!-t STDOUT) {
return 8;
}
#!/usr/bin/perl
########################################################################
# This script runs tcpdump on a specific NIC (defaults to eth1) and
# parses the output from that to calculate the top talked, both send
# and receive. After X second it will output who the top talkers were
# and continue to calculate
#
# Scott Baker - 2009-07-31
########################################################################