Skip to content

Instantly share code, notes, and snippets.

View michaelbukachi's full-sized avatar

Michael Bukachi michaelbukachi

View GitHub Profile
@michaelbukachi
michaelbukachi / realm.kt
Created May 8, 2019 09:24
Get realm instance
fun getRealm(context: Context): Realm {
try {
Realm.init(get())
} catch (e: Exception) {
}
val config = RealmConfiguration.Builder()
.schemaVersion(1)
.migration(Migration())
.build()
@michaelbukachi
michaelbukachi / credentialshelper.sh
Last active August 26, 2019 12:00
Docker credentials helper linux setup
#!/usr/bin/env bash
sudo apt install libsecret-1-0
wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.3/docker-credential-secretservice-v0.6.3-amd64.tar.gz && tar -xf docker-credential-secretservice-v0.6.3-amd64.tar.gz && chmod +x docker-credential-secretservice && mv docker-credential-secretservice /usr/local/bin/
@michaelbukachi
michaelbukachi / dialog.kt
Created September 19, 2019 09:28
Alert Dialog overlay color
val dialog = Dialog(context!!)
// val dialog = AlertDialog(context!!)
dialog.window?.setBackgroundDrawableResource(android.R.color.black)
// dialog.window?.setBackgroundDrawable(ColorDrawable(Color.BLACK))
dialog.show()
@michaelbukachi
michaelbukachi / async.kt
Created December 4, 2019 13:37
callback to kotlin coroutine
interface Callback<S> {
fun success(s: S)
fun error(e: Exception)
}
fun<T> doSomethingLong(callback: Callback<T>) {
}
private suspend fun <T> someFuncAwait() :T = suspendCancellableCoroutine {
@michaelbukachi
michaelbukachi / forkdelta.py
Last active January 14, 2020 08:44
Forkdelta example
import websockets
import asyncio
async def hello():
uri = 'wss://api.forkdelta.app/socket.io/'
async with websockets.connect(uri,) as websocket:
# await websocket.send('getMarket')
await websocket.send('getMarket')
res = await websocket.recv()
@michaelbukachi
michaelbukachi / admin.py
Last active November 25, 2021 10:40
Flask-Admin with `autocommit=True`
'''
This workaround helps avoid:
sqlalchemy.exc.InvalidRequestError: No transaction is begun
whenever you try to create/update a model when `autocommit=True`
'''
class BaseModelView(ModelView):
def create_model(self, form):
self.session.begin()
super(BaseModelView, self).create_model(form)
import threading
import time
def func1():
print('Starting func 1')
end_time = time.time() + 5
i = 0
while time.time() < end_time:
@michaelbukachi
michaelbukachi / pycharm-precommit-fix.md
Last active June 8, 2023 15:37
Pycharm precommits fix
package farmdrive.ripe.utils
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.location.Location
import androidx.core.app.ActivityCompat
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.gms.location.*