Skip to content

Instantly share code, notes, and snippets.

View kaidokert's full-sized avatar

Kaido Kert kaidokert

View GitHub Profile
@kaidokert
kaidokert / staticapp.py
Last active July 14, 2016 16:08
Low fuss bottle app to serve static
import os
import sys
import bottle
bottle.debug(True)
static_root = os.path.abspath(os.path.dirname(__file__))
@bottle.route('/')
@kaidokert
kaidokert / angular-bootstrap.html
Last active January 1, 2018 22:59
Minimal standalone bootstrap/angular page
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="" style="" xmlns:ng="http://angularjs.org" ng-app="fooApp" ng-strict-di>
# pip install retryz backoff
from __future__ import print_function
import random
import retryz
import backoff
def naughty_func():
picky = random.randint(1, 3)
import urlparse
import argparse
import psycopg2
class Bunch:
def __init__(self, **kwds):
self.__dict__.update(kwds)
@kaidokert
kaidokert / salt_repo.sls
Created January 25, 2016 06:41
Salt minion install from official repos, migrating from PPA
{% set ver_str = [grains.os|lower,grains.osrelease,grains.osarch]|join('/') %}
{% set release = latest %} {# currently 2015.8 #}
{% set release = 2015.5 %}
salt_repo:
pkgrepo.managed:
- humanname: salt-repo
- name: "deb http://repo.saltstack.com/apt/{{ ver_str }}/{{ release }} {{ grains.oscodename }} main"
- file: /etc/apt/sources.list.d/salt.list
- keyid: DE57BFBE
@kaidokert
kaidokert / demo.js
Created January 13, 2016 06:36
Easily make Node http requests with built in http and Promises module
var http = require('http');
function make_request(options, payload) {
return new Promise(function(resolve,reject) {
if(payload) options.method = 'POST'; else options.method = 'GET';
var request = http.request(options,function(response) {
var str = '';
response.on('error', function() { reject('Error'); } )
response.on('data', function (chunk) { str += chunk; })
response.on('end', function () { resolve(JSON.parse(str));})
@kaidokert
kaidokert / varmacros.h
Created January 8, 2016 01:11
Portable variadic macros
// excellent solution from here : http://stackoverflow.com/a/24028231/295231
//macro glue to make it work on msvc/gcc
#define GLUE(x, y) x y
#define RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, count, ...) count
#define EXPAND_ARGS(args) RETURN_ARG_COUNT args
#define COUNT_ARGS_MAX5(...) EXPAND_ARGS((__VA_ARGS__, 5, 4, 3, 2, 1, 0))
@kaidokert
kaidokert / librato_alerts_to_yaml.py
Created January 6, 2016 02:30
Dump all defined alerts in Librato to a cleaned and ordered Yaml file, to use in Salt
import argparse
import collections
import yaml
import librato
# ht to http://stackoverflow.com/a/16782282/295231
# http://stackoverflow.com/a/20720773/295231
class UnsortableList(list):
def sort(self, *args, **kwargs):
@kaidokert
kaidokert / osx-for-hackers.sh
Created December 31, 2015 19:41 — forked from matthewmueller/osx-for-hackers.sh
OSX for Hackers (Mavericks/Yosemite)
# OSX for Hackers (Mavericks/Yosemite)
#
# Source: https://gist.github.com/brandonb927/3195465
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront
{%- set fqdn = grains['id'] %}
{%- set internal_ip = grains['ip4_interfaces']['eth0'][0] %}
hostname-match:
file.managed:
- name: /etc/hostname
- contents: {{ fqdn }}
primary_ip_in_host_file:
host.present: