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 / repopick.py
Created December 11, 2019 07:15
download topics from gerrit.
#!/usr/bin/env python
#
# Copyright (C) 2013-15 The CyanogenMod Project
# (C) 2017 The LineageOS Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
private static final String HTTP_END = "\r\n";
private static final String HTTP_START = "--";
private static final String HTTP_BOUNDARY = "*******";
private boolean uploadFileToServer(File file) {
if (file == null || !file.exists()) {
LogUtil.d(TAG, "file not exists, ignore upload.");
return true;
}
@bitristan
bitristan / queue.py
Created April 10, 2020 05:41
八皇后问题
N = 8
def isVaild(path, dcolumn):
drow = len(path)
for row, column in enumerate(path):
if column + drow - row == dcolumn:
return False
if column - (drow - row) == dcolumn:
return False
return True
@bitristan
bitristan / jdk_alternative
Last active June 1, 2021 07:14
Add jdk version
1 #!/bin/bash
2
3 sudo update-alternatives --install /usr/bin/java java /home/sunting/tools/jdk1.8.0/bin/java 1070
4 sudo update-alternatives --install /usr/bin/javac javac /home/sunting/tools/jdk1.8.0/bin/javac 1070
5 sudo update-alternatives --install /usr/bin/jar jar /home/sunting/tools/jdk1.8.0/bin/jar 1070
6 sudo update-alternatives --install /usr/bin/javah javah /home/sunting/tools/jdk1.8.0/bin/javah 1070
7 sudo update-alternatives --install /usr/bin/javap javap /home/sunting/tools/jdk1.8.0/bin/javap 1070
import android.media.AudioFormat
import android.media.AudioRecord
import android.media.MediaRecorder
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.View
import android.widget.Button
import java.io.*
@bitristan
bitristan / ContactUtil.kt
Created July 31, 2020 03:17
读写通讯录
import android.app.Activity
import android.content.*
import android.database.Cursor
import android.provider.ContactsContract
import android.util.Log
object ContactUtil {
private const val TAG = "ContactUtil"
fun getContacts(context: Context): StringBuilder {
@bitristan
bitristan / minigrep.rs
Last active August 1, 2020 03:34
minigrep demo from rust book.
use std::env;
use std::process;
use std::fs;
use std::error::Error;
fn main() {
let args: Vec<String> = env::args().collect();
let config = Config::new(&args).unwrap_or_else(|err|{
println!("Problem parsing arguements: {}", err);
@bitristan
bitristan / MyLinearLayoutManager.java
Created February 8, 2021 07:13
A simple cusstom linearlayout manager
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
public class MyLinearLayoutManager extends RecyclerView.LayoutManager {
private int mOffsetY = 0;
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
@bitristan
bitristan / ExampleUnitTest.java
Created June 30, 2021 10:30
Create hello world by asm tool
public class ExampleUnitTest {
@Test
public void helloWorldByAsm() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_8, ACC_PUBLIC, "Hello", null, "java/lang/Object", null);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC,
"main", "([Ljava/lang/String;)V", null, null);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("Hello, World");
@bitristan
bitristan / gradle_user_guide_note.md
Created July 21, 2021 07:48
gradle reference note
  1. When Gradle executes a Groovy build script (.gradle), it compiles the script into a class which implements Script. This means that all of the properties and methods declared by the Script interface are available in your script.

  2. When Gradle executes a Kotlin build script (.gradle.kts), it compiles the script into a subclass of KotlinBuildScript. This means that all of the visible properties and functions declared by the KotlinBuildScript type are available in your script. Also see the KotlinSettingsScript and KotlinInitScript types respectively for settings scripts and init scripts.

  3. An important feature of the resulting file collections is that they are live. In other words, when you combine file collections in this way, the result always reflects what’s currently in the source file collections, even if they change during the build.

  4. Define custom gradle plugin

plugins {
    `java-gradle-plugin`