Skip to content

Instantly share code, notes, and snippets.

View josephabrahams's full-sized avatar

Joseph Abrahams josephabrahams

View GitHub Profile
@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 / 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
// 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 / 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>
@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 / 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 / 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 / admin.py
Created May 31, 2015 17:55
Limit number of Django model instances
from django.contrib import admin
from example.models import Example
class ExampleAdmin(admin.ModelAdmin):
"""
Don't allow addition of more than one model instance in Django admin
See: http://stackoverflow.com/a/12469482
"""
def has_add_permission(self, request):

Docker on Mac OS X

These are my notes based on my experience with using Docker on Mac OS X.

Assumptions

If these assumptions are not true for you, then this document may not be for you.

I assume you have these installed:

  • recent-ish Mac OS X
@josephabrahams
josephabrahams / circle.yml
Created October 26, 2015 18:57
Use .nvmrc with CircleCI
machine:
post:
- nvm use && nvm alias default $(nvm current)