Skip to content

Instantly share code, notes, and snippets.

View Tamkien's full-sized avatar
👨‍💻

Cao Tam Kiên Tamkien

👨‍💻
View GitHub Profile
@Tamkien
Tamkien / Baitap.java
Created July 18, 2019 09:08
Bai tap String
import java.util.*;
public class Baitap {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
for (; ; ) {
System.out.println("Input String");
String s = scanner.nextLine();
s = s.trim().replaceAll("\\s+", " ");//Dong nay de xoa het dau cach thua (de dem tu)
@Tamkien
Tamkien / FakePhoneNo.java
Last active August 18, 2019 08:24
Một vài người trên phòng GD&ĐT huyện do không có việc làm nên đã bắt u mình nhập số điện thoại của phụ huynh học sinh trong 5 năm trở lại đây. Code này để cho họ thấy nhà mình có một kỹ sư.
import java.util.ArrayList;
import java.util.Random;
public class FakePhoneNo {
public static void main(String[] args) {
ArrayList<String> dauso = new ArrayList<>();
dauso.add("032");
dauso.add("033");
dauso.add("034");
dauso.add("035");

Keybase proof

I hereby claim:

  • I am tamkien on github.
  • I am tamkien (https://keybase.io/tamkien) on keybase.
  • I have a public key ASD5FUZGlsFBRLlVDdYY30Zmz3Hn0oWZCvAOJvtiJ3uCSAo

To claim this, I am signing this object:

@Tamkien
Tamkien / OnTouch.kt
Last active October 14, 2020 08:00
Kotlin code for creating OnTouchListener on a DrawableEnd
editTextNumber.setOnTouchListener(object : View.OnTouchListener{//editTextNumber is the id of my EditText that contains the drawable
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_UP){
if (event.rawX >= editTextNumber.right - editTextNumber.compoundDrawables[2].bounds.width()){ //*Why [2]? See below
Log.d("DrawableEnd", "Pressed")//Insert your action here
return true
}
}
return false
@Tamkien
Tamkien / onItemClick.kt
Created October 16, 2020 09:53
To create a simple dialog for each items of a recycleView.
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is EmployeeViewHolder) { //EmployeeViewHolder is my custom viewHolder to bind values
holder.bind(employees[position]) //employees is my list
holder.itemView.setOnClickListener {
val dialog = AlertDialog.Builder(it.context).create()
dialog.setTitle("Title")//your title here
dialog.setMessage("Message")//your message here
dialog.setButton(
AlertDialog.BUTTON_NEUTRAL, "OK" //a button labeled "OK"
) { _: DialogInterface, _: Int -> dialog.dismiss() }
@Tamkien
Tamkien / AddField.kt
Created October 20, 2020 06:45
A function to add a field (Calendar.SOMETHING) into a given date. To minus, put a negative number.
private fun Date.add(field: Int, amount: Int): Date = Calendar.getInstance().let { calendar ->
calendar.time = this@add
calendar.add(field, amount)
return@let calendar.time
}
@Tamkien
Tamkien / VietCalendar.kt
Last active February 26, 2023 23:20
A Kotlin object to convert Western Calendar (Solar Calendar) to Lunar Calendar. All kudos to Mr.Ho Ngoc Duc, the creator of the Java version.
//Java version: http://www.informatik.uni-leipzig.de/~duc/amlich/VietCalendar.java
import kotlin.math.floor
import kotlin.math.sin
object VietCalendar {
private const val PI = Math.PI
/**
*
#include <stdio.h>
int main()
{
int n,m,i,j;
float a[10][10];
printf("Nhap so hang ma tran");
scanf("%d", &m);
printf("Nhap so cot ma tran");
scanf("%d", &n);
@Tamkien
Tamkien / ADiDaPhat.txt
Created October 7, 2021 06:12
Đức Phật sẽ phù hộ độ trì cho đồ án của chúng tôi! A Di Đà Phật!
/////////////////////////////////////////////////////////
// //
// _oo0oo_ //
// o8888888o //
// 88" . "88 //
// (| -_- |) //
// 0\ = /0 //
// ___/`---'\___ //
// .' \\| |// '. //
// / \\||| : |||// \ //
@Tamkien
Tamkien / OneTimePasswordAlgorithm.java
Created March 4, 2022 11:38 — forked from bvermeule/ OneTimePasswordAlgorithm.java
HOTP Algorithm: Reference Implementation
/*
* OneTimePasswordAlgorithm.java
* OATH Initiative,
* HOTP one-time password algorithm
*
*/
/* Copyright (C) 2004, OATH. All rights reserved.
*
* License to copy and use this software is granted provided that it