Skip to content

Instantly share code, notes, and snippets.

@mingcheng
mingcheng / uutils.fish
Created March 24, 2025 01:47
Replace coreutils by uutils-coreutils in fish shell script
# Check that the uutils are available in the current search paths
if not command -sq uhostid
echo "The uutils are not installed or not in the PATH variable. Adapt the script." >&2
exit 1
end
# --- uutils-coreutils Aliasing ---
# Function to check if uutils command exists
function _uutils_command_exists
package main
import (
"fmt"
"log"
"net"
)
func main() {
addrs, err := net.InterfaceAddrs()
public class HelloWorld {
public static void main(String[] args) {
var greet = "Hello, world!";
System.out.println(greet);
}
}
@mingcheng
mingcheng / gist:835238415f94c2c35285
Created December 19, 2014 01:51
SQLite 获取和删除重复的数据
# 获取重复的数据
select title, id, count(*) as count from eslpod group by title having count(*) > 1;
# 删除重复的数据,其中 rowid 为 sqlite 自带字段
delete from eslpod where eslpod.rowid not in (select max(eslpod.rowid) from eslpod group by
title);
@mingcheng
mingcheng / gist:5472680
Created April 27, 2013 10:55
Android/Java equivalent of MD5 function in PHP
public static String md5(String string) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Huh, MD5 should be supported?", e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e);
}
@mingcheng
mingcheng / gist:4473364
Last active December 10, 2015 18:18
在 Android 设备中发起 HTTP GET 请求
String response = "";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
@mingcheng
mingcheng / gist:4460417
Created January 5, 2013 07:58
淘宝的 IP 地址请求库
http://greencompute.org/instructions.php
1. 请求接口(GET):
http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串]
2. 响应信息:
(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商
3. 返回数据格式:
@mingcheng
mingcheng / gist:4173722
Created November 30, 2012 04:07
Android 检查网络状态
public void myClickHandler(View view) {
...
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
// fetch data
} else {
// display error
}
@mingcheng
mingcheng / gist:4173614
Created November 30, 2012 03:33
remount android partition for read/write
The commands for mounting the partition and copying the old build.prop from the root of your sdcard are:
$su
# mount -ro remount,rw /system
You don't need to use those though if you are using an app that gets root access.
@mingcheng
mingcheng / gist:4152074
Created November 27, 2012 02:48
Gets the data from a URL
/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
curl_setopt($ch, CURLOPT_REFERER, $url);
$data = curl_exec($ch);