Skip to content

Instantly share code, notes, and snippets.

View xionglun's full-sized avatar

Jafar Stein xionglun

  • TBD
  • Freedom, China
View GitHub Profile
@xionglun
xionglun / foo.service
Created February 15, 2017 07:55
Use systemd's timer
[Unit]
Description=A timer service
[Service]
Type=simple
ExecStart=/bin/echo 'Hello, timer'
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=mytimer
@xionglun
xionglun / txt.go
Created December 29, 2016 01:40
Golang retrieve one domain's TXT record via custom DNS.
package main
import (
"fmt"
"time"
"github.com/miekg/dns"
)
func queryTXT(resolve, domain string) (txt string) {
@xionglun
xionglun / Dev.Dockerfile
Last active April 23, 2018 07:33
Docker Usage
FROM alpine
RUN echo "@testing http://dl-4.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk update \
&& apk --no-cache --no-progress add \
bash \
make \
wget \
git \
@xionglun
xionglun / rsa.sh
Created January 6, 2016 05:31
openssl RSA key & crt generator
#!/usr/bin/env bash
openssl req -new -newkey rsa:2048 -nodes -out hello_abc_com.csr -keyout hello_abc_com.key -subj "/C=US/ST=New York/L=New York/O=ABC Inc./OU=IT/CN=hello.abc.com"
openssl x509 -req -days 365 -in hello_abc_com.csr -signkey hello_abc_com.key -out hello_abc_com.crt
@xionglun
xionglun / osVersion
Created November 4, 2014 14:01
iOS swift detect OS version
switch UIDevice.currentDevice().systemVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch) {
case .OrderedSame, .OrderedDescending:
println("iOS >= 8.0")
case .OrderedAscending:
println("iOS < 8.0")
}
var userAgent = navigator.userAgent.toLowerCase();
var browser = {
version: (userAgent.match(/.+(?:rv|it|ra|ie|me|on)[\/: ]([\d.]+)/) || [])[1],
chrome: /chrome/.test(userAgent),
safari: /webkit/.test(userAgent) && !/chrome/.test(userAgent ),
webkit: /webkit/.test(userAgent),
opera: /opera/.test(userAgent),
msie: /msie/.test(userAgent) && !/opera/.test(userAgent ),
mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent ),
@xionglun
xionglun / android_listview_transparent.md
Created June 11, 2014 18:22
Android listview transparent

How to make a ListView transparent in Android?

In xml:

  android:background="@android:color/transparent"
  android:cacheColorHint="@android:color/transparent"

In java:

@xionglun
xionglun / android_custom_user_agent.md
Created June 10, 2014 17:39
Android WebView custom User-Agent

At Activity:

  //...
  webView.getSettings().setUserAgentString("CUSTOM_USE_AGENT");
  //...
@xionglun
xionglun / android_webview.md
Last active August 29, 2015 14:02
Android WebView EventHub.removeMessages(int what = 107)

WebView Lifecycle

We ran into a problem when leaving the activity. WebView will display the following message in logcat:

EventHub.removeMessages(int what = 107) is not supported before WebViewCore is set up

To prevent this message from showing up use WebView stopLoading() method:

  // !!! This method is wrong!
  // !!! Do not solve problem
  @Override
 public void onStop() {
@xionglun
xionglun / proguard-project
Created May 30, 2014 10:50
Android Proguard Example
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*