Skip to content

Instantly share code, notes, and snippets.

View christophchamp's full-sized avatar

Christoph Champ christophchamp

View GitHub Profile
@christophchamp
christophchamp / aws-cloudformation-lamp-stack.json
Created May 10, 2016 23:27
AWS CloudFormation single instance LAMP stack template
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template LAMP_Single_Instance: Create a LAMP stack using a single EC2 instance and a local MySQL database for storage. This template demonstrates using the AWS CloudFormation bootstrap scripts to install the packages and files necessary to deploy the Apache web server, PHP and MySQL at instance launch time. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName",
@christophchamp
christophchamp / calc_aa_freq.py
Created July 29, 2012 22:44
Calculates amino acid codon frequency
# 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 / gist:8e086f73c148510c0fc6
Last active October 31, 2021 17:34
Steganography trick
# 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

Find lowercase letter frequencies in English words

  • Issues with the following Linux/Bash one-liner:
    • It is ugly
    • It has trailing tabs (\t)
  • Challenge:
    • Come up with a more elegant and concise Linux one-liner.
  • Rules:
    • You must only use Linux and/or Bash and it must be able to be run from the Linux CLI as a one-liner.
@christophchamp
christophchamp / multi-upload_cloud_files
Last active April 27, 2019 13:24
Upload multiple files to Rackspace Cloud Files using Linux CLI
$ 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
#!/usr/bin/env python
import yaml
import json
"""
DESCRIPTION: The goal of this script is to find the outermost/top-level key in
the following YAML document, given only the sub-group/sub-key name.
EXAMPLE: Say you only know the sub-group "mars" or "pluto", and you want to
know which top-level key they belong to (i.e., "apps" and "services",
respectively). The find_category() function will do just that, albeit, very
#!/usr/bin/env python
from random import randint
RANGE = 1000000
def random_guess(RANGE):
wins = []
for _ in range(0, RANGE):
guess = randint(0, 1)
outcome = randint(0, 1)
#!/bin/bash
#
# description: Apache Tomcat init script
# processname: tomcat
# chkconfig: 234 20 80
#
#
# Copyright (C) 2014 Miglen Evlogiev
#
# This program is free software: you can redistribute it and/or modify it under
@christophchamp
christophchamp / Vagrantfile
Created June 28, 2016 23:35
Spin up multiple Vagrant VMs
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$common_script = <<COMMON_SCRIPT
# Set verbose
set -v
# Set exit on error
@christophchamp
christophchamp / pyrax_create_cloud_server.py
Created January 16, 2014 06:53
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.
# 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.