Skip to content

Instantly share code, notes, and snippets.

View vinhdn's full-sized avatar

Vinh Do Ngoc vinhdn

  • Humaxdigital
  • Vietnam
  • 19:57 (UTC +07:00)
View GitHub Profile
@vinhdn
vinhdn / convert.kt
Created January 19, 2021 08:30
Convert string unicode to UTF-8
import java.util.regex.Matcher
import java.util.regex.Pattern
fun String.unicode(): String {
return unicodeToUtf8().unicodeToUtf8(16)
}
fun String.unicodeToUtf8(radix: Int = 10): String {
val p = Pattern.compile(if (radix == 10) "&#(\\d+);|." else "&#x(.+?);|.")
val sb = StringBuilder()
default android/drawable-mdpi/, 150% android/drawable-hdpi/, 200% android/drawable-xhdpi/, 300% android/drawable-xxhdpi/, 400% android/drawable-xxxhdpi/, 100% iphone/, 200% iphone/@2x, 300% iphone/@3x
@vinhdn
vinhdn / convertImageToWebp.py
Created January 22, 2020 02:37
convertImageToWebp.py
from PIL import Image
from os import rename, listdir
from webptools import webplib as webp
basewidth = 512
path = "webp"
fnames = listdir(path)
for fname in fnames:
if fname.startswith("sk") and fname.endswith(".png") and not fname.endswith("_temp.png"):
im = Image.new("RGBA", (basewidth, basewidth), 0)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
DELETE FROM sds;
INSERT INTO table1 (
column1,
column2 ,..)
VALUES
(value1,
value2 ,...),
(value1,
value2 ,...),
(value1,
@vinhdn
vinhdn / RealmHelper.java
Created September 18, 2017 09:33
Realm Helper Android
public class RealmHelper {
public static <T extends RealmObject> void save(T object) {
Realm realm = Realm.getDefaultInstance();
try {
realm.beginTransaction();
realm.copyToRealmOrUpdate(object);
realm.commitTransaction();
} finally {
realm.close();
}
@vinhdn
vinhdn / UnderLineTextView.java
Last active June 27, 2017 09:14
UnderlineTextView
package jp.mediaid.nge.library.categories.ui;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Build;
@vinhdn
vinhdn / scrollbar.java
Created June 21, 2017 03:13
Change color of scrollbar
public static void changeColorScrollBar(View Scroll, int color, Context cxt){
try
{
Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
mScrollCacheField.setAccessible(true);
Object mScrollCache = mScrollCacheField.get(Scroll);
Field scrollBarField = mScrollCache.getClass().getDeclaredField("scrollBar");
scrollBarField.setAccessible(true);
Object scrollBar = scrollBarField.get(mScrollCache);
@vinhdn
vinhdn / .bash_profile
Created June 21, 2017 03:11
Setup PATH in Macos
Step 1: Open up a Terminal window (this is in your Applications/Utilites folder by default)
Step 2: Enter the follow commands:
touch ~/.bash_profile; open ~/.bash_profile
This will open the .bash_profile file in Text Edit (the default text editor included on your system). The file allows you to customize the environment your user runs in.
Step 3: Add the following line to the end of the file adding whatever additional directory you want in your path:
@vinhdn
vinhdn / SHA.java
Created June 21, 2017 03:10
Get SHA
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);