Skip to content

Instantly share code, notes, and snippets.

@scottchiefbaker
scottchiefbaker / snmp_int_watch.pl
Created Aug 30, 2015
Monitor port bandwidth via SNMP
View snmp_int_watch.pl
#!/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
@scottchiefbaker
scottchiefbaker / jsonrpc-client.class.php
Last active May 22, 2018
Move to Curl instead of file_get_contents
View jsonrpc-client.class.php
<?php
// Create the client object
// $url = "https://scott.internal.web-ster.com/api/json-rpc/";
// $j = new jsonrpc_client($url);
// Run the echo_data() function
// $a = $j->echo_data('one','two');
// if $a === null, there was some sort of error
@scottchiefbaker
scottchiefbaker / argv.php
Last active Aug 29, 2015
PHP $argv processor - add support for single char arguments
View argv.php
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 / php-array-tests.php
Created Mar 20, 2015
PHP functions to test if an array is associative or numeric (hash vs array)
View php-array-tests.php
/**
* 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 / qw.php
Created Mar 20, 2015
PHP version of Perl's qw
View qw.php
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 / prng.php
Created Mar 16, 2015
Initial work on a userland implementation of the Easy User-land CSPRNG RFC
View prng.php
<?php
if (!function_exists("random_bytes")) {
function random_bytes($bytes = 16)
{
$ret = '';
if (function_exists("mcrypt_create_ivz")) {
$ret = mcrypt_create_iv($bytes);
View gist:9017fee1890d4741fe91
" 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
View Trim Test
use Benchmark qw(cmpthese);
use Getopt::Long;
use strict;
my $short = 0;
my $long = 0;
my $iterations = 3000000;
GetOptions(
"long" => \$long,
@scottchiefbaker
scottchiefbaker / term_test.pl
Created Oct 18, 2013
Test terminal color detection.
View term_test.pl
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;
}