Skip to content

Instantly share code, notes, and snippets.

View kamikat's full-sized avatar

Kamikat kamikat

  • Beijing, China
View GitHub Profile
@kamikat
kamikat / nginx-amplify.tmpl
Last active July 1, 2016 09:26
Generate nginx-amplify compatible Nginx configuration with docker-gen.
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
{{ define "upstream" }}
{{ if .Address }}
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
{{ if and .Container.Node.ID .Address.HostPort }}
# {{ .Container.Node.Name }}/{{ .Container.Name }}
server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }};
{{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
{{ else if .Network }}
@kamikat
kamikat / MoshiHelper.java
Last active January 15, 2019 10:32
Clone a com.squareup.moshi.JsonReader object
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
import okio.Buffer;
import okio.BufferedSink;
import java.io.IOException;
public final class MoshiHelper {
public static void dump(JsonReader reader, BufferedSink sink) throws IOException {
@kamikat
kamikat / AccessToken.java
Last active March 6, 2018 00:17
polymorphic parsing example of moshi-jsonapi
package moe.banana.jsonapi2.issue5;
import moe.banana.jsonapi2.JsonApi;
import moe.banana.jsonapi2.Resource;
@JsonApi(type = "accessToken") // `access-tokens` is recommended by JSON API specification
public class AccessToken extends Resource {
public String tokenType;
public String value;
}
@kamikat
kamikat / layout.xml
Last active September 1, 2021 17:40
NestedScrollView + SwipeRefreshLayout + RecyclerView
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
@kamikat
kamikat / RxLocation.java
Created September 5, 2016 07:17
RxJava implementation to locate user with http://ip.taobao.com/service/getIpInfo.php?ip=myip
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import rx.Observable;
import rx.Scheduler;
@kamikat
kamikat / AVUpdateUtils.java
Last active March 29, 2019 06:34
Auto-upgrade module for Android apps using LeanCloud SDK and RxJava.
public class AVUpdateUtils {
public static final long RESULT_OK = 0L;
public static final long RESULT_CANCEL = 1L;
public static final long RESULT_INSTALLING = 2L;
private static long downloadInBackground(Context context, String url, File file) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
@kamikat
kamikat / jupyter.js
Last active March 13, 2017 08:42
Jupyter configuration of editor/notebook code indent
// In editor console
Jupyter.editor.config.update({Editor: {codemirror_options: { indentUnit:2 }}})
// In notebook console
Jupyter.notebook.get_selected_cell().config.update({CodeCell: {cm_options: { indentUnit:2 }}})
@kamikat
kamikat / image64.sh
Last active January 31, 2024 06:08 — forked from puppybits/image64.sh
Create data URI image from Terminal command
#!/bin/sh
# Examples:
# ./image64.sh myImage.png
# outputs: data:image/png;base64,xxxxx
# ./image64.sh myImage.png -img
# outputs: <img src="data:image/png;base64,xxxxx">
append=""
if [[ "$1" == *.gif ]]; then
@kamikat
kamikat / typography.scss
Created December 1, 2016 07:46
SCSS font configuration using serif CJK fonts
@font-face {
font-family: "Kagami Serif";
src: local("Liberation Serif"),
local("Times New Roman"),
local("Times");
}
@font-face {
font-family: "Kagami Songti SC";
src: local("Songti SC Regular"), local(STSongti-SC-Regular), // OS X 10.8
@kamikat
kamikat / esp8266-prelude.py
Created December 22, 2016 06:32
A prelude script to easy access filesystem & network functionalities for MicroPython on ESP8266.
# utility
logfile = None
def debug(*objects):
print(*objects)
if logfile:
print(*objects, file=logfile, flush=True)
def format_hex(bs, delim=''):