Skip to content

Instantly share code, notes, and snippets.

View bmbariah's full-sized avatar
🌍

Boniface Mbaria bmbariah

🌍
View GitHub Profile
@bmbariah
bmbariah / regex.js
Last active March 24, 2020 17:39
Safaricom Regex for Phone Numbers Prefixes Regex ~ Feb 2020
const phone_re = /^(\+){0,1}(254){0,1}(70|71|72|79)(\d{7})|(254){0,3}(740|741|742|743|745|746|748|757|758|759|768|769|110|111)(\d{6})$/;
// See test cases here
// https://regex101.com/r/vuPu6k
@bmbariah
bmbariah / bitbucket-pipelines.yml
Created November 5, 2019 08:20
Bitbucket Pipeline android upload apk to slack
image: mingc/android-build-box:1.12.0
pipelines:
branches:
master:
- step:
caches:
- gradle
- gradlewrapper
- androidavd
@AdamMc331
AdamMc331 / AppDatabase.kt
Created September 16, 2017 18:53
Shows how a RoomDatabase.Callback can be used to add database triggers when a database is created.
@Database(...)
abstract class AppDatabase : RoomDatabase() {
abstract fun appDao(): AppDao
companion object {
private var INSTANCE: AppDatabase? = null
private set
fun getInMemoryDatabase(context: Context): CCDatabase {
if (INSTANCE == null) {
@SanderTheDragon
SanderTheDragon / postman-deb.sh
Last active June 11, 2024 10:46
A shellscript to create a Postman .deb file, for simple installation on Debian-based Linux distro's. Also creates a .desktop file.
#!/bin/sh
# SPDX-FileCopyrightText: 2017-2024 SanderTheDragon <sanderthedragon@zoho.com>
#
# SPDX-License-Identifier: MIT
arch=$(dpkg --print-architecture)
echo "Detected architecture: $arch"
case "$arch" in
@zcaceres
zcaceres / Include-in-Sequelize.md
Last active January 8, 2024 07:14
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query

@JosiasSena
JosiasSena / DeCryptor.java
Last active September 12, 2023 12:40
Encryptor and Decryptor for data encryption.decryption using the Android KeyStore.
/**
_____ _____ _
| __ \ / ____| | |
| | | | ___| | _ __ _ _ _ __ | |_ ___ _ __
| | | |/ _ \ | | '__| | | | '_ \| __/ _ \| '__|
| |__| | __/ |____| | | |_| | |_) | || (_) | |
|_____/ \___|\_____|_| \__, | .__/ \__\___/|_|
__/ | |
|___/|_|
*/
@rajendarreddyj
rajendarreddyj / DbeaverStringEncrypter.java
Created January 25, 2017 22:36
program to decrypt password values in .dbeaver-data-sources.xml
package com.rajendarreddyj.java;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.Arrays;
/**
@destan
destan / ParseRSAKeys.java
Last active June 25, 2024 15:21
Parse RSA public and private key pair from string in Java
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
@benwells
benwells / reduce-example.js
Created May 12, 2016 13:40
Using Array.reduce to sum a property in an array of objects
var accounts = [
{ name: 'James Brown', msgCount: 123 },
{ name: 'Stevie Wonder', msgCount: 22 },
{ name: 'Sly Stone', msgCount: 16 },
{ name: 'Otis Redding', msgCount: 300 } // Otis has the most messages
];
// get sum of msgCount prop across all objects in array
var msgTotal = accounts.reduce(function(prev, cur) {
return prev + cur.msgCount;
@Tetr4
Tetr4 / ForceCacheOrNetwork.java
Last active February 1, 2020 05:17
How to force a cached or network response on Android with Retrofit + OkHttp
OkHttpClient okHttpClient = new OkHttpClient();
try {
int cacheSize = 10 * 1024 * 1024 // 10 MiB
Cache cache = new Cache(getCacheDir(), cacheSize);
okHttpClient.setCache(cache);
} catch (IOException e) {
Log.e(TAG, "Could not set cache", e);
}
// Forces cache. Used for cache connection