Skip to content

Instantly share code, notes, and snippets.

View matteo-grella's full-sized avatar
🔥
I enjoy programming my own inventions.

Matteo Grella matteo-grella

🔥
I enjoy programming my own inventions.
View GitHub Profile
@matteo-grella
matteo-grella / NotEmptyOrNull.kt
Created May 12, 2019 22:05
Return the list if it is not empty, otherwise null
/**
* Return the list if it is not empty, otherwise null
*/
private fun <T>List<T>.notEmptyOrNull(): List<T>? = if (this.isEmpty()) null else this
@matteo-grella
matteo-grella / SplitToNChar.kt
Last active May 8, 2019 21:27
Split text into substrings of N characters.
/**
* Split text into substrings of [size] characters.
*
* @param size the split size.
* @return an array of the split text.
*/
private fun String.splitToNChar(size: Int): List<String> {
val parts = ArrayList<String>()
val length = this.length
/*
Yoshua Bengio:
My preferred style of moving average is the following. Let's say you
have a series x_t and you want to estimate the mean m of previous
(recent) x's:
m <-- m + (2/t) (x_t - m)
Note that with (1/t) learning rate instead of (2/t) you get the exact
@matteo-grella
matteo-grella / ByteArrayFromInt.kt
Created February 25, 2019 09:33
Transform an Integer to a Byte Array
/**
* Transform an Integer to a Byte Array.
*
* @param value the Integer
*
* @return the Byte Array
*/
internal fun getByteArrayFromInt(value: Int): ByteArray {
val mask = 0xFF // binary 1111 1111
@matteo-grella
matteo-grella / incrementalAverage.kt
Created March 28, 2018 21:25
Simple Method to Calculate the Incremental Average
fun incrementalAverage(previousAverage: Double, value: Double, iterationIndex: Int): Double {
return (value - previousAverage) / (iterationIndex + 1) + previousAverage
}
@matteo-grella
matteo-grella / GoogleMapsGeocodingHelper.kt
Created November 2, 2017 18:37
A Kotlin wrapper for the Google Maps Geocoding API v3
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*

Nice, compliant input boxes

Nice input box with a lot of styling based on sibling selectors and psuedo classes.

CSS only, and WCAG 2.0 AA compliant!

A Pen by Andrew Tunnecliffe on CodePen.

License.