Skip to content

Instantly share code, notes, and snippets.

@ChaosJohn
ChaosJohn / installDockerMachine.sh
Last active April 12, 2018 10:09
Install docker-machine executable from official (Automatically check the running system)
#!/bin/sh
# Extract the value for the key
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
# Get the latest version name from github
{"sig":"e6257cca04ab5f2659e9093fd2d61d648b98adceb700bc665a3560886bbe003593799b821cde23035134a73dfbf50d31bde2b7b815516ed6f5707cab77a9b5b30","msghash":"8e8a4b38a0d90aa23c3a9168902bf4f166f88f403a96057c1f9869b00f77307f"}
@ChaosJohn
ChaosJohn / KotlinGson.java
Last active January 20, 2018 07:02 — forked from leoleozhu/Foo.java
Use gson to parse integer array
package com.foo;
import java.util.Arrays;
import java.util.List;
import com.google.gson.Gson;
public class KotlinGson {
private static List<Integer> toList(String json, Gson parser) {
@ChaosJohn
ChaosJohn / visualstudiocode.sh
Created March 15, 2017 17:26 — forked from ted-piotrowski/visualstudiocode.sh
Visual Studio Code on ARM Debian Linux
# building Visual Studio Code Debian package on ARM
# get source code
git clone git@github.com:Microsoft/vscode.git
cd vscode
# build debian package
./scripts/npm.sh install --arch=armhf
./node_modules/.bin/gulp vscode-linux-arm-build-deb
@ChaosJohn
ChaosJohn / gist:485683c8c845f340ff74f32f9d7f3d58
Created February 11, 2017 02:02 — forked from rtrouton/gist:f92f263414aaeb946e54
Install Xcode command line tools on 10.7.x - 10.10.x. Tested on 10.7.5, 10.8.5, 10.9.5 and 10.10.2.
#!/bin/bash
# Installing the Xcode command line tools on 10.7.x or higher
osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}')
cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
# Installing the latest Xcode command line tools on 10.9.x or higher
if [[ "$osx_vers" -ge 9 ]]; then
@ChaosJohn
ChaosJohn / update_gfwlist.sh
Created December 14, 2016 02:38 — forked from VincentSit/update_gfwlist.sh
Automatically update the PAC for ShadowsocksX. Only tested on OS X.
#!/bin/bash
# update_gfwlist.sh
# Author : VincentSit
# Copyright (c) http://xuexuefeng.com
#
# Example usage
#
# ./whatever-you-name-this.sh
#
# Task Scheduling (Optional)
@ChaosJohn
ChaosJohn / ATS.plist
Created September 21, 2016 11:49 — forked from onevcat/ATS.plist
Fuck off ATS
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
@ChaosJohn
ChaosJohn / brew-cask-upgrade.sh
Created August 22, 2016 06:35 — forked from c00kiemon5ter/brew-cask-upgrade.sh
a portable shell script to upgrade cask packages
#!/bin/sh
help=0
latest=0
verbose=0
status=0
usage() {
cat <<-EOF
${0##*/} [options]
@ChaosJohn
ChaosJohn / OkHttpProgressGlideModule.java
Created June 29, 2016 09:56 — forked from TWiStErRob/OkHttpProgressGlideModule.java
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@ChaosJohn
ChaosJohn / PersistentCookieStore.java
Created April 14, 2016 14:16 — forked from lezorich/PersistentCookieStore.java
Android basic persistent cookie manager for Volley. This cookie store wraps the default CookieManager store to store the session cookie. It use's Gson to json serialize the cookie and store it as a json string in SharedPreferences.
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Lukas Zorich
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is