Skip to content

Instantly share code, notes, and snippets.

View qianjigui's full-sized avatar
🎯
Focusing

WPC qianjigui

🎯
Focusing
View GitHub Profile
@qianjigui
qianjigui / aws-vpn-shell.sh
Created December 5, 2020 14:54
aws-vpn-shell
#!/bin/sh
#
# Amazon EC2 user-data file for automatic configuration of IPsec/L2TP VPN server
# on a Ubuntu or Debian instance. Tested with Ubuntu 14.04 & 12.04 and Debian 8.
# With minor modifications, this script *can also be used* on dedicated servers
# or any KVM- or XEN-based Virtual Private Server (VPS) from other providers.
#
# DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! THIS IS MEANT TO BE RUN WHEN
# YOUR AMAZON EC2 INSTANCE STARTS!
#
@qianjigui
qianjigui / ruby_chinese_to_unicode8_java_format.rb
Created May 7, 2015 07:26
ruby_chinese_to_unicode8_java_format
#!/usr/bin/env ruby
#encoding: utf-8
#
'你好'.unpack('U*').each do |i|
print "\\u%s" % [i.to_s(16)]
end
puts ''
@qianjigui
qianjigui / Go_httpserver_demo.go
Created September 8, 2014 00:31
Go httpserver demo
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world")
}
@qianjigui
qianjigui / Go_concurrent_demo.go
Last active August 29, 2015 14:06
GO concurrent demo
package main
// similar to Matt Aimonetti's example, read his blog!
// http://matt.aimonetti.net/posts/2012/11/27/real-life-concurrency-in-go/
func concurrently(integers []int) []int {
// make a channel to talk to the goroutines
ch := make(chan int)
// prepare a slice with all the results
responses := []int{}
@qianjigui
qianjigui / java_sdk_build.gradle
Created September 4, 2014 04:17
Java SDK Build gradle template: proguard, static-test
apply plugin: 'java'
//repositories {
// mavenCentral()
// maven {
// url 'https://repo.eclipse.org/content/groups/releases/'
// }
//}
@qianjigui
qianjigui / Rails_mysql_utf8_encoding.patch
Created August 22, 2014 03:28
Rails MYSQL UTF8 Connection
Subject: [PATCH] Fix DB linking encoding to utf8
---
Gemfile | 2 +-
Gemfile.lock | 4 ++--
config/application.rb | 2 ++
config/database.yml | 12 ++++++------
config/environment.rb | 2 ++
5 files changed, 13 insertions(+), 9 deletions(-)
@qianjigui
qianjigui / Makefile_multithread_sync_file.mk
Created July 7, 2014 11:06
Makefile_multithread_sync_file.mk
CONFIG_LAST_TIME_FILE := $(srctree)/.compile.project.time
CONFIG_STAT_TIME:=$(if $(wildcard $(CONFIG_FILE)),$(shell stat -c %Y $(CONFIG_FILE)),)
TMP_CONFIG_LAST_TIME:=$(if $(wildcard $(CONFIG_LAST_TIME_FILE)),$(shell cat $(CONFIG_LAST_TIME_FILE)),)
# ......
ifneq ("$(CONFIG_STAT_TIME)","$(TMP_CONFIG_LAST_TIME)")
$(warning "merge config and defaut config:")
OUT_CONFIG := $(srctree)/.config
xxx_config := $(call config.generate-auto-rules)
@qianjigui
qianjigui / Ruby_LDAP_Use_Example.rb
Created June 12, 2014 04:08
Ruby_LDAP_Use_Example
class LdapRequest
HOST = 'mail.example.com'
PORT = 636
TREEBASE='DC=example.com,DC=com'
ATTRS=['mail', 'department', 'telephoneNumber', 'mobile']
def initialize(username, password)
@ldap = Net::LDAP.new :host => HOST,
:port => PORT,
:encryption => :simple_tls,
:auth => {
@qianjigui
qianjigui / shell_previous_status.sh
Created April 21, 2014 07:25
Shell get the previous command's return status. 0 = success
#!/bin/bash
echo 'Error' > /abc.txt
echo $? #1
echo 'Pass'
echo $? #0
echo 'Pass' && echo 'Error' > /adc.txt && echo 'After Error'
echo $? #1
@qianjigui
qianjigui / android_build_preinstall_apps.sh
Created April 20, 2014 04:12
Android System, Many devices will contain preinstall apps
#!/system/xbin/busybox sh
PREINSTALL_RECORD_FILE=/data/system.notfirstrun
if [ ! -e $PREINSTALL_RECORD_FILE ]; then
echo "do preinstall job"
for i in `/system/xbin/busybox find /system/etc/property/app/ -type f -name '*.apk'`;
do
/system/bin/sh /system/bin/pm install $i
done
/system/xbin/busybox touch $PREINSTALL_RECORD_FILE
echo "preinstall ok"