Skip to content

Instantly share code, notes, and snippets.


Christoph Champ christophchamp

View GitHub Profile

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.
#!/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)
# 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 / Vagrantfile
Created June 28, 2016 23:35
Spin up multiple Vagrant VMs
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
$common_script = <<COMMON_SCRIPT
# Set verbose
set -v
# Set exit on error
christophchamp / aws-cloudformation-lamp-stack.json
Created May 10, 2016 23:27
AWS CloudFormation single instance LAMP stack template
View aws-cloudformation-lamp-stack.json
"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 / gist:8e086f73c148510c0fc6
Last active October 31, 2021 17:34
Steganography trick
View gist:8e086f73c148510c0fc6
# Steganography trick:
$ cat >> bar.gif # "hides" '' inside 'bar.gif'
$ qiv bar.gif # views just fine (note: you can use any image viewer you like here)
$ unzip bar.gif # extracts ''
# Example:
$ echo "HELLO WORLD" > file.txt
$ zip -r file.txt
$ cat >> bar.gif
$ hexdump -C bar.gif |tail -12
# 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]}"
christophchamp / trove.bash_completion
Created June 18, 2015 19:56
Bash completion for `trove` (OpenStack DBaaS API)
View trove.bash_completion
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 cors-nginx.conf
# Wide-open CORS config for nginx
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';