Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bukachi michaelbukachi

View GitHub Profile
View LocationUtils.kt
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.*
View pycharm-precommit-fix.md
View multithread.py
import threading
import time
def func1():
print('Starting func 1')
end_time = time.time() + 5
i = 0
while time.time() < end_time:
@michaelbukachi
michaelbukachi / admin.py
Last active Mar 15, 2020
Flask-Admin with `autocommit=True`
View admin.py
'''
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)
@michaelbukachi
michaelbukachi / forkdelta.py
Last active Jan 14, 2020
Forkdelta example
View forkdelta.py
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 / async.kt
Created Dec 4, 2019
callback to kotlin coroutine
View async.kt
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 / dialog.kt
Created Sep 19, 2019
Alert Dialog overlay color
View dialog.kt
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 / credentialshelper.sh
Last active Aug 26, 2019
Docker credentials helper linux setup
View credentialshelper.sh
#!/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 / realm.kt
Created May 8, 2019
Get realm instance
View realm.kt
fun getRealm(context: Context): Realm {
try {
Realm.init(get())
} catch (e: Exception) {
}
val config = RealmConfiguration.Builder()
.schemaVersion(1)
.migration(Migration())
.build()
@michaelbukachi
michaelbukachi / file.py
Last active Jan 11, 2019
Mongoengine case insensitive query with _in operator
View file.py
import operator
from functools import reduce
from mongoengine import Document, Q, StringField
class Person(Document):
name = StringField()
names = ['mike', 'John', 'JIMMY']