Skip to content

Instantly share code, notes, and snippets.

tableView.deselectRowAtIndexPath(indexPath, animated: true)
@lawrenceching
lawrenceching / launch-softinput-after-activity-start.java
Last active May 16, 2016 09:07
Activity 启动后自动弹出软键盘
@Override
protected void onResume() {
super.onResume();
final Handler handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
EditText et = (EditText) findViewById(android.R.id.text1);
et.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@lawrenceching
lawrenceching / Convert string to NSDate.swift
Created May 24, 2016 18:30
[Swift] Convert string to NSDate
let strDate = "2016-06-01T00:00:00Z"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = dateFormatter.dateFromString(strDate)
@lawrenceching
lawrenceching / Format the number format.swift
Created June 3, 2016 04:43
Format the number, turn 3 into 3.00 or 033
import Foundation
extension Int {
func format(f: String) -> String {
return String(format: "%\(f)d", self)
}
}
extension Double {
func format(f: String) -> String {
@lawrenceching
lawrenceching / read-file-in-clojure.clj
Created June 18, 2017 16:51
Reading file in Clojure
(ns hello-clojure.core
(:use [clojure.test]))
(require '[
clojure.java.io :as io
] )
(def path "./resources/test/hello.txt")
(defn read-file [path]
@lawrenceching
lawrenceching / kotlin.kt
Last active July 25, 2019 16:51
hello-kotlin
package com.example
import java.util.*
import kotlinx.coroutines.*
import kotlin.system.measureTimeMillis
val title = "Kotlin Demo"
var content = "A 20-mins Kotlin sharing"
var optional: String? = null
// Refer to https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
crypto.getRandomValues(new Uint8Array(5)).map(i => i%100)
// Uint8Array(5) [21, 54, 59, 41, 79]
@lawrenceching
lawrenceching / pull-docker-images-and-retag.sh
Created March 16, 2020 15:38
Pull Kubernetes images from Azure mirror registry and retag them
images=(
kube-apiserver:v1.17.4
kube-controller-manager:v1.17.4
kube-scheduler:v1.17.4
kube-proxy:v1.17.4
pause:3.1
etcd:3.4.3-0
coredns:1.6.5
)
TC_TOKEN=<Teamcity Token>
curl -X POST -H "Authorization: Bearer $TC_TOKEN" \
--header "Content-Type:application/xml" \
-d"
<build>
<buildType id=\"<TeamCity Build ID>\"/>
<properties>
<property name=\"<Parameter Name>\" value=\"<Parameter Value>\"/>
</properties>
</build>
@lawrenceching
lawrenceching / Tracker.kt
Last active September 9, 2020 17:07
A util class to measure how much a operation take
package me.imlc.example
import java.lang.StringBuilder
import java.util.*
class Tracker {
data class Tick(val name:String, val timeInMillis: Long)