Skip to content

Instantly share code, notes, and snippets.

View bananaumai's full-sized avatar
🙄

bnn bananaumai

🙄
  • MODE, Inc.
  • Tokyo
View GitHub Profile
@bananaumai
bananaumai / README.md
Created September 9, 2025 02:45
Go program to examine net.SplitHostPort function behavior

Go net.SplitHostPort Test Program

This program demonstrates the behavior of Go's net.SplitHostPort function with various input cases.

What it does

The net.SplitHostPort function splits a network address into host and port components. This program tests the function with:

  1. Standard cases: Regular hostnames and IP addresses with ports
  2. IPv6 cases: IPv6 addresses properly bracketed
@bananaumai
bananaumai / Main.kt
Last active March 24, 2022 23:55
Coroutines delay and Future get
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.concurrent.CompletableFuture
fun main() {
val future = CompletableFuture<Unit>()
doSuspend {
@bananaumai
bananaumai / throttle.kt
Created July 31, 2020 02:26
Throttling flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
fun <T> Flow<T>.throttleByTime(wait: Long): Flow<List<T>> = flow {
val holder = emptyList<T>().toMutableList()
var nextTime = 0L
collect {
val curTime = System.currentTimeMillis()
@bananaumai
bananaumai / ActivityMain.java
Created January 17, 2020 05:50
QuickStart MODE Gateway SDK for Android
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ModeGatewayClient modeGatewayClient = initModeGateway();
Button eventButton = findViewById(R.id.event_button);
@bananaumai
bananaumai / AccelerationFlow.kt
Created December 3, 2019 09:37
Android Accelerometer to event (with calibration steps)
@ExperimentalCoroutinesApi
private fun accelerationFlow(context: Context): Flow<Acceleration> = channelFlow {
val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
val listener = object : SensorEventListener {
private val sampleNumber = 20
private val samples: MutableList<Acceleration.Coordinate> = mutableListOf()
private var offset: Acceleration.Coordinate? = null
@bananaumai
bananaumai / MainActivity.kt
Created October 11, 2019 14:42
Sensor Flow with lifecycleScope
@ExperimentalCoroutinesApi
class MainActivity : AppCompatActivity() {
private var working = false
private var job: Job? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<Button>(R.id.button)
@bananaumai
bananaumai / fib.rs
Last active March 24, 2019 15:02
rust code example - fibonacci generator
fn fib(n: usize) -> Vec<u64> {
let mut fibs = Vec::new();
while fibs.len() < n {
let current = match fibs.len() {
0 => 0,
1 => 1,
_ => {
fibs.iter().rev().take(2).sum()
}
@bananaumai
bananaumai / prime.rs
Last active March 24, 2019 15:01
rust code example - find prime numbers
use std::collections::HashMap;
fn primes(n: usize) -> Vec<usize> {
if n < 2 {
return vec![];
}
if n == 2 {
return vec![2];
}
o :: Ord a => a -> a -> Bool
o x y = x >= y
e :: Eq a => a -> a -> Bool
e x y = x == y
f :: Ord a => (a -> a -> Bool) -> a -> a -> String
f cmp x y = if cmp x y then "YES" else "NO"
main :: IO ()