Skip to content

Instantly share code, notes, and snippets.

View bitristan's full-sized avatar
😀
happy coding everyday

Ting Sun bitristan

😀
happy coding everyday
View GitHub Profile
@bitristan
bitristan / build.gradle
Created June 9, 2015 03:13
use gradle upload library to bintrary
//classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
//classpath 'com.github.dcendents:android-maven-plugin:1.2'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version '1.5.0'
android {
@bitristan
bitristan / ViewController.m
Created June 17, 2015 02:47
IOS autolayout code snippet
//
// ViewController.m
// AutoLayoutDemo
//
// Created by Ting Sun on 6/17/15.
// Copyright (c) 2015 sunting. All rights reserved.
//
#import "ViewController.h"
@bitristan
bitristan / api.go
Created July 14, 2015 02:31
Send get and post request by golang
//发送get请求
func get(url string) string {
response, err := http.Get(url)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
@bitristan
bitristan / BLEPeripheral.java
Created July 15, 2015 11:57
Create a ble peripheral service
package com.example.android.bluetoothleadvertiser;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattServer;
import android.bluetooth.BluetoothGattServerCallback;
import android.bluetooth.BluetoothGattService;
private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
Log.v(TAG, "Connection State Changed: " + (newState == BluetoothProfile.STATE_CONNECTED ? "Connected" : "Disconnected"));
if (newState == BluetoothProfile.STATE_CONNECTED) {
setState(State.CONNECTED);
gatt.discoverServices();
} else {
setState(State.IDLE);
@bitristan
bitristan / exists.go
Created September 2, 2015 09:00
Check file exists.
package main
import (
"log"
"os"
)
var (
fileInfo *os.FileInfo
err error
@bitristan
bitristan / RecognitionTaskType.java
Created September 6, 2015 11:53
android aidl enum parameter
public enum RecognitionTaskType implements Parcelable {
HOTWORD,
OFFLINE,
ONLINE,
MIX,
RECORD_ONLY;
@Override
public int describeContents() {
return 0;
@bitristan
bitristan / GetCurrentProcessName.java
Created September 7, 2015 08:42
Get current process name.
private String getCurrentProcessName() {
String processName = "";
int pid = android.os.Process.myPid();
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == pid) {
processName = processInfo.processName;
break;
}
}
@bitristan
bitristan / RecycleBitmap.java
Created October 16, 2015 08:58
Recycle ImageView Bitmap
//Recycle src of ImageView
private static void recycleImageViewBitMap(ImageView imageView) {
if (imageView != null) {
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
rceycleBitmapDrawable(bd);
}
}
private static void rceycleBitmapDrawable(BitmapDrawable bitmapDrawable) {
if (bitmapDrawable != null) {
@bitristan
bitristan / CompressUtil.java
Created October 29, 2015 15:28
compress util
package com.zc.logger.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;