Skip to content

Instantly share code, notes, and snippets.

@tgross
tgross / shuffle_select.py
Created February 20, 2012 01:55
Rednsake Trivia: Pick N Random of M without Replacement
import random
def fisher_yates(n, m):
'''
Because
return random.sample(m,n)
would be boring.
'''
scratch = range(len(m))
stop = len(scratch) - n
@tgross
tgross / swallow.py
Created February 21, 2012 02:09
Redsnake trivia: speed of a swallow
import math
import string
from time import struct_time
import json
from requests import request
def get_geocoord(pt):
'''
Take the Web2.0y approach and get Google to do all the
heap profile: 11: 37296 [6894: 99824424] @ heap/1048576
1: 32768 [1: 32768] @ 0x53e86b 0x53f441 0x541f8a 0x54815c 0x7cbe5f 0x7cb72b 0x7d935a 0x7d8302 0x7dfa7c 0x7dc325 0x7e36b1 0x7e39c3 0x6ec6b4 0x6edaf0 0x6eeeb2 0x6eb222 0x459be1
# 0x53e86a regexp.(*bitState).reset+0x18a /usr/local/go/src/regexp/backtrack.go:86
# 0x53f440 regexp.(*machine).backtrack+0xa0 /usr/local/go/src/regexp/backtrack.go:321
# 0x541f89 regexp.(*Regexp).doExecute+0x339 /usr/local/go/src/regexp/exec.go:439
# 0x54815b regexp.(*Regexp).FindStringSubmatch+0xeb /usr/local/go/src/regexp/regexp.go:919
# 0x7cbe5e internal/pprof/profile.parseMappingEntry+0x5e /usr/local/go/src/internal/pprof/profile/legacy_profile.go:1084
# 0x7cb72a internal/pprof/profile.(*Profile).ParseMemoryMap+0x1ca /usr/local/go/src/internal/pprof/profile/legacy_profile.go:1048
# 0x7d9359 runtime/pprof/internal/protopprof.addMappings+0xa9 /usr/local/go/src/runtime/
pex: Installed VendorImporter(root='/<redacted>/build/example/.bootstrap', importables=(_Importable(module='pkg_resources', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'),))
pex: Installed VendorImporter(root='/<redacted>/build/example/.bootstrap', importables=(_Importable(module='archiver', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='base', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='bootstrap', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='common', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='compatibility', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='compiler', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='crawler', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='environment', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='executor', is_pkg=False, path='pex', prefix='_pex'), _Importable(module='fetcher', is_pkg=False, path='pex', prefix='_pex'),
@tgross
tgross / packer.json
Last active May 13, 2019 15:54
panic with nil map
==> amazon-ebs: Stopping the source instance...
amazon-ebs: Stopping instance
==> amazon-ebs: Waiting for the instance to stop...
==> amazon-ebs: Creating AMI OAsX7vH from instance i-REDACTED
amazon-ebs: AMI: ami-REDACTED
==> amazon-ebs: Waiting for AMI to become ready...
==> amazon-ebs: Deregistering the AMI because cancellation, error or it was temporary (encrypt_boot was set)...
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Stopping the source instance...
amazon-ebs: Stopping instance
==> amazon-ebs: Waiting for the instance to stop...
==> amazon-ebs: Creating AMI n0iBIcp from instance i-0e5a3291cc68cd9b1
amazon-ebs: AMI: ami-07edc511e26111c15
==> amazon-ebs: Waiting for AMI to become ready...
==> amazon-ebs: Copying AMI (ami-07edc511e26111c15) to other regions...
amazon-ebs: Copying to: us-east-1
amazon-ebs: Waiting for all copies to complete...
==> amazon-ebs: 1 error(s) occurred:
[vagrant@test-centos build]$ sudo ~/execsnoop
PCOMM PID PPID RET ARGS
ps 2202 1312 0 /usr/bin/ps afx
nomad 2207 1312 0 /usr/bin/nomad job run countdash.hcl
getconf 2212 2207 0 /usr/bin/getconf CLK_TCK
runc 2216 632 0 /usr/bin/runc --version
docker-init 2221 632 0 /usr/bin/docker-init --version
runc 2222 632 0 /usr/bin/runc --version
docker-init 2227 632 0 /usr/bin/docker-init --version
ps 2228 1312 0 /usr/bin/ps afx
@tgross
tgross / primes.go
Created November 22, 2019 16:14
Dummy application for testing Nomad batch workloads
package main
import (
"fmt"
"os"
"strconv"
)
// return list of primes less than N
func sieveOfEratosthenes(N int) (primes []int) {
job "countdash" {
datacenters = ["dc1"]
group "api" {
network {
mode = "bridge"
}
service {
name = "count-api"
job "countdash" {
datacenters = ["dc1"]
group "api" {
network {
mode = "bridge"
}
service {
name = "count-api"