Skip to content

Instantly share code, notes, and snippets.

View kinsleykajiva's full-sized avatar
🏠
Working from home

Kinsley Kajiva kinsleykajiva

🏠
Working from home
  • Africa
  • 10:42 (UTC +02:00)
View GitHub Profile
@kinsleykajiva
kinsleykajiva / OkHttpProgressGlideModule.java
Created January 21, 2017 10:58 — forked from TWiStErRob/OkHttpProgressGlideModule.java
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@kinsleykajiva
kinsleykajiva / autocorrrect.py
Created April 18, 2017 12:26 — forked from bgreenlee/autocorrrect.py
Simple ngram autocorrect #python #algorithms
import os.path
import collections
from operator import itemgetter
WORDFILE = '/usr/share/dict/words'
class Autocorrect(object):
"""
Very simplistic implementation of autocorrect using ngrams.
"""
@kinsleykajiva
kinsleykajiva / PrimaryKeyFactory.java
Created April 20, 2017 05:40 — forked from cmelchior/PrimaryKeyFactory.java
Helper class for creating auto increment keys for Realm model classes
/*
* Copyright 2017 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@kinsleykajiva
kinsleykajiva / RealmAssetLoaderHelperMethods.java
Last active April 20, 2017 06:30 — forked from cmelchior/HelperMethods.java
Load new Realm file from assets when a migration is required
public Realm loadAssetFileOnMigration() {
// TODO Don't re-create this every time
RealmConfiguration config = new RealmConfiguration.Builder()
.schemaVersion(2) // Bumping the schema because new app
.build();
Realm realm;
try {
realm = Realm.getInstance(config);
import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class TripleDESTest {
@kinsleykajiva
kinsleykajiva / password_pattern.txt
Created September 10, 2017 07:29 — forked from yogonza524/password_pattern.txt
Java pattern for password
((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%-_.]).{6,32})
@kinsleykajiva
kinsleykajiva / Movable JavaFX Window.java
Created September 12, 2017 05:34 — forked from k33ptoo/Movable JavaFX Window.java
Renders a borderless/underdecorated window movable/dragable
/*
* The MIT License
*
* Copyright 2017 keeptoo.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Answer for http://stackoverflow.com/questions/31681732/lodash-get-duplicate-values-from-an-array">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@kinsleykajiva
kinsleykajiva / group-objects-by-property.md
Created March 25, 2019 02:32 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">