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 / omnigraffle_export_all_files.scpt
Created November 6, 2013 10:16
Export all OmniGraffle Canvasses
tell application "OmniGraffle Professional 5"
--Setup export options
set current export settings's area type to selected graphics
set current export settings's draws background to false
set current export settings's export scale to 1
set current export settings's include border to false
set current export settings's resolution to 2.0
--Retrieve the desired output export path
set myFolder to POSIX path of (choose folder)
@thomaswitt
thomaswitt / applescript_string_helper
Created November 6, 2013 10:18
Apple Script String Helpers
on replace(sourcetext, search, replacement)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search
set the textItemList to every text item of the sourcetext
set AppleScript's text item delimiters to the replacement
set the output to the textItemList as string
set AppleScript's text item delimiters to oldDelim
return output
end replace
@thomaswitt
thomaswitt / check_oracle.rb
Created November 6, 2013 10:29
Check Oracle One Liner Ruby
ruby -r oci8 -e "OCI8.new('xms01','R1launch','//my.cool.host:1521/ORACM.BLA').exec('select sysdate from dual') do |r| puts r.join(','); end"
@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 / 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 / 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_aws_eu_ip_ranges.sh
Last active October 21, 2016 13:28
Get IP ranges of AWS in Europe
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.region=="eu-west-1" or .region == "eu-central-1" or .region == "GLOBAL") | .ip_prefix' | sort -u | sort -n