Skip to content

Instantly share code, notes, and snippets.

View lyhcode's full-sized avatar

Kyle Lin lyhcode

View GitHub Profile
@lyhcode
lyhcode / jsoup_demo.groovy
Created December 30, 2012 13:34
Groovy + Jsoup
@Grab('org.jsoup:jsoup:1.7.1')
def doc = org.jsoup.Jsoup.connect("https://news.google.com/nwshp?hl=zh-TW&tab=wn").get()
doc.select("#s_POPULAR .titletext").each {
node->
println "title=${node.text()}"
}
@lyhcode
lyhcode / selenium_screenshot.groovy
Created December 30, 2012 14:35
Groovy + Selenium for Web ScreenShot Capturing
@Grapes([
@Grab('org.seleniumhq.selenium.client-drivers:selenium-java-client-driver:1.0.2'),
@Grab('org.seleniumhq.selenium:selenium-server:2.25.0'),
@GrabConfig(systemClassLoader=false, initContextClassLoader=true)
])
import com.thoughtworks.selenium.*
import org.openqa.selenium.server.*
seleniumServer = new SeleniumServer()
@lyhcode
lyhcode / svn
Created January 5, 2013 13:39
sample configuration /etc/xinetd.d/svn
# default: off
# description: svnserve is the server part of Subversion.
# server_args = -i -r /var/lib/svn/repositories
service svn
{
disable = no
port = 3690
socket_type = stream
protocol = tcp
wait = no
worker.list=loadbalancer
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=contpub1
worker.loadbalancer.sticky_session=1
worker.loadbalancer.error_escalation_time=0
worker.loadbalancer.max_reply_timeouts=10
worker.contpub1.reference=worker.template
worker.contpub1.host=localhost
@lyhcode
lyhcode / client-ifconfig.txt
Created January 25, 2013 16:05
all relevant configuration files and the route tables
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=2b<RXCSUM,TXCSUM,VLAN_HWTAGGING,TSO4>
ether 10:9a:dd:46:41:8d
@lyhcode
lyhcode / vpnconn.sh
Created January 25, 2013 17:21
Let VPN clients access to server LAN using iptables and route
# ubuntu vpn server
sudo iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -d 192.168.0.0/24 -j MASQUERADE
# mac os x client
sudo route add 192.168.0.0/24 192.168.100.1
/**
* HttpBuilder Testing
*/
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://localhost:8080' )
@lyhcode
lyhcode / sample1.groovy
Created November 15, 2013 07:26
Illustrate how to access data with KoobeCommonData using scripts
/**
* sample1.groovy - Koobe Scripting Project
*
* Illustrate how to access data with KoobeCommonData using scripts
*
* Usages:
* groovy sample1.groovy
*
* Required System Environment properties:
* JDBC_CONNECTION_STRING
@lyhcode
lyhcode / default.latex
Created January 1, 2014 10:15
pandoc default.latex sample
\documentclass[$if(fontsize)$$fontsize$,$endif$b5paper]{$documentclass$}
%\documentclass[$if(fontsize)$$fontsize$,$endif$twocolumn]{$documentclass$}
\usepackage[vmargin=$vmargin$,hmargin=$hmargin$]{geometry}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
%\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\else
\ifluatex
@lyhcode
lyhcode / pdftrim
Created March 8, 2015 07:21
Remove text layer from PDF using Apache PDFBox in a Groovy script
#!/usr/bin/env groovy
@Grab('org.apache.pdfbox:pdfbox:1.8.8')
import org.apache.pdfbox.cos.COSArray
import org.apache.pdfbox.cos.COSString
import org.apache.pdfbox.pdfparser.PDFStreamParser
import org.apache.pdfbox.pdfwriter.ContentStreamWriter
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.PDPage
import org.apache.pdfbox.pdmodel.common.PDStream
import org.apache.pdfbox.util.PDFOperator