Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / sendmail-lines.conf
Last active April 15, 2016 01:30
/etc/fail2ban/action.d/sendmail-lines.conf
# Fail2Ban configuration file
#
# Author: Cyril Jaquier
#
# $Revision$
#
# 詳見: 「fail2ban: 新手老手 root 網管都要練的金鐘罩」
# http://newtoypia.blogspot.tw/2016/04/fail2ban.html
@ckhung
ckhung / apache-deepurls.conf
Last active April 15, 2016 01:32
/etc/fail2ban/filter.d/apache-deepurls.conf to block "deep path" requests attacking apache2
# Fail2Ban configuration file
# 詳見: 「fail2ban: 新手老手 root 網管都要練的金鐘罩」
# http://newtoypia.blogspot.tw/2016/04/fail2ban.html
#
# Author: Chao-Kuei Hung
#
# $Revision: 1 $
#
[Definition]
@ckhung
ckhung / f2b-ad.conf
Last active April 15, 2016 01:33
filter to catch repeated offenders from /var/log/fail2ban.log
# Fail2Ban configuration file
#
# Author: Chao-Kuei Hung
#
# $Revision: 1 $
#
# 詳見: 「fail2ban: 新手老手 root 網管都要練的金鐘罩」
# http://newtoypia.blogspot.tw/2016/04/fail2ban.html
[Definition]
@ckhung
ckhung / decolumn-csv.perl
Last active May 4, 2016 12:50
把 csv 檔的很多個同性質欄位合併成兩個欄位
#!/usr/bin/perl -w
use strict;
use utf8;
use Getopt::Std;
my (%opts, @header, @decol, $x, $i);
%opts = (
d => ',', # delimiter
c => '0-', # columns to be de-columned. '0-6,8,12-15'
);
@ckhung
ckhung / simPWM.ino
Created August 17, 2016 14:47
arduino: simulating pulse-width modulation
void setup() {
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);
// Serial.begin(9600);
}
int epoch = 3000;
int cycle = 10;
int t = 0;
@ckhung
ckhung / csv2geojson.perl
Last active August 19, 2016 01:58
convert csv containing lon,lat,name files into geojson
#!/usr/bin/perl -w
# see http://newtoypia.blogspot.tw/2015/07/csv-geojson.html
$prev = 0; # was there any previous output?
print "[\n";
while (<>) {
chomp;
next if (/^#/ or /^\s*$/);
@f = split /\s*,\s*/;
if (defined($F{lon}) and defined($F{lat})) {
@ckhung
ckhung / ldap-objectClass-hierarchy.dot
Last active September 24, 2016 02:28
objectClass inheritance hierarchy as defined in the default schemas of openldap
// generating the content of this file:
// ldapsearch -x -LLL -o ldif-wrap=no -b cn=Subschema -s base '(objectClass=subschema)' + | perl -ne 'print "$2 -> $1;\n" if /\bNAME\s*\x27(\w+)\x27.*?\bSUP\s+(\w+)/' | grep -v '^top ->'
// generating an svg from this file:
// dot -Tsvg ldap-objectClass-hierarchy.dot > ldap-objectClass-hierarchy.svg
digraph "openldap schemas" {
rankdir = LR;
overlap = scale;
@ckhung
ckhung / readfile-jq.js
Last active January 9, 2017 11:08
the simplest file-reading example using jquery, plus fancy csv- and json-data display on html page
/* global $, document, console */
$(document).ready(function (){
// http://stackoverflow.com/questions/9898813/jquery-wait-till-multiple-get-requests-are-successully-processed
var f1 = 'https://raw.githubusercontent.com/g0v/potluckmap/gh-pages/data/shop-clothes.csv';
var f2 = 'https://raw.githubusercontent.com/g0v/potluckmap/gh-pages/data/shop-gift.geojson';
var clothes, gift;
clothes = $.get(f1);
gift = $.get(f2);
$.when(clothes, gift).done(init);
});
@ckhung
ckhung / fwmp.lxc.perl
Last active February 9, 2017 14:35
forward multiple port in one command ; 詳見 [fwmp 懶人的通訊埠轉發指令](https://newtoypia.blogspot.tw/2017/02/fwmp.html): 用一個指令幫區網內的一部機器 (可以是實體機、 kvm 虛擬機或 lxc 容器) 同時轉發好幾個通訊埠。
#!/usr/bin/perl -w
# LXC calls us with the following arguments:
# fwmp.lxc set $IP $hp1:$cp1 $hp2:$cp2 ... $cname net up veth $iface
# fwmp.lxc clear $IP $cname net down veth $iface
use strict;
my ($iface, undef, $when, undef, $cid, @ARGV) = reverse @ARGV;
@ARGV = reverse @ARGV;
@ckhung
ckhung / climage.py
Last active February 17, 2017 03:18
classify images using keras
#!/opt/conda/bin/python
# -*- coding: utf-8 -*-
import sys, argparse
from keras.preprocessing import image
import numpy as np
parser = argparse.ArgumentParser(description='classify images')
parser.add_argument('-v', '--verbosity', type=int,
choices=range(3), default=2, help='increase output verbosity')