Skip to content

Instantly share code, notes, and snippets.

View jiafangtao's full-sized avatar

Bruce Jia jiafangtao

  • Shanghai, China
View GitHub Profile
@jiafangtao
jiafangtao / randout.py
Created December 14, 2023 03:34
random output to stdout or stderr
import sys
import time
import random
print(f"hello from {sys.argv[0]}")
out = 0
err = 0
while out < 10 and err < 10:
@jiafangtao
jiafangtao / bash_alias
Created October 9, 2023 03:22
Most used bash alias
# git
alias ga='git add'
alias gb='git branch'
alias gclone='git clone'
alias gco='git checkout'
alias gc='git commit'
alias gcmt='git commit'
alias gs='git status'
alias gl='git log'
alias gdiff='git diff'
@jiafangtao
jiafangtao / checkcomments.groovy
Created November 17, 2021 06:37
Check if files are started with comments
#! /usr/bin/groovy
/*******************************************************************
*
* My first groovy script which is used to determine if a file is
* started with JAVA comments, i.e. // or /*.
*
*******************************************************************/
// The file list is piped to the script (i.e. stdin)
@jiafangtao
jiafangtao / sources.list
Created March 27, 2020 02:39
debian pkg mirror_163
# SRC: http://mirrors.163.com/.help/debian.html
deb http://mirrors.163.com/debian/ stretch main non-free contrib
deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
@jiafangtao
jiafangtao / doPostWithCurl.java
Created June 25, 2018 07:46
Invoke curl to do HTTP POST in JAVA
/*
* Sends a POST request to target URL by forking curl.
* Returns the response content on success; Otherwise returns null.
*
*/
private static String sendPostWithCurl (String url) {
String [] cmdOptions = new String[] {"/usr/bin/curl", "-k", "-H \"Content-Length: 0\"", "-X", "POST", url};
StringBuilder builder = new StringBuilder();
@jiafangtao
jiafangtao / ignoreSslClient.java
Created June 25, 2018 07:42
HttpClient to ignore SSL errors
public static Client ignoreSSLClient() throws Exception {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[]{new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
}}, new java.security.SecureRandom());
// register global shortcuts
var { globalShortcut } = require('electron');
var ret = globalShortcut.register('CommandOrControl+Down', function () {
console.log ('Key down is pressed with globalShortcut');
});
if (!ret) {
console.log ('failed to register shortcut');
}
@jiafangtao
jiafangtao / centurypark.json
Created August 31, 2017 06:45
century park in GeoJSON format
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
121.55539512634279,
31.224876067583286
],