Skip to content

Instantly share code, notes, and snippets.

View gwillem's full-sized avatar
💫

Willem de Groot gwillem

💫
View GitHub Profile
@gwillem
gwillem / gist:6751384
Created September 29, 2013 10:44
Debug vagrant-lxc #150
INFO global: Vagrant version: 1.3.3
DEBUG global: Loading core plugin: /opt/vagrant/embedded/gems/gems/vagrant-1.3.3/plugins/provisioners/salt/plugin.rb
INFO manager: Registered plugin: salt
DEBUG global: Loading core plugin: /opt/vagrant/embedded/gems/gems/vagrant-1.3.3/plugins/provisioners/shell/plugin.rb
INFO manager: Registered plugin: shell
DEBUG global: Loading core plugin: /opt/vagrant/embedded/gems/gems/vagrant-1.3.3/plugins/provisioners/ansible/plugin.rb
INFO manager: Registered plugin: ansible
DEBUG global: Loading core plugin: /opt/vagrant/embedded/gems/gems/vagrant-1.3.3/plugins/provisioners/file/plugin.rb
INFO manager: Registered plugin: file
DEBUG global: Loading core plugin: /opt/vagrant/embedded/gems/gems/vagrant-1.3.3/plugins/provisioners/cfengine/plugin.rb
@gwillem
gwillem / gist:7084632
Created October 21, 2013 14:17
Pure SQL to query for MySQL Query Cache Rate
-- run with:
-- boxes -f db | while read i; do echo -n "$i: "; cat qcache-ratio.sql | mysql -h $i | tail -1; done | sort -nk2
use INFORMATION_SCHEMA;
SELECT VARIABLE_VALUE FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'Qcache_hits' INTO @hits;
SELECT SUM(VARIABLE_VALUE) FROM GLOBAL_STATUS WHERE VARIABLE_NAME IN ('Qcache_hits','Com_select') into @total;
select round(@hits / @total * 100);
@gwillem
gwillem / samplebot.py
Created November 23, 2013 12:39
Sample unit test for http://robotgame.org Run with: while (sleep 1); do clear; nosetests -vs bots/samplebot.py; done
import rg
import ast
import game as rgkit_game
import unittest
class Robot:
def act(self, game):
# if we're in the center, stay put
if self.location == rg.CENTER_POINT:
return ['guard']
@gwillem
gwillem / Original
Created January 15, 2014 13:59
Magento url indexer partitioning
SELECT
CONCAT(r.identifier, CASE WHEN ur.inc IS NULL OR `m`.`value` = 1 THEN '' ELSE CONCAT('-', ur.inc) END) AS `request_path`,
`r`.`target_path`,
'3beb48718b9de2b903447079560756bc' AS `guid`,
0 AS `is_system`,
CONCAT(r.identifier, CASE WHEN ur.inc IS NULL OR `m`.`value` = 1 THEN '' ELSE CONCAT('-', ur.inc) END) AS `identifier`,
`r`.`redirect_id` AS `value_id`,
`r`.`store_id`, 1 AS `entity_type`
FROM `enterprise_url_rewrite_redirect` AS `r`
LEFT JOIN `enterprise_url_rewrite` AS `ur` ON ur.identifier = r.identifier AND ur.store_id = r.store_id AND ur.entity_type = 1
@gwillem
gwillem / gist:9089433
Created February 19, 2014 10:25
pivotal unreachable
$ traceroute www.pivotaltracker.com
traceroute to www.pivotaltracker.com (67.214.223.103), 30 hops max, 60 byte packets
1 corona.r139.net (192.168.101.1) 0.151 ms 0.133 ms 0.114 ms
2 nl-asd-dc2-ias-arg37.kpn.net (62.12.4.5) 1.029 ms 1.034 ms 1.025 ms
3 nl-asd-dc2-zsi-sg01-xe-1-3-0.kpn.net (139.156.113.156) 1.480 ms 1.491 ms 1.479 ms
4 nl-asd-dc2-ice-ir01.kpn.net (139.156.222.65) 5.439 ms 5.448 ms 9.392 ms
5 ams-ix.ae1.cr1.ams2.nl.nlayer.net (195.69.145.219) 3.288 ms 3.307 ms 3.276 ms
6 ae3-50g.cr1.ams2.nl.nlayer.net (69.22.139.238) 1.935 ms 15.841 ms 1.986 ms
7 * xe-5-3-0.cr1.lhr1.uk.nlayer.net (69.22.142.94) 9.420 ms 10.844 ms
8 ae0-40g.cr1.lhr2.uk.nlayer.net (69.22.139.117) 9.397 ms 11.892 ms xe-4-0-1.cr1.ewr1.us.nlayer.net (69.22.142.30) 86.096 ms
@gwillem
gwillem / pdns-subdomain-wildcard.md
Last active August 29, 2015 14:03
PowerDNS changed behaviour between 2.9 and 3.3.1

Database entries

domain_id	name	type	content
55392	domain.nl	SOA     nsa.byte.nl. hostmaster.byte.nl. 2003030410
55392	domain.nl	NS      nsa.byte.nl
55392	domain.nl	NS      nsb.byte.nl
55392	domain.nl	NS      nsc.byte.nl

55392	domain.nl      A       46.21.227.210
55392	*.domain.nl    A       46.21.227.210
@gwillem
gwillem / axfr
Last active August 29, 2015 14:03
PowerDNS unexpected NXDomain
$ dig @10.1.1.60 internal -t AXFR
; <<>> DiG 9.7.3 <<>> @10.1.1.60 internal -t AXFR
; (1 server found)
;; global options: +cmd
internal. 600 IN SOA nsa.byte.nl. hostmaster.byte.nl. 2009121500 10800 3600 604800 3600
localhost.internal. 604800 IN A 127.0.0.1
internal. 43200 IN NS nsa.byte.nl.
internal. 43200 IN NS nsb.byte.nl.
internal. 43200 IN NS nsc.byte.nl.
[...]
#!/usr/bin/env python
# split logs in 10 min buckets
# per bucket, tel request time per netblock
#
import json
import sys
@gwillem
gwillem / parse-json-lines.py
Last active August 29, 2015 14:06
Smart JSON line parser (for logs etc)
#!/usr/bin/env python
"""
Usage:
$ grep '"status":"200"' /var/log/nginx/access.log | parse-json-lines status,referer
200 http://www.forestryforum.com/board/index.php?PHPSESSID=4db861b1cb6e82ea8ce8284d16465bfa&thememode=mobile;redirect=http%3A%2F%2Fuwall.tv%2Fredir.php%3Fw%3D800%26url%3Dhttp%3A%2F%2Fwww.kookshopdepepermolen.nl%2Fblog%2Fperfecte-kopje-thee-solis-waterkoker%2F
200 http://eduraft.com/common/login/registeruser.php?redirecturl=http://www.ccjpoz.org/libraries/main/exlink.php?url=www.kookshopdepepermolen.nl/blog/perfecte-kopje-thee-solis-waterkoker/
200 http://cloud.itsc.cuhk.edu.hk/redirection/redirect.aspx?URL=http://open-search.eu/recent.php?lang=at&q=www.kookshopdepepermolen.nl/blog/perfecte-kopje-thee-solis-waterkoker/
@gwillem
gwillem / .gitconfig
Last active August 24, 2016 16:03
My .gitconfig
[alias]
c = commit -m
a = add
aa= !git add -u && git add . && git status
cb = checkout -b
up = !git fetch origin && git rebase origin/master
ir = !git rebase -i origin/master
done = !git fetch && git rebase origin/master && git checkout master && git merge @{-1} && rake && git push
p = pull --rebase --verbose --stat --prune
po = !git push -u origin $(git describe --contains --all HEAD)