Skip to content

Instantly share code, notes, and snippets.

View eoinahern's full-sized avatar
🏠
reading the joy of kotlin. fantastic book

eoin_a eoinahern

🏠
reading the joy of kotlin. fantastic book
View GitHub Profile
package main
import (
"bufio"
"errors"
"fmt"
"log"
"mime/multipart"
"net/http"
"os"
package main
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"mime/multipart"
"net/http"
"os"
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
"time"
@eoinahern
eoinahern / client.js
Last active October 21, 2021 17:49
connecting to ktor websocket endpoints with simple node.js client (dont really use node a lot)
const WebSocket = require('ws')
//setup input from console
var stdin_input = process.stdin;
stdin_input.setEncoding("utf-8");
//connect socket!!
const url = "ws://localhost:8080/output_all";
const connection = new WebSocket(url);
@eoinahern
eoinahern / Memoizer.kt
Created March 29, 2020 22:34
a Memoizer class from the book joy of kotlin
import java.util.concurrent.ConcurrentHashMap
class Memoizer<T, U> private constructor() {
private val map = ConcurrentHashMap<T, U>()
private fun callLocalMemoize(block: (T) -> U): (T) -> U = { input ->
map.computeIfAbsent(input) {
block(it)
private const val IV_KEY = "iv"
class EncryptionUtil @Inject constructor(
private val keyGenerator: KeyGenerator,
private val keyGenParameterSpec: KeyGenParameterSpec,
private val keyStore: KeyStore,
private val prefs: SharedPreferences,
private val editPrefs: SharedPreferences.Editor
@eoinahern
eoinahern / Main.kt
Created January 16, 2020 12:37
playing with pure functions curried functions
fun main() {
val addOne : (Int) -> Int = { it + 1 }
val doubleStuff : (Int) -> Int = { it * 2}
val myFunc = composer(addOne, doubleStuff)
println(myFunc(3))
val add : (Int) -> (Int)-> Int= { a -> {b -> a + b}}
val num = add(1)(2)
println(num)
@Test
fun testGetCurrency() {
val item: Pair<DomainCurrency, List<DomainCurrency>> = Pair(
DomainCurrency("USD", "1.00", 2, "US DOLLAR"),
listOf(DomainCurrency("EUR", "12.00", 1, "EURO"))
)
@eoinahern
eoinahern / FormatRealTime.kt
Created April 9, 2019 18:39
trying to format text in edittext using the Locale to add decimal places and comma seperators after user has typed
val df = DecimalFormat("#,###", DecimalFormatSymbols(Locale.getDefault()))
var textChanged = false
df.minimumFractionDigits = 0
df.maximumFractionDigits = asset.investmentDecimalPlaces
layout.txt_amount.textChanges()
.debounce(400, TimeUnit.MILLISECONDS)
.map { layout.txt_amount.text.toString() }
.subscribeOn(AndroidSchedulers.mainThread())
class CustomShrinkLayoutBehavior(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<NestedScrollView>(context, attrs) {
private var screenHeight: Int = context.resources.displayMetrics.heightPixels
override fun layoutDependsOn(parent: CoordinatorLayout, child: NestedScrollView, dependency: View): Boolean {
return dependency is AppBarLayout
}
override fun onDependentViewChanged(parent: CoordinatorLayout, child: NestedScrollView, dependency: View): Boolean {