Skip to content

Instantly share code, notes, and snippets.

@rlei
rlei / sshguard_banned_ips.sh
Last active March 7, 2020 13:08
Generate CSV of country/city/geo location/ISP information of the IPs banned by sshguard. Requires jq (https://stedolan.github.io/jq/).
#!/bin/sh
echo '"country","city","latitude","longitude","ISP","organization","IP"'
sudo iptables-save | grep sshguard | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | xargs -I{} curl -s http://ip-api.com/json/{} | jq -r '[.country, .city, .lat, .lon, .isp, .org, .query] | @csv'
<html>
<head>
<title>API Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
var accessToken = "<your agent's client access token>";
var baseUrl = "https://api.api.ai/v1/";
@rlei
rlei / chinese-num.clj
Created December 1, 2015 07:28
Convert number to its Chinese representation
; Algorithm described in http://zhuanlan.zhihu.com/iobject/20370983
; Be warned: it's in Chinese too ;)
(def digits-name (zipmap "0123456789" "零一二三四五六七八九"))
(def tens-name (zipmap [1 2 3] [\十 \百 \千]))
(defn digit-pos-to-name [pos]
(cond (= pos 0) nil
(= 0 (rem pos 8)) \亿
(= 0 (rem pos 4)) \万
:else (tens-name (rem pos 4))))
@rlei
rlei / dnspod-ddns.py
Last active February 16, 2020 20:14
DNSPod dynamic DNS bridge for OpenWRT DDNS service
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# DNSPod dynamic DNS bridge for OpenWRT DDNS service
# This script creates a simple HTTP server and updates your DNSPod DDNS record
# on any HTTP GET request received. This allows you to create a customized DDNS
# service for DNSPod with OpenWRT's standard DDNS support.
# Copyright 2015-2016 rlei @ GitHub
#
@rlei
rlei / osx-chrome-footprint.sh
Last active August 29, 2015 14:06
View Google Chrome total RAM footprint on OS X (tested on 10.9.4)
top -l 1 -stats mem,command | grep Chrome | cut -d' ' -f1 | awk '/K/ { gsub(/K.*$/,""); sum+=$1} /M/ { gsub(/M.*$/,""); sum+=$1*1024} END {printf "%.2fM\n", sum/1024} '
@rlei
rlei / flash.sh
Created September 1, 2014 14:49 — forked from fcicq/flash.sh
#!/bin/sh
#high chance need have a change ...
if [ ! $# -eq 2 ]; then
echo "usage: $0 UBOOTFILE MD5"
exit
fi
UBOOT_NAME=$1
MD5SUM_SHOULD_BE=$2
diff --git a/build/module.mk b/build/module.mk
index b69019c..4ed8e3e 100644
--- a/build/module.mk
+++ b/build/module.mk
@@ -25,10 +25,10 @@ luasource:
cp -pR htdocs/* dist$(HTDOCS) 2>/dev/null || true
for i in $$(find dist -name .svn -o -name .gitignore); do rm -rf $$i || true; done
ifneq ($(PO),)
- mkdir -p dist$(LUCI_I18NDIR)
- for file in $(PO); do \