Skip to content

Instantly share code, notes, and snippets.

View ozgurg's full-sized avatar
🏠
Working from home

Özgür Görgülü ozgurg

🏠
Working from home
View GitHub Profile
@ozgurg
ozgurg / StringToColorConverter.js
Created June 11, 2024 23:59
JS StringToColorConverter (Ported with minor adjustments by ChatGTP 4o from https://github.com/shahonseven/php-color-hash)
class StringToColorConverter {
static L = [
0.35,
0.5,
0.65
];
static S = [
0.35,
0.5,
0.65
@ozgurg
ozgurg / MarginItemDecoration.kt
Created May 27, 2024 21:49
Android RecyclerView Item Decoration : Equal Margin + Auto Span Count + Auto Orientation
import android.graphics.Rect
import android.view.View
import androidx.annotation.Px
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MarginItemDecoration(
@Px private val marginInPixels: Int
) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
@ozgurg
ozgurg / remove-last-line.css
Created May 12, 2024 00:31
Ionic: Remove the last line of the ion-list
/* Tested on Ionic 8. */
/* The `px` suffix might be required to avoid breaking inside the calculation of Ionic. */
ion-list ion-item:last-child {
--border-width: 0px !important;
--inner-border-width: 0px !important
}
@ozgurg
ozgurg / DateTimePicker.kt
Last active April 21, 2023 22:53
Android DateTimePicker (MaterialDatePicker + MaterialTimePicker)
import androidx.fragment.app.FragmentManager
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.timepicker.MaterialTimePicker
import java.util.Calendar
class DateTimePicker(
private val datePicker: MaterialDatePicker<Long>,
private val timePicker: MaterialTimePicker
) {
private var onDateTimeSelectedListener: ((dateTime: DateTime) -> Unit)? = null
@ozgurg
ozgurg / mapTypedArray.kt
Created April 15, 2023 23:58
Kotlin mapTypedArray
inline fun <reified IT, reified OT> Array<IT>.mapTypedArray(transform: (IT) -> OT): Array<OT> {
return map(transform).toTypedArray()
}
@ozgurg
ozgurg / FullScreenDialogFragment.kt
Last active April 14, 2023 19:12
Android Material 3 Full Screen Dialog Style (Dark + Light Theme)
class FullScreenDialogFragment : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.Theme_App_FullScreenDialog)
}
}
(() => {
"use strict";
let files = null;
window.addEventListener("paste", (event) => {
files = event.clipboardData.files;
document.querySelector('[aria-label="Search by image"]').click();
@ozgurg
ozgurg / RealPathUtil.java
Created August 18, 2022 23:48 — forked from tatocaster/RealPathUtil.java
Real Path Utility class for Android, works for all API
import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
@ozgurg
ozgurg / Extensions.kt
Created August 16, 2022 23:38
Useful Kotlin extensions
fun <T> MutableList<T>.addOrRemove(item: T) {
if (this.contains(item)) {
this.remove(item)
} else {
this.add(item)
}
}
fun <T> MutableList<T>.findIndex(predicate: (T) -> Boolean): Int {
val item = this.find(predicate)
@ozgurg
ozgurg / io.js
Last active August 15, 2022 14:27
Node.js type="module" path and fs helper. Put the file in the root folder
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { createReadStream, createWriteStream, existsSync, readFileSync, unlinkSync } from "fs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const io = Object.freeze({
join,
existsSync,