Skip to content

Instantly share code, notes, and snippets.

View omarmiatello's full-sized avatar

Omar Miatello omarmiatello

View GitHub Profile
@omarmiatello
omarmiatello / LeetcodeUtils.kt
Created July 30, 2022 17:01
LeetCode Utils
fun String.toArrayOfIntArray(): Array<IntArray> = split("],[")
.map { it.split(",").map { it.filter { it.isDigit() }.toInt() } }
.map { it.toIntArray() }
.toTypedArray()
fun String.toArrayOfCharArray(): Array<CharArray> = split("],[")
.map { it.split(",").map { it.filter { it.isLetterOrDigit() }[0] } }
.map { it.toCharArray() }
.toTypedArray()
package com.github.omarmiatello.composeclub
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
@omarmiatello
omarmiatello / BarcodeAdvancedDetector.kt
Last active July 25, 2018 15:35
Barcode Detector for Mobile Vision API (Add support for inverted color)Benchmark on Pixel 2: Invert color (8ms) + Decode (15ms)
package com.satispay.customer.profile.visionapi
import android.graphics.ImageFormat
import android.util.SparseArray
import com.google.android.gms.vision.Detector
import com.google.android.gms.vision.Frame
import com.google.android.gms.vision.barcode.Barcode
import java.nio.ByteBuffer
@omarmiatello
omarmiatello / Yeelight.kt
Last active December 5, 2020 11:07
Yeelight API in Kotlin. Add support for multiple light!
package gdax.notification
import gdax.conf.App
import gdax.utils.logV
import kotlinx.coroutines.experimental.*
import java.io.BufferedOutputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.DatagramPacket
import java.net.DatagramSocket
@omarmiatello
omarmiatello / google-apps-script-slide-share-telegram-slack-multicountry.js
Last active June 4, 2021 17:44
Notification system! Add button in Google Presentation for share a single slide in a Telegram channel.
function onOpen() {
var ui = SlidesApp.getUi();
ui.createMenu('GDG Tools')
.addSubMenu(ui.createMenu('Share this slide on "GDG Italia"')
.addItem('Telegram (favorite)', 'shareItalyTelegram')
.addItem('Slack', 'shareItalySlack'))
.addSubMenu(ui.createMenu('Share this slide on "GDG Spain"')
.addItem('Telegram', 'shareSpainTelegram')
.addItem('Slack (favorite)', 'shareSpainSlack'))
.addToUi();
@omarmiatello
omarmiatello / EasyWS.kt
Last active June 4, 2024 13:37
First experiment with WebSocket and Kotlin Coroutine
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.launch
import okhttp3.*
import okio.ByteString
import kotlin.coroutines.experimental.suspendCoroutine
/**
* Created by omarmiatello on 17/06/17.
*/
@omarmiatello
omarmiatello / B.kt
Last active March 27, 2017 21:23
Bencode Encoder/Decoder in Kotlin (extended version) - https://en.wikipedia.org/wiki/Bencode
class B(val s:String, var i:Int=0) {
fun r(c:Int)=s.substring(i,i+c).apply{i+=length}
fun u(c:Char)=s.substring(i,s.indexOf(c,i)).apply{i+=length+1}
fun d():Any=when(r(1)[0]){
'e'->Unit;'i'->u('e').toInt()
'l'->ArrayList<Any>().apply{var o=d();while(o!=Unit){add(o);o=d()}}
'd'->HashMap<String,Any>().apply{var o=d();while(o!=Unit){put(o as String,d());o=d()}}
in('0'..'9')->r((s[i-1]+u(':')).toInt())
else->throw IllegalStateException("Char:${s[i-1]}")
}
@omarmiatello
omarmiatello / copy-android.py
Last active June 19, 2018 11:47
Copy icons from Material Design to your Android Project
# Instruction:
# - git clone https://google.github.io/material-design-icons/
# - Place and run this script inside the material-icons-master folder
#
# How to use (by example)
# python copy-android.py social notifications_none white 24dp ~/AndroidStudioProjects/my-project/app/src/main/res/
# or separate name with ',' multiple images from same group
# python copy-android.py social notifications_active,notifications,notifications_none,notifications_off,notifications_paused 24dp ~/AndroidStudioProjects/my-project/app/src/main/res/
#
# NOTE: You can search icons in https://www.google.com/design/icons/
@omarmiatello
omarmiatello / RxUtils.kt
Created July 27, 2015 10:14
Helper class for handle rx.Subscription in Activity/Fragment
package it.justonetouch.utils
import rx.Observable
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import rx.subscriptions.CompositeSubscription
import kotlin.properties.Delegates
/**
package com.example.android;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Loader;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;