Skip to content

Instantly share code, notes, and snippets.

View dom96's full-sized avatar
🛤️

Dominik Picheta dom96

🛤️
View GitHub Profile
import selectors, net
type
Data = ref object of RootRef
someData: string
var selector = newSelector()
var sock = newSocket()
# The {} means "Don't notify me about any events for this sock", the sock is still registered though
selector.register(sock, {}, Data(someData: "Blah blah"))
import
asyncdispatch, asyncnet, htmlparser, xmltree, httpclient, strutils,
strtabs, streams, uri, sets
var visited = initSet[string]()
proc crawl(url: string, client: PAsyncHttpClient = newAsyncHttpClient()) {.async.} =
if url in visited: return # Already visited this URL.
echo("Crawling ", url)
visited.incl(url)
import macros, strutils
type
TokenKind = enum
FInt, FString, Text
Token = object
case kind: TokenKind
of FInt, FString: nil
of Text: c: String
## Module for handling and raising signals. Wraps ``<signals.h>``.
type
TSignal = enum
SIGINT = 2
proc signal*(sig: cint, func: pointer) {.importc: "signal", header: "<signal.h>".}
template atSignal*(s: TSignal, actions: stmt): stmt =
proc callback(sig: cint) =
@dom96
dom96 / The Technical Interview Cheat Sheet.md
Last active January 1, 2019 07:51 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
import macros
macro replace(node: untyped): untyped =
result = node
# StmtList
# Command
# Ident ident"echo"
# IntLit 42
result[0][1] = newStrLitNode("Hello World")
#? braces
proc main() {
echo("Hello");
}
when (isMainModule) {
main();
}
@dom96
dom96 / gist:4eb5f8730d5dd3a395b1bba17419b37a
Created September 22, 2017 21:18 — forked from Adeohluwa/gist:a49409d249d9f09a4a69b8efd867fb28
Choose NIM Fails To Build On The Server
root@ubuntu-512mb-nyc3-01:~# curl https://nim-lang.org/choosenim/init.sh -sSf | sh
choosenim-init: Downloading choosenim-0.2.2_linux_amd64
Info: Nim 0.17.2 already downloaded
Extracting nim-0.17.2.tar.gz
Building Nim 0.17.2
Building tools (nimble, nimgrep, nimsuggest)
Exception: Execution failed with exit code 1
... Command: ./koch tools -d:release
... Output: bin/nim c --noNimblePath -p:compiler -d:release -o:bin/nimsuggest nimsuggest/nimsuggest.nim
... Hint: used config file '/root/.choosenim/toolchains/nim-0.17.2/config/nim.cfg' [Conf]
import dom
type
CanvasRenderingContext* = ref object
fillStyle* {.importc.}: cstring
strokeStyle* {.importc.}: cstring
width* {.importc.}: int
height* {.importc.}: int
shadowColor* {.importc.}: cstring
var respChan: Channel[(string, string)]
var handlers: Table[string, proc (response: string)]
proc httpLoop() {.async.} =
while true:
let (received, resp) = respChan.tryRecv()
if received:
handlers[resp[0]](resp[1])
await sleepAsync(1000)