Skip to content

Instantly share code, notes, and snippets.

@zhouji
zhouji / nginx.conf
Created November 7, 2017 14:55 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@zhouji
zhouji / webcrawler.js
Created October 25, 2015 16:26 — forked from amoilanen/webcrawler.js
Simple PhantomJS-based web crawler library
//PhantomJS http://phantomjs.org/ based web crawler Anton Ivanov anton.al.ivanov@gmail.com 2012
//UPDATE: This gist has been made into a Node.js module and now can be installed with "npm install js-crawler"
//the Node.js version does not use Phantom.JS, but the API available to the client is similar to the present gist
(function(host) {
function Crawler() {
this.visitedURLs = {};
};
@zhouji
zhouji / build.gradle
Last active August 29, 2015 14:23 — forked from goncha/build.gradle
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
project.version = "1.0"
try {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'svn'
@zhouji
zhouji / test_jetty_gzip.groovy
Created February 26, 2015 06:14
Jettty Handle Gzip Post Body
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import java.util.zip.GZIPInputStream;
Server server = new Server(18811);
server.setHandler(new AbstractHandler(){
@zhouji
zhouji / HqlResultSet.java
Created August 29, 2014 07:01
ResultSet to List<Map>
public static List<Map<String,String>> convert(ResultSet resultSet) throws SQLException {
List<Map<String,String>> rows = new ArrayList<>();
while (resultSet.next()) {
int total_rows = resultSet.getMetaData().getColumnCount();
Map<String,String> row = new HashMap<>();
for (int i = 0; i < total_rows; i++) {
row.put(resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase(), resultSet.getObject(i + 1).toString());
}
rows.add(row);
}
#!/bin/bash
echo -ne "\033[0;33m"
cat<<EOT
_oo0oo_
088888880
88" . "88
(| -_- |)
0\ = /0
___/'---'\___
@zhouji
zhouji / .screenrc
Last active August 29, 2015 14:01 — forked from joaopizani/.screenrc
# use C+b as escape key
escape ^Bb
# the following two lines give a two-line status, with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%? %1`%?%{g}][%= %{= kw}%-w%{+b yk} %n*%t%?(%u)%? %{-}%+w %=%{g}][%{B}%m/%d %{W}%C%A%{g}]'
# huge scrollback buffer
defscrollback 5000

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@zhouji
zhouji / ssh-agent
Created September 26, 2013 06:49 — forked from rezlam/ssh-agent
SSH_ENV="$HOME/.ssh/environment"
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
echo succeeded
chmod 600 "$SSH_ENV"
. "$SSH_ENV" > /dev/null
@zhouji
zhouji / test.clj
Created August 12, 2013 01:53 — forked from adambard/test.clj
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)