Skip to content

Instantly share code, notes, and snippets.

@timoyuen
timoyuen / gist:94f9ea3cd7253144e543
Created November 27, 2014 08:18
grep remove blank line and remove bash comment
cat /etc/dnsmasq.conf | grep -v '^$' | grep -v '#'
@timoyuen
timoyuen / README.md
Last active August 29, 2015 14:24 — forked from robschmuecker/README.md

Multi Link Example for http://www.robschmuecker.com/d3-js-drag-and-drop-zoomable-tree/#comment-6190

Added an additional link between nodes at the bottom of the dndTree.js file.

This example pulls together various examples of work with trees in D3.js.

The panning functionality can certainly be improved in my opinion and I would be thrilled to see better solutions contributed.

One can do all manner of housekeeping or server related calls on the drop event to manage a remote tree dataset for example.

@timoyuen
timoyuen / epubs2t_opencc.py
Last active August 29, 2015 14:27 — forked from yen3/epubs2t_opencc.py
Convert epub content from simple chinese to traditional chinese using OpenCC (https://code.google.com/p/opencc/)
#!/usr/bin/env python
#-*- coding: utf8 -*-
from __future__ import print_function
from optparse import OptionParser
import zipfile
from sys import argv, exit
from subprocess import Popen, PIPE, check_output
import os.path
@timoyuen
timoyuen / SynchronousHandler.java
Last active August 29, 2015 14:28 — forked from Petrakeas/SynchronousHandler.java
Android - Posts a runnable on a handler's thread and waits until it has finished running.
import android.os.Handler;
import android.os.Looper;
/**
* A helper class that provides more ways to post a runnable than {@link android.os.Handler}.
*
* Created by Petros Douvantzis on 19/6/2015.
*/
public class SynchronousHandler {
@timoyuen
timoyuen / zext_msmtp.sh
Created September 30, 2015 10:10 — forked from ramunasd/zext_msmtp.sh
Zabbix email alert script with TLS support
#! /bin/sh
################################################################################
# Zabbix extensions (C) 2011-* Joseph Bueno <[email protected]>
# Published under GNU General Public License version 2 or later.
# See LICENSE.txt
#-------------------------------------------------------------------------------
# Usage:
# zext_msmtp.sh <recipient> <subject> <message>
#
# Description:
@timoyuen
timoyuen / lockfile_pid_tpl.sh
Created December 18, 2015 02:21
Limit bash script to one running instance, while keeping it open to other calls
#!/bin/bash
user_id_num=$(id -u)
pid_file="/tmp/foobar-$user_id_num/foobar-$user_id_num.pid"
lock_file="/tmp/foobar-$user_id_num/running.lock"
ps_id=$$
function alertRunningPS () {
local PID=$(cat "$pid_file" 2> /dev/null)
echo "Lockfile present. ps id file: $PID"
@timoyuen
timoyuen / README.md
Created January 7, 2016 08:36 — forked from renchap/README.md
One-line certificate generation/renews with Letsencrypt and nginx

Prerequisites : the letsencrypt CLI tool

This method allows your to generate and renew your Lets Encrypt certificates with 1 command. This is easily automatable to renew each 60 days, as advised.

You need nginx to answer on port 80 on all the domains you want a certificate for. Then you need to serve the challenge used by letsencrypt on /.well-known/acme-challenge. Then we invoke the letsencrypt command, telling the tool to write the challenge files in the directory we used as a root in the nginx configuration.

I redirect all HTTP requests on HTTPS, so my nginx config looks like :

server {
@timoyuen
timoyuen / nginx.conf
Created February 19, 2016 05:05 — forked from jrom/nginx.conf
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
@timoyuen
timoyuen / SelfExpiringHashMap.java
Created March 30, 2016 02:39
SelfExpiringHashMap - a Java Map which entries expire automatically after a given time; it uses a DelayQueue internally.
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;