Skip to content

Instantly share code, notes, and snippets.

View al6x's full-sized avatar

Alex Kraft al6x

  • Australia
View GitHub Profile
@al6x
al6x / transform.js
Last active March 20, 2023 03:37
babel transformation
import * as parser from "@babel/parser";
import * as t from '@babel/types';
import _traverse from "@babel/traverse";
const traverse = _traverse.default;
import _generate from '@babel/generator';
const generate = _generate.default;
let code
code = `
{
"editor.tokenColorCustomizations": {
"textMateRules": [
// Nim ---------------------------------------------------------------------------------------
{ // Bold
"scope": [
"entity.name.function.nim",
],
"settings": { "foreground": "#111827", "fontStyle": "bold" } // #3730A3
},
"workbench.colorTheme": "Default Light+",
"editor.tokenColorCustomizations": {
// gray 900 #111827
"textMateRules": [
{
"scope": [
"punctuation.definition.comment",
],
"settings": { "foreground": "#047857", "fontStyle": "bold" }
},
import base/[basem, timem, jsonm, mathm, logm, docm]
import ext/[persistencem]
import std/os
export jsonm, timem # otherwise there will be bug
# Defaults -----------------------------------------------------------------------------------------
let default_retry_timeout = 5.minutes
let default_max_retry_timeout = 4.hours
import pl0t # https://github.com/al6x/pl0t/blob/main/api/nim/pl0t.nim
let options = TableOptions[seq[float]](
order: @[("mv_usd", PlotOrder.desc_e)].some,
columns: @[
PlotTableColumn(
id: "mv_usd",
`type`: "number",
format: FormatOptions(
`type`: PlotFormatType.line_e,
@al6x
al6x / original.text
Last active June 17, 2021 15:51
Literal Nim
import nimib, nimibook
import ggplotnim
nbInit()
nbUseNimibook
# Simple plotting using [ggplotnim](https://github.com/Vindaar/ggplotnim)
## Line plot
import times, os, std/json, std/jsonutils
type OptionContract* = ref object
id*: string
right*: string
expiration*: string
strike_raw*: float
premium_raw*: float
data_type*: string
import tables, strformat, sugar, sequtils
{.experimental: "code_reordering".}
type Message = tuple[from_channel_id: int, message_id: int, message: string]
# Channels
# TODO channels should be initialized with macro, like `define_channels()`, don't know how to do that.
var channel_1: Channel[Message]
channel_1.open()
@al6x
al6x / nimprof.nim
Last active January 13, 2021 18:54
nimprof.nim
#
#
# Nim's Runtime Library
# (c) Copyright 2015 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Profiling support for Nim. This is an embedded profiler that requires
@al6x
al6x / test.kt
Last active August 14, 2020 12:24
Kotlin parallel threads
import kotlin.concurrent.thread
sealed class Errorneous<R>
data class Success<R>(val result: R) : Errorneous<R>()
data class Fail<R>(val error: Exception) : Errorneous<R>()
fun <R> thread_with_result(fn: () -> R): (() -> Errorneous<R>) {
var r: Errorneous<R>? = null
val t = thread {
r = try { Success(fn()) } catch (e: Exception) { Fail(e) }