Skip to content

Instantly share code, notes, and snippets.

View Groostav's full-sized avatar

Geoff Groostav

View GitHub Profile
@Groostav
Groostav / eventcontext.kt
Created July 26, 2019 19:45
first crack at mutable event bus context
class EventContext(key: Key): AbstractCoroutineContextElement(key) {
private val completed = CompletableDeferred<Unit>()
private var events: AtomicReference<ImmutableList<EventWrapper>?> = AtomicReference(immutableListOf())
// in this implementation, polling an empty list "closes" it,
// thus, if you poll a list of 1 element, it becomes a list of 0 elements,
// when thats polled, its atomically closed and subsequent offer calls return false.
fun poll(): EventWrapper? {
@Groostav
Groostav / results.log
Created June 11, 2019 21:02
looks fine to me
[ditto@teamcity ~]$ cat ./.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTEe1AqswRuHevBWuuuIcEzFTxz+glnohcGQWFpQShhawcTiB4FRhF3FsayU1Qt9HaiDd/Mafdnh0tGpWGJ/sozl6l3ydFSD++FIlJM9TSxhnPHMOOBKLISpB3rDSH4Nz8C6Hp0ySMtF2aMZhCSz/EKjjm/iV6cTQ/ScYFh3rcn6Y78cR3U9WgOFFfFaIfh9QQRs3oN6RowrlE+Oj+5U6W8PtPgcoC+smxd1DxEE2aX96FhlpmeRyAQtyoJEPj07LExKPEIQ6Vv2aAiL13EB/dK5qV5gSeq5+m9C/OOscnR/S6NkXUpsprxpXPyVFmanaKn87i57Iq5146IKP+Wfwr geoff@Kusinagi-2
[ditto@teamcity ~]$ logout
Connection to teamcity.empowerops.ca closed.
C:\Users\Geoff\Code\OASIS\Samples\PowerShell\SC function via ssh [2238_create_non_commercial_version ≡ +0 ~2 -0 !]> cat C:\Users\Geoff\.ssh\id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTEe1AqswRuHevBWuuuIcEzFTxz+glnohcGQWFpQShhawcTiB4FRhF3FsayU1Qt9HaiDd/Mafdnh0tGpWGJ/sozl6l3ydFSD++FIlJM9TSxhnPHMOOBKLISpB3rDSH4Nz8C6Hp0ySMtF2aMZhCSz/EKjjm/iV6cTQ/ScYFh3rcn6Y78cR3U9WgOFFfFaIfh9QQRs3oN6RowrlE+Oj+5U6W8PtPgcoC+smxd1DxEE2aX96FhlpmeRyAQtyoJEPj07LExKPEIQ6Vv2aAiL13EB/dK5qV5gSeq5+m9C/OOscnR/S6NkXUpsprxpXPyVFm
Param(
$OutputCerts = "./sslcerts",
$ServerCN = "127.0.0.1",
$ClientCN = "127.0.0.1"
)
Get-Command "openssl" -ErrorAction Stop
# you can get this from choco with
# choco install openssl-light
@Groostav
Groostav / my opinions.kt
Created March 11, 2019 19:01
synchronizing on database events
@Test fun `should receive updated data when querying all challenges`() = runBlocking<Unit> {
//setup
val initChallenges = list(Challenge(...),Challenge(...))
val newSurveyChallenge = SurveyChallenge(...)
val expectedChallenges = initChallenges + newSurveyChallenge
//act
initChallenges.forEach(challengeDao::addOrUpdate)
challengeDao.addOrUpdate(newSurveyChallenge)
@Groostav
Groostav / ReasonablySimpleTest.kt
Last active March 3, 2019 19:41
trying to use Undispatched to clean up stack traces
@Test fun `when using a rendezvous channel can see through to caller if configured`() = runBlocking{
val channel = Channel<String>(RENDEZVOUS)
var exception: Exception? = null
val producer = GlobalScope.launch(Dispatchers.IO){
hardpoint {
channel.send("hello!")
}
}
class Test {
@Volatile
var ticker = 0
@Volatile
var deferred: Deferred<String>
val retryingExceptionHandler: CoroutineExceptionHandler = CoroutineExceptionHandler { _, throwable ->
println("!!!!!!!")
authScope.kickoffUpdateWithDelay()
authScope.testB()
@Groostav
Groostav / SimpleInlineMulticaster.kt
Created January 30, 2019 22:33
a channel that distrubutes messages from another channel, with state checks to make sure you cant loose any messages
package groostav.kotlinx.exec
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Unconfined
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.RENDEZVOUS
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.consumeEach
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
@Groostav
Groostav / NewCallAdapterFactory.kt
Created January 16, 2019 19:38
using coroutines instead of RX
Retrofit.addCallAdapterFactory(ErrorCheckingCallAdapterFactory())
class ErrorCheckingCallAdapterFactory() : CallAdapter.Factory() {
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>? {
if (CallAdapter.Factory.getRawType(returnType) != Deferred::class.java) {
return null // Ignore ~~non-Observable~~ non-coroutine types.
}
class Tests{
@Test
fun `Submits app selection if selections can be made`() = runBlocking(Dispatchers.Main) { //@Test... = runBlocking is a good convention
mainActivityViewModel.submitAppSelection(selectedApp)
verify(mockAppsStartupFsm).submitEvent(AppSelected(selectedApp))
}
}
@Groostav
Groostav / OrAsync.kt
Last active August 7, 2018 02:10
orAsync implementation attempt
private enum class Side { Left, Right }
infix fun Deferred<Boolean>.orAsync(right: Deferred<Boolean>) = async<Boolean> {
val left: Deferred<Boolean> = this@orAsync
//note: I didnt take a context object.
//`infix` might not be possible...
// 'short circuit'
if(left.isCompleted && left.getCompleted()) return@async true
if(right.isCompleted && right.getCompleted()) return@async true