Skip to content

Instantly share code, notes, and snippets.

View brettfreer's full-sized avatar

Brett Freer brettfreer

View GitHub Profile
@brettfreer
brettfreer / perl-post-multipart.pl
Created May 26, 2016 00:12
Example showing perl multipart http(s) post
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
my $url = 'https://someurl.com/einvoice.dll';
my $filename = $ARGV[0];
my $sid = "username";
my $spwd = "password";
@brettfreer
brettfreer / perl-post-xml.pl
Created May 26, 2016 00:09
Example perl script showing http(s) post of a cXML document
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use Net::SSL;
use LWP::Protocol::https;
use URI::https;
my $url = 'https://someurl.com/SubmitCXML';
@brettfreer
brettfreer / last_day_of_month.py
Last active May 24, 2016 06:30
Return last day of month
import datetime
import calendar
def last_day_of_month(d):
return datetime.datetime(d.year, d.month, calendar.mdays[d.month]).date()
@brettfreer
brettfreer / first_day_of_month.py
Last active May 24, 2016 06:28
Return first day of month
import datetime
def first_day_of_month(d):
return datetime.date(d.year, d.month, 1)
@brettfreer
brettfreer / linux_idleout.sh
Last active May 23, 2016 08:40
Auto-logout script for linux
#!/bin/sh
#
# linux_idleout.sh [idle time]
#
# Auto-logout process for telnet/ssh sessions
#
IDLE_TIME=180
LOG_FILE=/tmp/idle.out
EXEMPT_PROCESSES="app1|app2|app3|etc" # optional list of apps which can be excluded
@brettfreer
brettfreer / printer_restart.sh
Created May 23, 2016 08:32
Linux bash script to attempt restarting specifed cups print queues
#!/bin/sh
# restart print queues
process()
{
host=$1 queue=$2
ping -c 1 ${host} 2>&1 >/dev/null
status=$?
@brettfreer
brettfreer / convert.py
Last active June 2, 2016 23:49
Convert integer to another base, returning a string
# convert base-10 integer a to base-b, returning a string
def convert(a,b):
add = a % b
if a <= 1:
return str(a)
return str(convert(a//b, b)) + str(add)