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
import options | |
import future | |
import sequtils | |
# Unfolding the Nim Magic | |
## Bug https://github.com/nim-lang/Nim/issues/5647 open. | |
## unfold proper type signature should have Option[(T, U)] instead of Option[(T, T)] | |
# proc unfoldr*[T, U](f: U -> Option[(T, U)], x:U): seq[T] {. inline .}= |
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
template scanr[T](s: seq[T], operation: untyped): untyped = | |
## Template to scan a sequence from right to left, returning the accumulation and intermediate values. | |
## This is a foldr with intermediate steps returned | |
## @[2, 2, 3, 5].scanr(a + b) = @[48, 24, 12, 4] | |
let len = s.len | |
assert len > 0, "Can't scan empty sequences" | |
var result = newSeq[T](len) |
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
import gzip | |
import json | |
import requests | |
try: | |
from cStringIO import StringIO | |
except: | |
from StringIO import StringIO | |
# Let's fetch the Common Crawl FAQ using the CC index | |
resp = requests.get('http://index.commoncrawl.org/CC-MAIN-2015-27-index?url=http%3A%2F%2Fcommoncrawl.org%2Ffaqs%2F&output=json') |
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
type | |
Context*[T] = ref object | |
nodes: seq[T] | |
Variable*[T; C: static[Context[T]]] = object | |
tape: Context[T] | |
index: int | |
value: T | |
proc newContext*[T]: Context[T] {.noSideEffect.} = |
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
## main.nim - uses a loop and a split | |
import strutils | |
let inFile = open("input.txt", fmRead) | |
let outFile = open("output.txt", fmWrite) | |
var ln: TaintedString = "" | |
var parts: seq[string] | |
while inFile.readLine(ln): |
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
proc filter[T](it: (iterator : T), f: proc(x: T): bool): (iterator: T) = | |
return iterator(): T = | |
while (let x = it(); not finished(it)): | |
if f(x): | |
yield x |
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
git rev-list --objects --all \ | |
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \ | |
| awk '/^blob/ {print substr($0,6)}' \ | |
| sort --numeric-sort --key=2 \ | |
| cut --complement --characters=13-40 \ | |
| numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest |
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
#!/usr/bin/env bash | |
# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/ | |
### | |
# Label definitions | |
### | |
declare -A LABELS | |
# Platform |
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
import nimcuda/[cuda_runtime_api, driver_types, nimcuda] | |
import sequtils, future | |
type GpuArray[T: SomeReal] = object | |
data: ref[ptr T] | |
len: int | |
{.compile: "./square.cu".} | |
proc cuda_square(bpg, tpb: cint, y: ptr cfloat, x: ptr cfloat) {.importc, header:"../square.cuh".} | |
#../square.cuh is a workaround because header is not copied to nimcache |