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 / 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
@thomaswitt
thomaswitt / crawl_sipgate.rb
Last active August 29, 2015 13:56
As the sipgate guys appearently don't have an API to fetch all users and SIP credentials for provisioning, you have to crawl their web-site. Ugly, but it works. The crawl may take quite some time, so you're better off caching it. If there's somebody listening from @sipgate: please provide a clean API …
require 'mechanize'
m = Mechanize.new
users = []
rooms = []
login = m.get('https://secure.live.sipgate.de/settings/setup')
login.form do |f|
f.username = 'name@company.com'
f.password = 'secret_password'
@thomaswitt
thomaswitt / create_route53_domains.rb
Last active August 29, 2015 13:57
Mass Create Route 53 Domains at AWS
require 'aws-sdk'
AWS.config({
access_key_id: ENV['AWSAccessKeyId'].strip,
secret_access_key: ENV['AWSSecretKey'].strip,
region: 'eu-west-1',
use_ssl: true,
})
r53 = AWS::Route53.new
# upload-cert www_myserver_com.crt aws_profile_name SSL123_SecondaryCA.crt SSL123_PrimaryCA.crt
function upload-cert() {
NAME=`echo "$1" | cut -d'.' -f1`
END=`openssl x509 -in $NAME.crt -noout -enddate | cut -f2 -d= | while read x; do date -j -f '%b %d %T %Y %Z' "$x" '+%Y-%m-%d'; done`
cat $3 $4 $5 >certchain.pem
aws --profile $2 iam upload-server-certificate --server-certificate-name ${NAME}-${END} \
--certificate-body file://$NAME.crt --private-key file://$NAME.key.rsa --certificate-chain file://certchain.pem
}
@thomaswitt
thomaswitt / install_ruby_rbenv_sh
Last active October 11, 2015 13:37
Getting Umlauts/UTF-8 in irb or rails/console on the mac using rbenv
RUBY_VERSION="1.9.3-p362"
###Use this for global readline for later reuse
# OPT_DIR=/usr/local/ruby-opt/
OPT_DIR=${HOME}/.rbenv/versions/${RUBY_VERSION}/
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
cd ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git
cd /tmp
@thomaswitt
thomaswitt / sms.rb
Created November 3, 2012 09:50
How to send an SMS via Sipgate API and Ruby
require 'xmlrpc/client'
class SMS
def self.deliver(phonenumber, text)
user = Rack::Utils.escape(SIPGATE_USER_NAME)
url = "https://#{user}:#{SIPGATE_PASSWORD}@api.sipgate.net/RPC2"
client = XMLRPC::Client.new2(url)
client.call('samurai.ClientIdentify', {'ClientName' => 'Ruby-Client'} )
number = strip_phonenumber(phonenumber)
@thomaswitt
thomaswitt / bydesign_printer.rb
Created January 10, 2013 16:14
SAP SaaS-Solution Business ByDesign has a Print API, which allows you to spool print jobs to be fetched remotely over the Web. Decoding this API is one of the biggest mess I've ever seen. Anyway, finally I got it right and now I've got a nice ruby printer spooler which you can put in your crontab. It polls the print queue of ByDesign, retrieves …
#!/usr/bin/env ruby
require 'rubygems'
require 'savon'
require 'tempfile'
require 'base64'
USER = 'PRT_001'
PASS = 'YOUR_PASSWORD_GOES_HERE'
SAP_BASE_URL = 'https://my012345.sapbydesign.com'
@thomaswitt
thomaswitt / list_aws_iam_users.rb
Created October 5, 2013 11:23
List all AWS IAM Users of an account
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
require 'highline/import'
def get_aws_account_data(iam)
begin
iam = iam.client.get_user
id, user = iam[:user][:arn].match('^arn:aws:iam::([0-9]{12}):(.*)$').captures
@thomaswitt
thomaswitt / rename_pem_certs
Created November 5, 2013 12:23
Rename PEM certificates to CN and date
#!/usr/bin/ruby
require 'openssl'
require 'date'
Dir.chdir('/Users/thomas/Desktop/certs')
Dir.glob('./*.pem') do |file|
next if file =~ /.k.pem$/
puts file
@thomaswitt
thomaswitt / oracle_login.sql
Created November 6, 2013 09:50
Oracle Login File
SET termout OFF
ALTER SESSION SET NLS_DATE_FORMAT = 'dd.mm.yyyy HH24:mi:ss';
SET termout ON
SET sqlprompt "_USER'@'_CONNECT_IDENTIFIER _PRIVILEGE> "
set pagesize 50000
SET linesize 190