Skip to content

Instantly share code, notes, and snippets.

View schwuk's full-sized avatar

David Murphy schwuk

View GitHub Profile
@schwuk
schwuk / cliploc
Created February 3, 2023 14:12
Count lines of code in a folder and copy to clipboard
#!/usr/bin/env bash
cloc . --quiet --hide-rate --csv | head -n -1 | tail -n +2 | awk -F',' '{ print $2","$5 }' | sort | awk -F',' '{ print $2}' | xclip -sel clip
@schwuk
schwuk / gitpull
Last active August 28, 2018 09:22
Simple shell script to update all git repositories in a directory. Requires the `lockfile` utility from Procmail.
#!/bin/sh
# Updates git repositories
LOCKFILE=/tmp/git.lock
lockfile -r 0 $LOCKFILE || exit 1
GIT=`which git`
@schwuk
schwuk / countries.sql
Last active August 29, 2015 14:07
County names and two-letter codes
CREATE TABLE countries (id VARCHAR(2) NOT NULL, name VARCHAR(64) NOT NULL, PRIMARY KEY(id));
INSERT INTO "countries" ("id", "name") VALUES ('AF', 'Afghanistan');
INSERT INTO "countries" ("id", "name") VALUES ('AL', 'Albania');
INSERT INTO "countries" ("id", "name") VALUES ('DZ', 'Algeria');
INSERT INTO "countries" ("id", "name") VALUES ('AS', 'American Samoa');
INSERT INTO "countries" ("id", "name") VALUES ('AD', 'Andorra');
INSERT INTO "countries" ("id", "name") VALUES ('AO', 'Angola');
INSERT INTO "countries" ("id", "name") VALUES ('AI', 'Anguilla');
INSERT INTO "countries" ("id", "name") VALUES ('AQ', 'Antarctica');

Keybase proof

I hereby claim:

  • I am schwuk on github.
  • I am schwuk (https://keybase.io/schwuk) on keybase.
  • I have a public key whose fingerprint is B278 852C FF3C 219C 204E 4E16 D072 DD92 3BBF C414

To claim this, I am signing this object:

@schwuk
schwuk / describe_csv.py
Created February 25, 2014 09:05
A quick'n'dirty script to describe a CSV file - outputs the header for each column and the maximum width of that column.
#! /usr/bin/env python
import csv
import sys
with open(sys.argv[1], 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
header = reader.next()
columns = []
for row in reader:
for i, v in enumerate(row):
_length = len(v)
@schwuk
schwuk / Vagrantfile
Created January 30, 2014 14:58
Vagrantfile that installs the latest version of Puppet into the official Ubuntu 12.04 Vagrant image. Also opens up port 5000 (default Foreman port).
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$script = <<SCRIPT
INITIAL_PROVISION=/var/cache/initial_provision
DISTRIB_CODENAME=$(lsb_release --codename --short)
DEB="puppetlabs-release-${DISTRIB_CODENAME}.deb"
@schwuk
schwuk / post-receive
Created September 10, 2013 16:02
Git post-receive hook for deploying/updating applications (using gitolite, make, and upstart).
#!/bin/sh
APP_NAME=foo
mkdir -p /srv/$APP_NAME
GIT_WORK_TREE=/srv/$APP_NAMEs GIT_DIR=/var/lib/git/repositories/$APP_NAME.git git reset --hard
sudo /bin/chown -R $APP_NAME:$APP_NAME /srv/$APP_NAME
sudo /bin/chmod -R g+w /srv/$APP_NAME
sudo /sbin/status $APP_NAME | grep "^$APP_NAME start" > /dev/null 2>&1
@schwuk
schwuk / plexmediaserver
Created August 29, 2013 10:24
UFW Application Profile for Plex Media Server
[plexmediaserver]
title=Plex Media Server
description=The Plex Media Server is smart software that makes playing Movies, TV Shows and other media on your computer simple
ports=32400/tcp|1900/udp|32469/udp|5353/udp
@schwuk
schwuk / flatpage_mixin.py
Last active September 23, 2017 20:44
Django class-based view(CBV) mixin to include flatpage content in the context.
from django.contrib.flatpages.models import FlatPage
class FlatPageMixin(object):
"""
Retrieves the FlatPage object for the specified url, and includes it in the
context.
If no url is specified, request.path is used.
"""
@schwuk
schwuk / gist:4168007
Created November 29, 2012 10:15
Hubot IRC + Jenkins configuration
HUBOT_IRC_NICK=hubot_test
HUBOT_IRC_PASSWORD=[redacted]
HUBOT_IRC_PORT=[redacted]
HUBOT_IRC_ROOMS=[redacted]
HUBOT_IRC_SERVER=[redacted]
HUBOT_IRC_SERVER_FAKE_SSL=yes
HUBOT_IRC_USESSL=yes
HUBOT_JENKINS_AUTH=[redacted]
HUBOT_JENKINS_URL=[redacted]
HUBOT_PORT=6697