Skip to content

Instantly share code, notes, and snippets.

Avatar

Christoph Champ christophchamp

View GitHub Profile
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:

@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"]'`
@christophchamp
christophchamp / pyrax_create_cloud_server.py
Created Jan 16, 2014
This script creates a Cloud Server in your Rackspace account. It then creates an image of that server, and, finally, creates a new server from that saved image.
View pyrax_create_cloud_server.py
# NAME: pyrax_create_cloud_server
# AUTHOR: Christoph Champ
# DESCRIPTION: This script creates a Cloud Server in your Rackspace account.
# It then creates an image of that server, and, finally, creates a new server
# from that saved image.
#
# NOTES: Within each of the created VMs, the generated credentials are in
# master_server.adminPass and clone_server.adminPass. To access the box, use
# master_server.accessIPv4 and clone_server.accessIPv4.
# However, it is _much_ better/safer/wiser to use SSH keypairs.
@christophchamp
christophchamp / curl_cf_extract_archive.sh
Created Nov 25, 2013
Upload a tarball to a Rackspace Cloud Files container and extract its contents.
View curl_cf_extract_archive.sh
#!/bin/bash
# SEE: http://docs.rackspace.com/files/api/v1/cf-devguide/content/Extract_Archive-d1e2338.html
# NOTE: That "Content-Type: " _must_ be blank if you want the API to guess the types!
token=`./curl_authenticate.sh |grep ^X-Auth-Token |cut -d: -f2`
tarball=/home/champ/tmp/test_cf_extract.tar.gz
container=tmp
region=dfw
curl -i -XPUT \
-H "X-Auth-Token: $token" \
-H "Content-Type: " \
@christophchamp
christophchamp / multi-upload_cloud_files
Last active Apr 27, 2019
Upload multiple files to Rackspace Cloud Files using Linux CLI
View multi-upload_cloud_files
$ REGION=dfw; CONTAINER_NAME=sandbox; for i in *.png; do curl -XPUT -T $i -v -H "X-Auth-Token:$MYRAXTOKEN" -H"Content-Type: text/plain" "https://storage101.${REGION}1.clouddrive.com/v1/MossoCloudFS_ffff-ffff-ffff-ffff-ffff/${CONTAINER_NAME}/$i"; done
@christophchamp
christophchamp / rackspace_token
Created Nov 8, 2013
Rackspace authenticated token
View rackspace_token
$ MYRAXTOKEN=`curl -s -XPOST https://identity.api.rackspacecloud.com/v2.0/tokens -d'{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"$MYRAXUSERNAME","apiKey":"'$MYRAXAPIKEY'"}}}' -H"Content-type:application/json" | python -c 'import sys,json;data=json.loads(sys.stdin.read());print data["access"]["token"]["id"]'`
@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')
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 / 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")
@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