Skip to content

Instantly share code, notes, and snippets.

View kzap's full-sized avatar
🏠
Working from home

Andre Marcelo-Tanner kzap

🏠
Working from home
View GitHub Profile
@kzap
kzap / terraform-app.sh
Created June 28, 2016 15:54
Wrapper for terraform that lets you specify an environment and calls an $ENV.tfvars file, uses a $ENV.tfstate file and sets the env variable
#!/bin/bash
#
# terraform-app
#
# This to terraform the servers for the Galleon App
# By storing the date now, we can calculate the duration of provisioning at the
# end of this script.
start_seconds="$(date +%s)"
@kzap
kzap / module.tf
Last active August 8, 2019 21:31
Terraform: How to pass map to module
variable "region" {
default = "tr2"
description = "The region of openstack, for image/flavor/network lookups."
}
variable "image" {
default = {
tr2 = "eee08821-c95a-448f-9292-73908c794661"
tr2-1 = ""
RegionOne = "WRONG VALUE"
@kzap
kzap / instructions.md
Last active April 14, 2016 11:58
How to use python-openstackclient with Dream Compute

Install python-novaclient 2.30.2 pip install -I python-novaclient==2.30.2

Install python-openstackclient pip install python-openstackclient

Create your config file: vi ~/.config/openstack/clouds.yaml

 dreamcompute:
@kzap
kzap / gist:34cc7659877f4692e14a
Created September 29, 2015 10:17
AMA Parsing
1.) FIND: ' {AMANAME}: '
REPLACE WITH: ' {AMANAME}! '
2.) FIND: '\[[0-9]{1,2}:[0-9]{2} PM\] ([^:]+)\: ([^\[]+)'
REPLACE WITH: '**Q (\1) : \2**
'
3.) FIND: '
**
@kzap
kzap / ubuntu-init-script.sh
Last active August 29, 2015 14:24
Ubuntu Build Init Script - configures a Rackspace Cloud server with all the necessary things you might want. Recommended flavor is a minimum 4-8GB as the disk partitions for /tmp and /var/log are 4-8GB
#!/bin/bash -x
# DESCRIPTION: The following UserData script is created to configure a Rackspace Cloud server
# with all the necessary things you might want.
# Recommended flavor is a minimum 4-8GB as the disk partitions for /tmp and /var/log are 4-8GB
#
# Can be used from CLI with nova or supernova
# example:
# supernova lincusa boot --image "Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)" --flavor performance1-8 --key-name {YOUR_KEY} --user-data "ubuntu-init-script.sh" --config-drive true {YOUR_SERVER_NAME}
#
@kzap
kzap / create-lvm.sh
Created June 26, 2015 02:28
LVM Script
echo RTFM >&2;
exit -1;
N=1
yum install -y lvm2
D=$(grep "unknown partition table" /var/log/messages | tail -n 1 | perl -pe 's/.*: ([^:]*): unknown.*/$1/g');
D=/dev/$D
pvcreate $D
vgcreate vg_$N $D
S=$(vgdisplay vg_$N | grep Total | perl -pe 's/[^0-9]+//g')
@kzap
kzap / useful
Last active August 29, 2015 14:23
Useful Unix Commands
#sql-restore-files
for SQL in *.sql.gz; do DB=${SQL/\.sql.gz/}; echo importing $DB; zcat $SQL | mysql -u root --password='{PASSWORD}' $DB; done
#backup all directories and compress them
find ./* -maxdepth 0 -type d -exec echo "Archiving {}" \; -exec tar -cjf "{BACKUP_DIR}/{}-{DATE}.tar.bz2" \;
#find and replace in files recursive without touching files that dont match
find ./ -type f -name '*.php' -print0 | xargs -0 grep 'FIND' -l | xargs sed -i 's/FIND/REPLACE/g'
#apache max clients recommendation
@kzap
kzap / plupload-formsubmit.js
Created May 22, 2015 03:02
plupload upload before submitting form
// Client side form validation
$("form").submit(function(e) {
var uploader = $("#uploader").pluploadQueue();
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind("StateChanged", function() {
@kzap
kzap / fealty_segmentio_tracking.js
Created January 21, 2015 11:28
Code for doing Register Once traits using Segment.com using a Cookie, this mimics the registerOnce function of MixPanel
var _optly = {
updateQueryString: function(key, value, url) {
if (!url) url = window.location.href;
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + "=" + value + '$2$3');
else {
var hash = url.split('#');
@kzap
kzap / gist:e26856adfcc73d8089d7
Created October 27, 2014 09:17
how to recreate a journal
umount /dev/xvdd1 (unmount the partition)
fsck -y /dev/xvdd1 (do an initial file system check)
tune2fs -O ^has_journal /dev/xvdd1 (remove the existing journal)
fsck -y /dev/xvdd1 (do a further file system check)
tune2fs -j /dev/xvdd1 (recreate the journal)