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
| #include <stdio.h> | |
| #define print(X) _Generic((X), \ | |
| double: printf("%f\n", X),\ | |
| int: printf("%d\n", X),\ | |
| char: printf("%c\n", X)) | |
| int main (void) { | |
| int x = 42; | |
| double z = 11.0; | |
| print(x); |
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 dub | |
| /+ dub.sdl: | |
| dependency "jsonizer" version="~>0" | |
| +/ | |
| import std.stdio; | |
| import jsonizer; | |
| struct ComponentList | |
| { | |
| mixin JsonizeMe; |
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 re | |
| let | |
| haystack = "example v22" | |
| versionRe = re"v(\d+)$" | |
| if haystack =~ versionRe: | |
| echo "Version: ", matches[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
| type | |
| Error1 = object of Exception | |
| Error2 = object of Exception | |
| proc t1(error: ref Exception) = | |
| raise error | |
| try: | |
| t1(newException(Error1, "foo")) | |
| except Error1: |
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 | |
| Error1 = object of Exception | |
| Error2 = object of Exception | |
| proc t1(error: ref Exception) = | |
| raise error | |
| try: | |
| t1(newException(Error1, "foo")) | |
| except Error1: |
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
| proc example = | |
| defer: echo "deferred" | |
| raise newException(ValueError, "an exception") | |
| example() |
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
| func ternary(a, b, c: bool): range[0..7] = | |
| int(a) shl 2 and int(b) shl 1 and int(c) | |
| proc renderVisibleRows(db: DbConn): string = | |
| template rows(query: varargs[untyped]): untyped = | |
| for row in db.fastRows(query): | |
| result.add renderVisibleRow(row) | |
| when defined(samplever): | |
| rows(sql"SELECT * FROM domains WHERE rowid in (SELECT rowid FROM domains WHERE ruling IS NULL ORDER BY RANDOM() LIMIT 25) ORDER BY HOST ASC, OWNER ASC, USER ASC, DOMAIN ASC") | |
| return |
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 | |
| AnyTypeTypes = enum | |
| ATString, ATInt, ATBool | |
| AnyType = object | |
| case kind: AnyTypeTypes | |
| of ATString: str: string | |
| of ATInt: n: int | |
| of ATBool: b: bool | |
| proc wrap(str: string): AnyType = result.kind = ATString; result.str = str |
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 asyncdispatch, asyncnet, times | |
| when defined(tryfix): | |
| # modified asyncstream | |
| # begin -old--old--old--old--old--old--old--old--old--old--old--old--old--old-- | |
| import asyncfutures, deques | |
| type | |
| FutureStream*[T] = ref object | |
| queue: Deque[T] |
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 asyncnet, asyncdispatch, threadpool | |
| proc echoStdin = | |
| var line = spawn stdin.readLine() | |
| while true: | |
| if line.isReady(): | |
| echo "You said: " & ^line | |
| line = spawn stdin.readLine() | |
| asyncdispatch.drain(60) |
NewerOlder