Skip to content

Instantly share code, notes, and snippets.

View thomaswitt's full-sized avatar
💭
Investing pre-seed/seed into tech startups via @ExpediteVentures

Thomas Witt thomaswitt

💭
Investing pre-seed/seed into tech startups via @ExpediteVentures
View GitHub Profile
@thomaswitt
thomaswitt / apache_get_transfer_volume.sh
Created November 6, 2013 10:34
Get Apache Transfer Volume from access_log
#!/bin/sh
echo "Statistik für Logfile $1"
awk '{sum+=$10} END {printf "%.2f GByte Transfervolumen\n",sum/1073741824}' $1
echo "$(wc -l < "$1" | sed 's/[^[:digit:]]//g') Requests"
#echo "$(grep -ivE '(.js|.css|.pdf|.gif|.jpg|.jpeg|.png|.tif|.tiff|.mp3|.mp4a|.aac|.mpg|.mp4|.mov|.flv|.swf|.zip|.gz|.rpm|.tgz|.doc|.xls|.ppt|.wmv|.avi|.wav|.ico|.exe)' "$1" | wc -l | sed 's/[^[:digit:]]//g') Requests auf Assets"
@thomaswitt
thomaswitt / parse_apachelog_stats.sh
Created November 6, 2013 10:35
Parse Apache Access Log for stats
#!/bin/sh
# Or try awk '{sum+=$10} END {print sum/1048576}'
#export LC_ALL=C
#env LC_ALL=en_US sort
unset LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME
bytes_in_mb=1048576
bytes_in_gb=1073741824
@thomaswitt
thomaswitt / list_all_google_apps_users.rb
Created November 14, 2013 14:54
Access Google Apps Admin SDK Directory API and retrieve all users from Google Apps
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'google/api_client'
require 'active_support/core_ext/hash'
# 1. Go to Google Cloud Console (https://cloud.google.com/console)
# 2. Create Service Account with P12 File
# 3. Enable the Admin SDK in APIs.
@thomaswitt
thomaswitt / elb-set-secure-policy.sh
Last active April 7, 2017 08:51
Sets a secure Cipher Suite Policy on Amazon Web Services (AWS) Elastic Load Balancer (ELB). Requires the Elastic Load Balancing Command Line Interface Tools from AWS.
#!/bin/bash
# bin/elb-describe-lbs | awk '{print $2}' | xargs -n1 elb-set-secure-policy.sh
ELB=$1
echo "Setting Policy on Load Balancer $1"
bin/elb-create-lb-policy $ELB \
--policy-type SSLNegotiationPolicyType \
--policy-name elb-secure-ssl \
@thomaswitt
thomaswitt / ruby_one_line_replace.sh
Created January 6, 2014 14:48
Ruby One Line Replace
find . -name "*.extension" -print0 | xargs -0 ruby -i -p -e '$_.gsub! %r{(THIS)}, "THAT was \\1"'
@thomaswitt
thomaswitt / gitgc-oneliner
Last active February 9, 2023 15:21
Clean Up all git directories
find . -maxdepth 1 -name "*.git" -type d -exec git gc "{}" ";"
@thomaswitt
thomaswitt / meraki_controller.rb
Last active January 4, 2016 02:29
Rails Controller for the Meraki Presence API. You need to generate a models for saving these into the database via: rails generate model presence ap_mac:string client_mac:string last_seen:datetime rssi:integer
# 1. Generate a model Presence before:
# rails generate model presence ap_mac:string client_mac:string last_seen:datetime rssi:integer
#
# 2. Add a route:
# match 'meraki', :to => 'meraki#presenceapi', :as => :meraki
#
# 3. Test this controller via:
# curl -d data="{\"secret\":\"foobar\",\"probing\":[{\"ap_mac\":\"00:aa:bb:cc:dd:ee\",\"client_mac\":\"ff:ee:dd:cc:bb:aa\",\"last_seen\":\"Wed Jan 22 08:34:02.409 UTC 2014\",\"rssi\":\"16\"},{\"ap_mac\":\"11:22:33:44:55:66\",\"client_mac\":\"99:88:77:66:55:44\",\"last_seen\":\"Wed Jan 22 08:34:06.409 UTC 2014\",\"rssi\":\"29\"}]}" https://localhost:3000/meraki
#
# 4. Point Meraki to https://my.app.name/presenceapi
@thomaswitt
thomaswitt / crypt_helper.rb
Last active January 4, 2016 06:09
Crypt Helper
require 'rubygems'
require 'openssl'
require 'digest/sha2'
require 'base64'
class CryptHelper
def self.generate_rsa_key(passphrase, bits = 4096)
cipher = OpenSSL::Cipher::AES256.new(:CBC)
rsa_key = OpenSSL::PKey::RSA.generate(bits)
@thomaswitt
thomaswitt / deploy_to_opsworks.rake
Last active April 25, 2016 02:59
Deploy to opsworks via rake
# Put this into lib/tasks
require 'rubygems'
require 'bundler'
require 'aws-sdk'
require 'socket'
require 'os'
if Rails.env.development?
@thomaswitt
thomaswitt / get_pingdom_probe_servers.sh
Created February 11, 2014 09:33
Get all pingdom probe servers by IP, useful for adding to an EC2 security group
wget -q -O - \
https://www.pingdom.com/rss/probe_servers.xml | \
perl -nle 'print $1 if /IP: (([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]));/' | \
sort -n -t . -k1,1 -k2,2 -k3,3 -k4,4