Skip to content

Instantly share code, notes, and snippets.

View josephabrahams's full-sized avatar

Joseph Abrahams josephabrahams

View GitHub Profile
@josephabrahams
josephabrahams / admin.py
Created May 25, 2015 15:50
Prevent permission escalation in Django admin when granting “user change” permissions
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
class RestrictedUserAdmin(UserAdmin):
"""
Prevent permission escalation in when granting “user change” permissions
See: http://stackoverflow.com/a/2298268
"""
@josephabrahams
josephabrahams / ddns.sh
Last active August 29, 2015 14:21
DNSimple Dynamic DNS Shell Script
#!/bin/sh
TOKEN="your-domain-api-token"
DOMAIN_ID="yourdomain.com"
RECORD_ID="12345" # Replace with the Record ID
IP="`curl http://jsonip.com | sed 's/{"ip":"\(.*\)"/\1/g' | sed 's/}//'`"
curl -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-DNSimple-Domain-Token: $TOKEN" \
@josephabrahams
josephabrahams / gh-pages-redirect.html
Created May 9, 2015 20:22
Redirect GitHub Pages URL to CNAME
{% if site.github %}
<script>
if (window.location.hostname.indexOf('{{ site.github.pages_hostname }}') !== -1) {
window.location = '{{ site.github.url }}';
}
</script>
{% endif %}
@josephabrahams
josephabrahams / where-am-i.html
Last active August 29, 2015 14:17
Use browser geolocation and the Google Maps API to auto-select your current country from a dropdown menu.
<!DOCTYPE html>
<title>Where am I?</title>
<h1>Where am I?</h1>
<select id="countries" name="countries">
<option selected>----------</option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@josephabrahams
josephabrahams / shc-trusty-install.sh
Created January 20, 2015 04:10
shc install script
#!/usr/bin/env bash
# Install shc <http://www.datsi.fi.upm.es/~frosal/> on Ubuntu 14.04
# Requires build-essential
if [ ! $(whoami) == "root" ]; then
echo "Please run as root!"
exit 1
fi
# download shc package to be compiled
@josephabrahams
josephabrahams / users.cgi
Created January 18, 2015 18:25
Link to public_html directory of all users
#!/bin/sh
echo "Content-type: text/html\n\n"
echo "<table>"
for user in $(ls -1 /home | egrep -v 'travis|ubuntu'); do
echo "
<tr>
<td valign=\"top\"><img src=\"/icons/folder.gif\" alt=\"[DIR]\"></td>
<td><a href=\"/~${user}/\">${user}</a></td>
</tr>"
done
@josephabrahams
josephabrahams / authorized_keys
Created January 9, 2015 03:25
Block root SSH access
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"foo\" rather than the user \"root\".';echo;sleep 10" ssh-rsa AAAAB3Nza...LiPk== [email protected]
@josephabrahams
josephabrahams / dyndns53.py
Last active August 29, 2015 14:12 — forked from vrypan/dyndns53.py
Route53 Dynamic DNS Updater
#!/usr/bin/env python
# Adapted from http://joseph.is/1HPHiOE
import sys
import inspect
from datetime import datetime
from syslog import syslog, LOG_ERR
from area53 import route53
from boto.route53.exception import DNSServerError
@josephabrahams
josephabrahams / histdel.sh
Created November 3, 2014 22:30
Delete previous line in .bash_history
#!/bin/sh
hist=$(history | tail -1 | awk '{ print $1 }'); history -d $hist; history -d $(expr $hist - 1); unset hist