Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am sudorandom on github.
* I am sudorandom (https://keybase.io/sudorandom) on keybase.
* I have a public key ASDYGS5yzBiuY_yTUAPT_vU-PWXPLIPFraUMgmnyvUvyugo
To claim this, I am signing this object:
@sudorandom
sudorandom / gist:97f25dcaf5e58f949c3c
Created April 16, 2015 10:46
Percent formatting vs format()
> python -m timeit '["%s" % n for n in range(10000)]' -n 100
100 loops, best of 3: 1.91 msec per loop
> python -m timeit '["{}".format(n) for n in range(10000)]' -n 100
100 loops, best of 3: 3.08 msec per loop
@sudorandom
sudorandom / update_tags.py
Created June 20, 2014 15:00
Update Hardware Server Tags
import SoftLayer
from pprint import pprint
client = SoftLayer.Client(username='USERNAME', api_key='API_KEY')
client['Hardware_Server'].setTags('these,are,new,tags', id=12345)
pprint(client['Hardware_Server'].getObject(id=12345, mask='id, hostname, tagReferences'))
@sudorandom
sudorandom / rate-limit.go
Last active August 29, 2015 14:01
Example Rate Limiter in Go
// Based on https://gobyexample.com/rate-limiting
package limiters
import (
"time"
)
func NewRateLimiter(rate time.Duration, burst uint) chan time.Time {
burstyLimiter := make(chan time.Time, burst)
for i := uint(0); i < burst; i++ {
@sudorandom
sudorandom / softlayer-hearbleed.sh
Created April 17, 2014 21:54
SoftLayer Account Heartbleed Testing
#!/bin/sh
# Run Heartbleed for virtual servers
for ip in $(sl vm list --format="json" | jq -r .[].primary_ip)
do
Heartbleed $ip:443 &
done
# Run Heartbleed for hardware servers
for ip in $(sl server list --format="json" | jq -r .[].primary_ip)
@sudorandom
sudorandom / import_stuff.py
Created March 5, 2014 23:56
Multi Multiple Import
PARSERS = [('pkg_resources', 'parse_version'), ('distutils.version', 'StrictVersion')]
def get_parse_fn():
for parser_module, parser in PARSERS:
try:
return getattr(importlib.import_module(parser_module), 'parser')
except ImportError:
pass
raise Exception("Couldn't find a thing to do the thing")
@sudorandom
sudorandom / softlayer_suds.py
Created December 12, 2013 03:27
Very primitive way to use suds with the SoftLayer API through SOAP
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('http://api.service.softlayer.com/soap/v3/')
doctor = ImportDoctor(imp)
client = Client('https://api.softlayer.com/soap/v3/SoftLayer_Account?wsdl', doctor=doctor)
#!/usr/bin/env python
"""
Generates graphs of VLANs and connected hardware/CCIs from data in the
SoftLayer API.
"""
import argparse
import time
try:
from pydot import Dot, Node, Edge
import SoftLayer.API
from pprint import pprint as pp
apiUsername = ''
apiKey = ''
templateId =
client = SoftLayer.API.Client('SoftLayer_Product_Order', None, apiUsername, apiKey)
import SoftLayer
apiUsername = ''
apiKey = ''
package = 46
client = SoftLayer.Client(username=apiUsername, api_key=apiKey)
categoryObjectMask = "mask[isRequired, itemCategory[id, name]]"
configurations = client['Product_Package'].getConfiguration(