This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
fn primes(n: usize) -> Vec<usize> { | |
if n < 2 { | |
return vec![]; | |
} | |
if n == 2 { | |
return vec![2]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rx = require('rx'); | |
var RtmClient = require('@slack/client').RtmClient; | |
var CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS; | |
var botToken = process.env.SLACK_BOT_TOKEN; | |
var rtm = new RtmClient(botToken); |
NewerOlder