Skip to content

Instantly share code, notes, and snippets.

@rlander
rlander / gist:9987786
Created April 5, 2014 05:18
use a python function from jinja
from jinja2 import contextfunction
@contextfunction
def widget(context, template_name, **extra_context):
t = jinja_env.get_template('widgets/' + template_name)
ctx = dict(context.items())
ctx.update(extra_context)
return t.render(ctx)
jinja_env.globals['widget'] = widget
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import csv
import collections
from datetime import datetime
from peewee import *
check process redis-server
with pidfile "/var/run/redis.pid"
start program = "/etc/init.d/redis-server start"
stop program = "/etc/init.d/redis-server stop"
if 2 restarts within 3 cycles then timeout
if totalmem > 100 Mb then alert
if children > 255 for 5 cycles then stop
if cpu usage > 95% for 3 cycles then restart
if failed host 127.0.0.1 port 6379 then restart
if 5 restarts within 5 cycles then timeout
@rlander
rlander / gist:20259a3970ce7ffbd503
Created April 27, 2015 11:26
Get gender for event attendees
import unicodecsv
r = unicodecsv.reader(open("attendees.csv"), encoding='utf-8-sig')
att = []
for row in r:
att.append(dict(id=row[0], Name=row[1]))
att_list = [first_name(i['Name']) for i in att]
for i in [i['Name'].split()[0] for i in att]:
// Create a dummy analytics object until real loaded
window.analytics || (window.analytics = []);
window.analytics.methods = ['identify', 'track', 'trackLink', 'trackForm', 'trackClick', 'trackSubmit', 'page', 'pageview', 'ab', 'alias', 'ready', 'group', 'on', 'once', 'off'];
window.analytics.factory = function(method) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
window.analytics.push(args);
return window.analytics;
};
@rlander
rlander / gist:a27c5a0cc034e700425b
Created September 22, 2015 22:20 — forked from that0n3guy/gist:905c812c0f65e7ffb5ec
Mautic nginx config
server {
# see: http://wiki.nginx.org/Pitfalls
# see: http://wiki.nginx.org/IfIsEvil
listen 80;
root /app;
index index.html index.htm index.php;
error_page 404 /index.php;
# Make site accessible from http://set-ip-address.xip.io
# IMPORTANT
# /OpenVBX/config/config.php
# $config['index_page'] = '';
server {
listen 80;
# Make site accessible from http://set-ip-address.xip.io
require! <[ watchify browserify gulp ]>
require! 'vinyl-source-stream': source
require! 'vinyl-buffer': buffer
require! 'gulp-util': gutil
require! 'liveify'
gulp.task \bundle !->
bundler = watchify browserify {} <<< watchify.args <<<
entries: ['./src/index.ls']
debug: true
@rlander
rlander / build-erlang-17.sh
Last active February 19, 2016 22:14 — forked from bryanhunter/build-erlang-17.0.sh
Build Erlang 17.0 on a fresh Ubuntu box (tested on 12.04 and 14.04)
#!/bin/bash
# Pull this file down, make it executable and run it with sudo
# wget https://gist.githubusercontent.com/rlander/7db38d57166f55c06fcf/raw/b4edf4c6fd39c604392a96ce6ff21953ff941e51/build-erlang-17.sh
# chmod u+x build-erlang-17.sh
# sudo ./build-erlang-17.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
@rlander
rlander / date_util.erl
Created May 12, 2016 23:45 — forked from zaphar/date_util.erl
set of utility functions that wrap the calendar module and erlangs now() date() and time() functions
-module(date_util).
-compile(export_all).
epoch() ->
now_to_seconds(now())
.
epoch_hires() ->
now_to_seconds_hires(now())
.