This file contains hidden or 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
| trait CrossProduct[A,B,C] { | |
| def cross( as: Traversable[A], bs: Traversable[B] ): Traversable[C] | |
| } | |
| trait LowPriorityCrossProductImplicits { | |
| private type TV[X] = Traversable[X] | |
| implicit def crosser2[A,B] = new CrossProduct[A,B,(A,B)] { | |
| def cross( as: TV[A], bs: TV[B] ): TV[(A,B)] = for { a <- as; b <- bs } yield (a, b) | |
| } |
This file contains hidden or 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 os, threadpool | |
| proc spawnBackgroundJob[T](f: iterator (): int): TChannel[T] = | |
| type Args = tuple[iter: iterator (): T, channel: ptr TChannel[T]] | |
| #type Args = tuple | |
| # iter: iterator (): T | |
| # channel: ptr TChannel[T] | |
| proc threadFunc(args: Args) {.thread.} = |
This file contains hidden or 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
| type | |
| Test = object | |
| field: seq[int] not nil | |
| var t: Test | |
| echo t.field.isNil() # true |
This file contains hidden or 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
| #!/usr/bin/env sh | |
| # A wrapper around the Nim compiler to allow for easy scripting of Nim. Puts | |
| # all temporary files in a temporary directory and cleans up after itself. | |
| # | |
| # Usage: | |
| # - add `#!/usr/bin/env nimrun` at the beginning of your script | |
| # - execute the nim file with it, for example, `nimrun file.nim args` | |
| # | |
| # Possible future extentions: |
This file contains hidden or 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
| macro stringParseTest(s: string): stmt = | |
| let trueString = s.strVal | |
| let ne = parseExpr(trueString) | |
| let ns = parseStmt(trueString) | |
| echo treeRepr(ne) | |
| echo treeRepr(ns) | |
| # looking good: | |
| # Infix | |
| # Ident !"+" | |
| # Ident !"y" |
This file contains hidden or 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 os, threadpool | |
| proc spawnBackgroundJob[T](channel: ptr Channel[T], f: iterator (): T) = | |
| type Args = tuple[iter: iterator (): T, channel: ptr Channel[T]] | |
| proc threadFunc(args: Args) {.thread.} = | |
| echo "Thread is starting" | |
| let iter = args.iter | |
| var channel = args.channel # note: still a `ptr Channel` |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains hidden or 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
| value | |
| 100 | |
| 150 | |
| 200 |
This file contains hidden or 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 future | |
| import options | |
| #[ | |
| proc flatMap[X](iter: iterator(): X, mapper: X -> iterator(): X): (iterator(): B) = | |
| result = proc() = | |
| yield X | |
| proc iter(): int = |
This file contains hidden or 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
| // https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8921bcc0302b066ef5e39bc6e9a8b7e3 | |
| #![allow(dead_code)] | |
| use std::collections::HashMap; | |
| struct Test { | |
| offset: f64, | |
| buffers: HashMap<i32, Vec<f64>>, | |
| data: Vec<f64>, |
This file contains hidden or 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 numpy as np | |
| import matplotlib.pyplot as plt | |
| from ssqueezepy import ssq_cwt, cwt | |
| SAMPLE_RATE = 44100 | |
| def sine(freq, num_samples=SAMPLE_RATE // 4, amp=1.0): |
OlderNewer