Skip to content

Instantly share code, notes, and snippets.

View Wavesonics's full-sized avatar

Adam Brown Wavesonics

View GitHub Profile
@Wavesonics
Wavesonics / Optimus.kt
Created October 24, 2018 01:44
Kotlin implementation of Optimus integer hashing algorithm https://github.com/jenssegers/optimus
class Optimus(private val prime: Int,
private val randomNumber: Int,
private val modInverse: Int = ModInverse(prime))
{
init
{
if (!isProbablyPrime(prime)) throw IllegalArgumentException("$prime is not a prime number")
}
fun encode(n: Int): Int = n * this.prime and MAX_INT xor this.randomNumber
body:before {
background: url( {IMAGE} ) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
content: "";
display: block;
@Wavesonics
Wavesonics / RouteHelper.kt
Created September 11, 2018 06:19
Route helper with params
class RouteHelper(private val router: Router) : BasicValueHelper()
{
override fun execute(options: Options?)
{
if( options != null )
{
val parameters = options.parameters
if( parameters != null && parameters.isNotEmpty() )
{
val routeName = parameters[0] as String
@Wavesonics
Wavesonics / RouteHelper.kt
Created September 11, 2018 04:11
A very simple helper for reverse routes in templates
class RouteHelper(private val router: Router) : BasicValueHelper()
{
override fun execute(options: Options?)
{
options?.parameters?.get(0)?.let { routeName ->
val route = router.uriFor(routeName.toString(), mutableMapOf())
append(options, route)
}
}
}
@Wavesonics
Wavesonics / IntentExtraString.kt
Created October 26, 2017 06:03
My extra injector (just for String type so far)
class IntentExtraString
{
operator fun getValue(activity: Activity, property: KProperty<*>): String =
activity.intent.getStringExtra(property.name)
operator fun setValue(activity: Activity, property: KProperty<*>, value: String)
{
activity.intent.putExtra(property.name, value)
}
}
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
unitTest {
java.srcDir file('src/test/java')