Skip to content

Instantly share code, notes, and snippets.

View awelm's full-sized avatar
🎯
Focusing

Akila Welihinda awelm

🎯
Focusing
View GitHub Profile
SELECT g.title FROM grants g WHERE g.title LIKE 'Monkey';
(module
;; Allocate a memory buffer of 1000 64KB pages (64MB total) for our image
(memory (export "memory") 1000 1000)
(func $fillBufferWithSIMD (param $numIterations i32)
;; declare local variables
(local $currentIteration i32)
(local $bufferPtr i32)
(local $bufferSizeBytes i32)
;; Set currentIteration=0 and bufferSizeBytes=64MB
def openFileTry(name: String): Try[Source] = Try(Source.fromFile(name))
val fileTry = openFileTry("a.txt").getOrElse(openFileTry("b.txt"))
try:
file = open("a.txt", 'rb')
except Exception:
try:
file = open("b.txt", 'rb')
except Exception:
pass
// type: Try[Int], value: Success(6)
val toIntTry = Try {
"6".toInt
}
// type: Try[Int], value: Success(7)
val incrementedIntTry = toIntTry.map(_+1)
// type: Try[Double], value: Success(7.0)
val toDoubleTry = incrementedIntTry.flatMap { integer =>
computeString.map(_.split(" ")).flatMap(persistWords)
async def storeWords():
computedString = await computeString()
words = computedString.split(" ")
await persistWords(words)
asyncio.run(storeWords())
// type: Future[String]
val stringFut = Future {
Thread.sleep(1000)
"Returned string"
}
/*
* You can call map() to register a synchronous operation
* to run once this Future completes successfully
*/
val viewerId = user.getSubscriptionOpt // type: Option[Subscription]
.flatMap(_.getPremiumTierOpt) // type: Option[Tier]
.flatMap(_.getPremiumIdOpt) // type: Option[ID]
.getOrElse(user.getId()) // type: ID
viewerId = None
subscription = user.getSubscription()
if subscription:
premiumTier = subscription.getPremiumTier()
if premiumTier:
premiumId = premiumTier.getPremiumId()
if premiumId:
viewerId = premiumId
else: