Skip to content

Instantly share code, notes, and snippets.

View liling's full-sized avatar

Ling Li liling

View GitHub Profile
@liling
liling / mysql_change_charset.groovy
Last active August 29, 2015 14:11
MySQL 数据库字符集修改
import groovy.sql.GroovyResultSet
import groovy.sql.Sql
import java.sql.ResultSet
/**
* 这个程序用来修改 MySQL 数据库表中字段的字符集标注。适用于原先没有标注(latin1),但存储的却是 GBK 编码的表格。
*
* 如果原本存储的是 UTF-8 数据,把程序中的 gbk 替换为 utf8 即可。
*/
@liling
liling / check_smsd_balance
Last active August 29, 2015 13:56
检查 gnokii smsd 短信猫所对应的中国移动神州行电话卡的余额,需配合 python-pynag 和 python-mysqldb 使用
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 检查 gnokii smsd 连接的短信猫对应的电话卡的余额,并返回给 nagios
# 使用方法为 check_smsd_balance -c 20: -w 100: -p 2
import MySQLdb, re, string
## This is for the custom nagios module
from pynag.Plugins import simple as Plugin
@liling
liling / gist:7052246
Created October 19, 2013 06:23
Shiro CAS Realm of grails-shiro 1.1.4 plugin. This one use CAS as authentication method and use database store authorization data. When user logging into the system for the first time, an user record is created for him automatically and a default role is added to user.
import base.shiro.ShiroRole
import base.shiro.ShiroUser
import org.apache.shiro.cas.CasAuthenticationException
import org.apache.shiro.authc.AccountException
import org.apache.shiro.authc.SimpleAuthenticationInfo
import org.apache.shiro.util.StringUtils
import org.apache.shiro.util.CollectionUtils
import org.apache.shiro.subject.PrincipalCollection
import org.apache.shiro.subject.SimplePrincipalCollection
@liling
liling / snapshot.sh
Created July 30, 2013 05:55
A bash script maintains rotate zfs snapshots
#!/bin/bash
function add_slash {
echo $1 | sed -e 's/\//\\\//'
}
function list_snapshot {
local v=$(add_slash $VOL)
zfs list -t snapshot | awk "/$v@$SNAPSHOT-/"'{print $1}'
}
@liling
liling / gist:2665413
Created May 12, 2012 09:13
北理工程序设计竞赛:2012年报名名单转换为Moodle导入名单
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import csv, subprocess
tableReader = csv.reader(open('lx.csv', 'rb'), delimiter=',', quotechar='"')
tableWriter = csv.writer(open('mdl-lx.csv', 'wb'))
tableWriter.writerow(['username','password','lastname','firstname','email','description','course1'])
@liling
liling / kaixin001-rich.user.js
Created December 5, 2009 04:33
开心网超级大亨:记录各种产品的价格并显示。
// ==UserScript==
// @name 开心网超级大亨
// @namespace kaixin001.app.rich
// @description 记录开心网超级大亨各种产品的价格
// @include http://www.kaixin001.com/!rich/*
// ==/UserScript==
function parse_number(num) {
var unit = 1;
if (num.match(/万元/)) {