Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Barnaby Gray barnybug

🏠
Working from home
View GitHub Profile
@barnybug
barnybug / k8s-tips.md
Created Jul 17, 2018
kubernetes tips
View k8s-tips.md

List pods ordered by node:

kubectl get po -o=wide --sort-by=.spec.nodeName

List nodes by instance type / zone:

kubectl get no -Lbeta.kubernetes.io/instance-type -Lfailure-domain.beta.kubernetes.io/zone
@barnybug
barnybug / docker-compose.yml
Created Nov 21, 2017
Docker compose for a Docker-in-docker gitlab runners setup
View docker-compose.yml
# Docker-in-Docker Gitlab runners setup taken from:
# https://medium.com/@tonywooster/docker-in-docker-in-gitlab-runners-220caeb708ca
dind:
restart: always
privileged: true
volumes:
- /var/lib/docker
image: docker:17.09.0-ce-dind
command:
- --storage-driver=overlay2
View gist:3c58c058c687c61c51107e6756f736a5
{
_index: "events_201701160824",
_type: "event",
_id: "AV6VlZ-AHWGhPQNyr0dK",
_score: 6.8922844,
_source: {
event: "portal.impressions",
sid: "dc7e7cec-800a-4454-b89e-2d42dfe0097a",
pid: "a03f0281-c9e3-4ba2-b5d0-92af0554af54",
total_count: 1,
View main.nim
import macros
import strutils
proc compile(input: string, setup: string): NimNode {.compiletime.} =
var caseBody = newNimNode(nnkCaseStmt)
caseBody.add parseExpr("pc")
var pc = 0
template addCase(text): typed =
var branch = newNimNode(nnkOfBranch)
View gist:ad0f224d015f62111e50cfb0bef6aeb1
~ % mosquitto_sub -h iot.eclipse.org -t 'cheerlightsRGB'
#000000
~ % mosquitto_sub -h iot.eclipse.org -t 'cheerlights'
oldlace
View gist:b37b661384d41c98c843aa7111ec9c45
~ % mosquitto_sub -h iot.eclipse.org -t 'cheerlightsRGB'
#000000
^C⏎ ~ % mosquitto_sub -h iot.eclipse.org -t 'cheerlights'
oldlace
^C⏎
View tree2code.py
def get_code(tree, feature_names, class_names):
left = tree.tree_.children_left
right = tree.tree_.children_right
threshold = tree.tree_.threshold
features = [feature_names[i] for i in tree.tree_.feature]
value = tree.tree_.value
def recurse(left, right, threshold, features, node, indent):
if threshold[node] != -2:
print "%sif %s <= %s:" % (indent, features[node], threshold[node])
View einstein.pl
% Prolog solution to:
% http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/04/einsteins-election-riddle-are-you-in-the-two-per-cent-that-can-solve-it
left(X, Y, [X | [Y | _]]).
left(X, Y, [_ | List]) :- left(X, Y, List).
neighbour(X, Y, List) :- left(X, Y, List); left(Y, X, List).
% house(Person, Pattern, Pet, Drink, Transport)
solution(Answer) :- Z = [_, _, _, _, _],
% 1. Nicola lives in the tartan house.
View gist:cc7b717387474bea18ac
// Bug demonstrating Release crash in swift code (XCode 6.2 / swift 1.1, Release builds only)
import UIKit
import XCTest
func dictSetValue(value: AnyObject, forKey key: String, inout #dictionary: [String : AnyObject]) {
dictSetValue(value, forKeyPathComponents: key.componentsSeparatedByString("."), dictionary: &dictionary)
}
func dictSetValue(value: AnyObject, forKeyPathComponents components: [String], inout #dictionary: [String : AnyObject]) {
View dockerdnsmasq.py
#!/usr/bin/env python
# Script to run dynamic dns for docker containers.
# DNS is served by dnsmasq running on the docker0 gateway ip, and dynamically
# updated at containers come and go.
#
# To use from docker, just provide the --dns option:
# docker run --dns <gateway> ...
# The gateway ip you need will be printed when this script is run.