Skip to content

Instantly share code, notes, and snippets.

View jbarber's full-sized avatar

Jonathan Barber jbarber

View GitHub Profile
@jbarber
jbarber / chrome-reload
Last active June 30, 2018 17:38
Reload Chrome tabs from the command line with Perl
#!/usr/bin/env perl
=head1 NAME
chrome-reload
=head1 SYNOPSIS
chrome-reload 1
@jbarber
jbarber / monitor-http-traffic.stp
Created September 27, 2013 15:44
Systemtap script for reporting the PID and command line of any program connecting to via IPv4 or IPv6 to port 80.
sudo stap -v - <<'EOF'
probe tcp.sendmsg {
# 2 = AF_INET
# 10 = AF_INET6
if ((family == 2 || family == 10) && tcpmib_remote_port($sk) == 80) {
printf("%i %s\n", pid(), cmdline_str())
}
}
EOF
@jbarber
jbarber / centos6-img.sh
Last active December 31, 2015 05:39
Create a minimal Centos6 image for Docker, must be run on a Centos6 OS. Copied from https://github.com/dotcloud/docker/issues/290#issuecomment-15738849
#!/bin/bash
MIRROR_URL="http://centos.netnitco.net/6.4/os/x86_64/"
MIRROR_URL_UPDATES="http://centos.netnitco.net/6.4/updates/x86_64/"
yum install -y febootstrap xz
febootstrap -i bash -i coreutils -i tar -i bzip2 -i gzip -i vim-minimal -i wget -i patch -i diffutils -i iproute -i yum centos centos64 $MIRROR_URL -u $MIRROR_URL_UPDATES
touch centos64/etc/resolv.conf
touch centos64/sbin/init
@jbarber
jbarber / redmine.pl
Created December 18, 2013 17:01
Simple example of hacking the redmine issue tracker via it's API
#!/usr/bin/env perl
# This script provides a basis for futzing about with redmine via it's API
# You will also need to refer to TFM at:
# http://www.redmine.org/projects/redmine/wiki/Rest_Issues
# to fully learn how to manipulate the system.
# It's my impression from the Redmine bugtrackker that there seem to be plenty
# of bugs in the Redmine API implimentation, and that the implimentation
# doesn't cover everything you can do via the GUI.
@jbarber
jbarber / get-yum-url.py
Created January 27, 2014 09:19
Show the URLs that YUM would get RPMs from
#!/usr/bin/env python
import os
import sys
import yum
yb = yum.YumBase()
yb.setCacheDir()
#pkgs = yb.pkgSack.searchNames(["perl"])
pkgs = yb.pkgSack.searchNames(sys.argv[1:])
@jbarber
jbarber / moose.pl
Last active August 29, 2015 13:58
Moose meta-example
use strict;
use warnings;
use Moose;
my $meta = Moose::Meta::Class->create_anon_class();
$meta->add_attribute("foo" => (is => "rw", isa => "Int"));
$meta->make_immutable;
my $object = $meta->new_object(foo => 2);
@jbarber
jbarber / timer.go
Created July 7, 2014 21:54
Go routine on a changable timer
package main
/*
Example of creating go routine with time based channel - this time can be
adjusted by the parent, so it can postpone (or bring forwards) whatever the
child should do. This could be useful for creating a polling mechanism which
you occasionally want to run sooner.
The parent creates the channel and passes it to the go routine to wait for 10
seconds. This channel is used to communicate how long the child should wait
@jbarber
jbarber / xml-parse.go
Created July 9, 2014 14:21
Example of parsing XML in Go, including extracting attributes
package main
import (
"encoding/xml"
"log"
"strings"
)
type document struct {
Title string `xml:"title"`
@jbarber
jbarber / limiter.go
Last active August 29, 2015 14:03
Function that returns updated values once every time period, no matter how often it is called
package main
import (
"fmt"
"time"
)
// This function returns a function that returns the current time. The current
// time is only updated when the returned function is called, and at most once
// during every period
@jbarber
jbarber / shibboleth-login.clj
Created October 13, 2014 12:13
Shibboleth example login
(comment (defproject otrs "0.1.0-SNAPSHOT"
:description "Example of Shibboleth login to OTRS with htmlunit"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[net.sourceforge.htmlunit/htmlunit "2.15"]]))
(ns otrs.core
(:import (com.gargoylesoftware.htmlunit WebClient)))