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
package concurrency | |
import ( | |
"fmt" | |
"sync" | |
) | |
type Promise struct { | |
value interface{} | |
error error |
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
package main | |
import ( | |
"archive/zip" | |
"bytes" | |
"io/ioutil" | |
"log" | |
) |
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
package main | |
import ( | |
"archive/zip" | |
"bytes" | |
"io/ioutil" |
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
func (db *DB) Transact(txFunc func(db *DB) error) (err error) { | |
tx := db.Begin() | |
if tx.Error == gorm.ErrCantStartTransaction { | |
// transaction already in progress | |
return txFunc(db) | |
} | |
defer func() { | |
if r := recover(); r != nil { | |
tx.Rollback() | |
panic(r) |
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
suspend fun uvClose(handle: CPointer<uv_handle_t>): Unit = suspendCoroutine { cont -> | |
handle.pointed.data = StableRef.create(cont).asCPointer() | |
uv_close(handle, staticCFunction { handle: CPointer<uv_handle_t>? -> | |
handle ?: return@staticCFunction | |
val data = handle.pointed.data ?: return@staticCFunction | |
val contRef = data.asStableRef<Continuation<Unit>>() | |
contRef.get().resume(Unit) | |
contRef.dispose() | |
}) | |
} |
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
suspend fun uvClose(handle: CPointer<uv_handle_t>): Unit = suspendCoroutine { cont -> | |
handle.pointed.data = StableRef.create(cont).asCPointer() | |
uv_close(handle, staticCFunction { handle: CPointer<uv_handle_t>? -> | |
handle ?: return@staticCFunction | |
val data = handle.pointed.data ?: return@staticCFunction | |
val contRef = data.asStableRef<Continuation<Unit>>() | |
contRef.get().resume(Unit) | |
contRef.dispose() | |
}) | |
} |
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
(ns game-of-life.core | |
(:require [clojure.string :as str] | |
[clojure.core.reducers :as r])) | |
(comment | |
" Rules | |
The universe of the Game of Life is an infinite two-dimensional orthogonal | |
grid of square cells, each of which is in one of two possible states, | |
alive or dead. Every cell interacts with its eight neighbours, |
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
-- LeNsTR | |
module Main where | |
comp :: (a -> a -> Bool) -> [a] -> Bool | |
comp f = comp' where | |
comp' (x:[]) = True | |
comp' (x:y:[]) = x `f` y | |
comp' (x:y:(h:t)) | x `f` y = comp' (y:h:t) | |
| otherwise = False |
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
(defn elevator [commands] | |
(letfn [(ff-open [[cmd & rest]] | |
#(case cmd | |
:close (ff-closed rest) | |
:done true | |
false)) | |
(ff-closed [[cmd & rest]] | |
#(case cmd | |
:open (ff-open rest) | |
:up (sf-closed rest) |
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
(defn map-ext [f x & xs] | |
(let [colls (cons x xs) | |
res (apply map f colls) | |
next (filter not-empty (map #(drop (count res) %) colls))] | |
(if (empty? next) res | |
(lazy-seq (concat res (apply map-ext f next)))))) |
NewerOlder