Skip to content

Instantly share code, notes, and snippets.

Avatar

Christoph Champ christophchamp

View GitHub Profile
@christophchamp
christophchamp / remove_network_from_server.sh
Created Mar 26, 2014
Remove a Rackspace Cloud Network from a Cloud Server
View remove_network_from_server.sh
# SEE: http://docs.rackspace.com/networks/api/v2/cn-devguide/content/delete_virt_interface_api.html
USERNAME=<REDACTED> # This is your Rackspace account's username
API_KEY=<REDACTED> # This is your Rackspace account's API Key
ACCOUNT=<REDACTED> # This is your Rackspace account number
REGION=dfw # Or, "iad", "ord", "lon", "syd", "hkg"
# Authenticate to obtain your 24-hour valid token:
TOKEN=`curl -s -XPOST https://identity.api.rackspacecloud.com/v2.0/tokens -d'{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'$USERNAME'","apiKey":"'$API_KEY'"}}}' -H"Content-type:application/json" | python -c 'import sys,json;data=json.loads(sys.stdin.read());print data["access"]["token"]["id"]'`
View keybase.md

Keybase proof

I hereby claim:

  • I am christophchamp on github.
  • I am xtof (https://keybase.io/xtof) on keybase.
  • I have a public key whose fingerprint is 8D0A 5408 3B16 7656 6B65 EBAC 26D5 622E 8B70 5E64

To claim this, I am signing this object:

View cors-nginx.conf
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@christophchamp
christophchamp / trove.bash_completion
Created Jun 18, 2015
Bash completion for `trove` (OpenStack DBaaS API)
View trove.bash_completion
_trove()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "--configuration --marker database-list metadata-show secgroup-delete-rule cluster-delete user-revoke-access root-show --users database-delete --limit datastore-show configuration-detach backup-list user-grant-access help configuration-list delete --region --replica_of metadata-update create show -h cluster-show user-create --include-clustered configuration-create restart configuration-default metadata-list --backup --detach-replica-source user-update-attributes --new_password metadata-edit configuration-parameter-show backup-show --new_host flavor-show datastore-list configuration-instances --databases list --description root-enable secgroup-list-rules configuration-patch metadata-create resize-flavor --help cluster-list --remove_configuration --collate user-list datastore-version-list --instance cluster-instances cluster-create database-create secgroup-add-rule --datastore configuration-update configuration-parameter-list secgro
View gist:8e086f73c148510c0fc6
# Steganography trick:
$ cat foo.zip >> bar.gif # "hides" 'foo.zip' inside 'bar.gif'
$ qiv bar.gif # views just fine (note: you can use any image viewer you like here)
$ unzip bar.gif # extracts 'foo.zip'
# Example:
$ echo "HELLO WORLD" > file.txt
$ zip -r foo.zip file.txt
$ cat foo.zip >> bar.gif
$ hexdump -C bar.gif |tail -12
View rename_yt.sh
# Rename:
# FROM: "Introduction___Networking_tutorial_(1_of_13)-qHzZUmP1vvON.mp4"
# TO: "nettut-01_of_13_-_Introduction-qHzZUmP1vvON.mp4"
for f in *.mp4; do \
[[ $f =~ ^(.*)___Networking_tutorial_\(([0-9]+)_of_13\)-(.*)$ ]]
mv "$f" "nettut-$(printf "%02d" ${BASH_REMATCH[2]})_of_13_-_${BASH_REMATCH[1]}-${BASH_REMATCH[3]}"
done
@christophchamp
christophchamp / vet_email.py
Created Apr 22, 2012
Vet a given E-mail address
View vet_email.py
def vet_email(email_address):
"""Vet email addresses. The local part (the part before the '@') must not
exceed 64 characters and the domain part (after the '@') must not
exceed 255 characters. The entire email address length must not exceed
320 characters.
"""
local_part = re.sub(r'^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$', '\\1', email_address)
domain_part = re.sub(r'^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$', '\\2', email_address)
if len(local_part) > 64:
return False
@christophchamp
christophchamp / calc_aa_freq.py
Created Jul 29, 2012
Calculates amino acid codon frequency
View calc_aa_freq.py
# Calculate amino acid codon frequency
from collections import defaultdict
#the first 600 nucleotides from GenBank: AAHX01097212.1
rna = ("tcccccgcagcttcgggaacgtgcgggctcgggagggaggggcctggcgccgggcgcgcg"
"cctgcgccccaccccgccccaccctggcgggtctcgcgcgcccggcccgcctcctgtcaa"
"ccccagcgcggcggtcaggtggtccccagcccttggccccagcctccagcttcctggtcc"
"ctcgggctctgagtcctgtctccggcagatcgcctttctgattgttctcctgcgcagctg"
"gaggtgtatagcccctagccgagctatggtgcctcagcagatgtgaggaggtagtgggtc"
"aggataaacccgcgcactccataataacgtgccagggctcagtgacttgggtctgcatta")
View gist:6419896
# http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html
# https://community.rackspace.com/developers/f/7/t/798
import hmac
from hashlib import sha1
from sys import argv
from time import time
if len(argv) != 5:
print 'Syntax: <method> <url> <seconds> <key>'
print 'Example: GET https://storage101.dfw1.clouddrive.com/v1/' \
@christophchamp
christophchamp / cf_update_content_type_by_ext.py
Created Oct 2, 2013
This simple script will change/update the Content-Type for all objects in our Rackspace Cloud Files container.
View cf_update_content_type_by_ext.py
#!/usr/bin/python
import os
import pyrax
YOUR_USERNAME=""
YOUR_API_KEY=""
YOUR_REGION="" # E.g., "ORD", "DFW", etc.
YOUR_CONTAINER_NAME=""
#pyrax.set_setting('identity_type', 'rackspace')