Skip to content

Instantly share code, notes, and snippets.

@timhughes
timhughes / bootstrap_cmdline.py
Created June 15, 2020 15:23 — forked from elmotec/bootstrap_cmdline.py
Minimal python program with logging and argparse.
#!/usr/bin/env python
# encoding: utf-8
"""Minimal python commad line."""
import sys
import argparse
import logging
@timhughes
timhughes / Ick.java
Created September 10, 2018 15:24 — forked from phlash/Ick.java
Self-executing single-file Java programs...
#!/bin/sh
# This self-executing Java program uses the following /embedded shell script/ to compile & execute itself..
# magic constant holding length of script
SKIP=26
# parse our name..
FILE=`basename $0 .java`
# get some working space, clean up old crud
#!/bin/bash
# SPDX-License-Identifier: MIT
## Copyright (C) 2009 Przemyslaw Pawelczyk <przemoc@gmail.com>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
#
# Lockable script boilerplate
@timhughes
timhughes / gist:b40dbd4197b67fcdbc24af903f271e75
Created April 5, 2018 15:01 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
@timhughes
timhughes / dell_warranty.py
Created August 18, 2017 17:37 — forked from teroka/dell_warranty.py
Dell API: Warranty Information
#!/usr/bin/env python
# Quick script to check your Dell asset's warranty status
# Just drop your service tag as parameters for the script and go.
import sys
import requests
APIKEY = 'd676cf6e1e0ceb8fd14e8cb69acd812d'
URL = 'https://api.dell.com/support/v2/assetinfo/warranty/tags.json?svctags={0}&apikey=' + APIKEY
@timhughes
timhughes / .golang-example-gitlab-ci.yml
Created July 15, 2017 23:30 — forked from mikeatlas/.golang-example-gitlab-ci.yml
Example Go GitLab CI setup (no root/sudo required)
# See docs/examples
# http://doc.gitlab.com/ce/ci/quick_start/README.html
# http://doc.gitlab.com/ce/ci/yaml/README.html
# GitLab CI template for Go tests. Note this installs
# a new working copy of Go in a non-standard path such
# that sudo/root is not needed for the install stage.
# note that this particular install-environment stage
# is overly verbose in order to debug anything tricky
@timhughes
timhughes / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
from urllib.parse import urlparse
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase
class ViewTestMixin(object):
"""the name of the url to access the view. If you provide url, then it will take precedence."""
view_urlname = None
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "your@email.to.match" ]
import simplejson as json
import lxml
class objectJSONEncoder(json.JSONEncoder):
"""A specialized JSON encoder that can handle simple lxml objectify types
>>> from lxml import objectify
>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
>>> objectJSONEncoder().encode(obj)
'{"price": 1.5, "author": "W. Shakespeare"}'
"""