Skip to content

Instantly share code, notes, and snippets.

@wolf0403
wolf0403 / json_order.go
Created July 19, 2018 09:17
Marshalling / unmarshalling JSON in Go, keeping "order of the keys as they were in the source"
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"os"
)
@wolf0403
wolf0403 / dedup.go
Created October 3, 2016 11:50
Scan multiple fs roots, looking for dup files.
package main
import (
"crypto/sha1"
"encoding/json"
"flag"
"fmt"
"hash/crc64"
"io/ioutil"
"log"
@wolf0403
wolf0403 / check_size.sh
Last active August 27, 2015 13:12
Find large file in your FS.
#!/bin/bash
export V=
check_size() {
wd=${1:-.}
indent=${2}
#echo "${indent}${wd}: "
du -h -d1 "${wd}" | (
while read line; do
@wolf0403
wolf0403 / my.slate
Last active December 8, 2018 10:44
Slate WM config to replace Spectacle
# I'm getting Amethyst for my dual-monitor work setup
#
# For laptop, I'm replacing good-old Spectacle with Slate
# just for its Grid / Hint and versionable configuration
# to start with.
# https://github.com/jigish/slate
bind 0:alt,cmd relaunch
bind 1:alt,cmd grid 0:6,4
bind 2:alt,cmd hint
@wolf0403
wolf0403 / sched_callback.py
Last active August 29, 2015 14:07
Bound method as callback
import sched, time
class O(object):
def __init__(self, name):
self.name = name
def print_time(self):
print("({}): From print_time {}".format(self.name, time.time()))
def entry(self):
s = sched.scheduler(time.time, time.sleep)
s.enter(2, 1, self.print_time, ())
@wolf0403
wolf0403 / schmitt_trigger.py
Created October 3, 2014 01:05
Schmitt trigger in python coroutines
from __future__ import print_function
def schmitt_trigger(lo, hi, cb, value):
"""http://en.wikipedia.org/wiki/Schmitt_trigger"""
while True:
newvalue = (yield value)
if newvalue is None:
raise StopIteration()
if newvalue >= hi and value < hi:
cb(hi, newvalue, 'to-hi')
@wolf0403
wolf0403 / Wordpress.dockerfile
Created September 26, 2014 05:42
Dockerfile for simple Wordpress with SQLite.
# Originally from: http://dustymabe.com/2014/05/10/zero-to-wordpress-on-docker-in-5-minutes/
FROM goldmann/f20
MAINTAINER Dusty Mabe
# Install httpd and update openssl
RUN rpm -Uvh http://kojipkgs.fedoraproject.org//packages/yum/3.4.3/120.fc20/noarch/yum-3.4.3-120.fc20.noarch.rpm
RUN yum update -y
RUN yum install -y httpd openssl unzip php php-pdo wget
@wolf0403
wolf0403 / svnrevs.py
Created September 18, 2014 10:47
List svn revisions by parsing `svn log` output.
import subprocess as sp
def list_revs(path, limit=10):
""" Parse output from svn log and find log headers. Maybe fooled if log entry contains some other svn log entries, etc."""
out = sp.check_output('svn log -l {limit} {path}'.format(path=path, limit=limit), shell=True)
lines = out.split('\n')
for pre, line, space in zip(lines[:-2], lines[1:], lines[2:]):
if pre.startswith('-------') and space.strip() == '':
parts = line.split('|')
if len(parts) == 4 and parts[0].startswith('r'):
@wolf0403
wolf0403 / gspider.py
Created September 5, 2014 19:10
Gevent Spider
import gevent
import logging
import requests
try:
import simplejson as json
except:
import json
from gevent.pool import Group, Pool
@wolf0403
wolf0403 / grpc.py
Created July 23, 2014 15:15
Simple "RPC" in Greenlet
import gevent
from gevent import Greenlet
from gevent.queue import Queue
from gevent.lock import BoundedSemaphore
class Worker(object):
def __init__(self, *a, **kw):
self._glet = Greenlet(self.run, *a, **kw)
self._q = Queue()