Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bukachi michaelbukachi

View GitHub Profile
@michaelbukachi
michaelbukachi / sentence_fixer.py
Last active Jun 9, 2017
A script to correct sentences
View sentence_fixer.py
import re
def replace(match):
if match:
phrase = match.group(0)
symbol = match.group(1)
return symbol + ' ' + phrase[-1].upper() if symbol is '.' else phrase[-1]
def parse(string):
string = re.sub(r'([\.\,\?\:\;])\w', replace, string) # add space between any punctuation symbol and letter
View ExcelParser.java
package dita.dev.myportal.utils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
@michaelbukachi
michaelbukachi / PersistentCookieStore.java
Last active Dec 18, 2017
Java persistent cookie storage using the gson library.
View PersistentCookieStore.java
/**
* Checkout https://gist.github.com/Triodes/b54aea95aceeb160c23d for an android implementation
*
**/
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.io.FileNotFoundException;
import java.io.FileReader;
@michaelbukachi
michaelbukachi / clear.sh
Created Jan 20, 2018
Git remove ignored files from Git index
View clear.sh
#!/bin/bash
git rm -r --cached .
git add .
git commit -am "Remove ignored files"
@michaelbukachi
michaelbukachi / MainActivity.java
Created Jun 10, 2018
Spinner Custom Object Example
View MainActivity.java
import android.os.Bundle;
import android.support.v4.util.ArrayMap;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity {
@michaelbukachi
michaelbukachi / Auth.java
Created Jul 24, 2018
Mocking of asynchronous call
View Auth.java
public static class Auth {
private static Auth auth;
private static String baseUrl;
private String message = null;
public static Auth getInstance(String base) {
baseUrl = base;
if (auth == null) {
auth = new Auth();
View CoroutinesTest.kt
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.junit.Test
class CoroutinesTest {
@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']
@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 / 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/