Skip to content

Instantly share code, notes, and snippets.

@labibmuhajir
labibmuhajir / usb.java
Last active May 16, 2025 09:33
android usb
/**
implementation 'com.github.mik3y:usb-serial-for-android:3.4.6'
*/
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
UsbSerialProber prober = UsbSerialProber.getDefaultProber();
List<UsbSerialDriver> availableDrivers = prober.findAllDrivers(usbManager);
if (availableDrivers.isEmpty()) {
@labibmuhajir
labibmuhajir / print.kt
Created May 5, 2025 06:32
java swing print
try {
val services = PrintServiceLookup.lookupPrintServices(null, null)
val printer = services.find {
it.name.lowercase().contains("star")
} ?: throw Exception("No printer")
val outputStream = ByteArrayOutputStream()
outputStream.write(byteArrayOf(27, 64)) // Initialize printer (ESC @)
outputStream.write("=== STRUK PEMBELIAN ===\n".toByteArray(charset("UTF-8")))
outputStream.write("Item 1 x2 Rp10.000\n".toByteArray(charset("UTF-8")))
@labibmuhajir
labibmuhajir / user.py
Created August 23, 2024 02:54
Create super user in cpanel
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectdir.settings")
import django
django.setup()
from django.contrib.auth.models import User
@labibmuhajir
labibmuhajir / .htaccess
Created July 12, 2024 04:01
2 htaccess php cpanel
# htdocs/
# ├─ public/
# │ └─.htaccess //second file
# │
# ├─ src/
# └─.htaccess //first file
# first .htaccess in root host folder
RewriteEngine On
@labibmuhajir
labibmuhajir / .htaccess
Created July 11, 2024 10:07 — forked from alch/.htaccess
Symfony full .htaccess file
# For a symfony application to work properly, you MUST store this .htaccess in
# the same directory as your front controller, index.php, in a standard symfony
# web application is under the "public" project subdirectory.
# Use the front controller as index file.
DirectoryIndex index.php
# Uncomment the following line if you install assets as symlinks or if you
# experience problems related to symlinks when compiling LESS/Sass/CoffeScript.
# Options +FollowSymlinks
@labibmuhajir
labibmuhajir / DefaultLinkMovementMethod.java
Created January 17, 2024 08:45 — forked from alexzaitsev/DefaultLinkMovementMethod.java
How to display HTML using Android Compose
/**
* Set this on a textview and then you can potentially open links locally if applicable
*/
public class DefaultLinkMovementMethod extends LinkMovementMethod {
private OnLinkClickedListener mOnLinkClickedListener;
public DefaultLinkMovementMethod(OnLinkClickedListener onLinkClickedListener) {
mOnLinkClickedListener = onLinkClickedListener;
}
@labibmuhajir
labibmuhajir / Compose.kt
Created October 19, 2023 08:28
compose in xml xml in compose
//If you want to use a Compose in your XML file, you can add this to your layout file:
<androidx.compose.ui.platform.ComposeView
android:id="@+id/my_composable"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
//and then, set the content:
@labibmuhajir
labibmuhajir / .bash_profile
Created April 11, 2023 06:50
.bash_profile
export NVM_DIR=~/.nvm
export PATH=~/Library/Android/sdk/tools:$PATH
export PATH=~/Library/Android/sdk/platform-tools:$PATH
export PATH=/Library/flutter/bin:$PATH
source $(brew --prefix nvm)/nvm.sh
@labibmuhajir
labibmuhajir / .htaccess
Created March 23, 2023 04:48
htaccess for react
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(assets/?|$)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
@labibmuhajir
labibmuhajir / Sha256.kt
Created October 13, 2022 08:12
sha-256
fun String.getSha256(): String {
val digest = MessageDigest.getInstance("SHA-256").apply { reset() }
val byteData: ByteArray = digest.digest(toByteArray())
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Base64.getEncoder().encodeToString(byteData)
} else {
String(
android.util.Base64.encode(byteData, android.util.Base64.DEFAULT),
StandardCharsets.UTF_8
)