Skip to content

Instantly share code, notes, and snippets.

View gokr's full-sized avatar

Göran Krampe gokr

View GitHub Profile
@gokr
gokr / gist:73cb41ac285611ba047a
Created December 10, 2014 23:30
Inheritance of ==?
type
Vehicle* = ref object of RootRef
color*: string
type
Car* = ref object of Vehicle
make*: string
# This method ... is never called, it seems
# that system.`==` is preferred, why?
var a = [1,2,3,4,5,6]
iterator twopow[T](a: openarray[T]): T =
var i = 1
while i <= a.high:
yield a[i-1]
i = i * 2
for x in twopow(a): echo x
@gokr
gokr / blink.cpp
Created February 9, 2016 23:25
Blink for LinkIt One in Nim
@gokr
gokr / Spry EBNF
Last active April 29, 2016 06:54
Draft of EBNF for the Spry language
The language constructs are explained using an extended BNF, in which (a)* means 0 or more a's,
a+ means 1 or more a's, and (a)? means an optional a. Parentheses may be used to group elements.
{} are used to describe character sets. Stuff I can't figure out is described inside {{ }}.
# Ints are parsed using Nim parseInt, floats using parseFloat and strings using unescape
int = ['+' | '-'] digit (['_'] digit)*
exponent = ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )*
float = ['+' | '-'] digit (['_'] digit)* (('.' (['_'] digit)* [exponent]) | exponent)
# Inside the string we replace any \\ by \, any \' by ', any \" by " and any
home/gokr/nim/test/a.nim(1, 8) Error: cannot open 'c'
import c
^
Traceback (most recent call last)
nim.nim(115) nim
nim.nim(71) handleCmdLine
main.nim(253) mainCommand
main.nim(64) commandCompileToC
modules.nim(227) compileProject
modules.nim(172) compileModule
Howto:
https://github.com/ttn-zh/ic880a-gateway/wiki
Get Raspbian Lite:
https://www.raspberrypi.org/downloads/raspbian/
Writing image to sdcard:
@gokr
gokr / blocker.nim
Last active October 12, 2017 09:37
Seems to block for me on Ubuntu
import osproc, threadpool
setMinPoolSize(200)
setMaxPoolSize(200)
proc perform() =
echo "Starting"
discard execCmdEx("sleep 25")
echo "Done "
@gokr
gokr / tt.nim
Created October 27, 2017 07:14
Hack
import httpclient, marshal, json
type
User* = ref object
login*: string
id*: int
avatar_url*: string
gravatar_id*: string
url*: string
html_url*: string
@gokr
gokr / crash.log
Created January 24, 2018 07:54
VerneMQ 1.2.3 crash on SSL stuff
2018-01-24 00:01:18 =CRASH REPORT====
crasher:
initial call: tls_connection:init/1
pid: <0.413.0>
registered_name: []
exception error: bad argument: [{erlang,binary_to_list,[undefined],[]},{ssl_config,file_error,2,[{file,"ssl_config.erl"},{line,137}]},{ssl_config,init,2,[{file,"ssl_config.erl"},{line,36}]},{ssl_connection,ssl_config,3,[{file,"ssl_connection.erl"},{line,334}]},{tls_connection,init,1,[{file,"tls_connection.erl"},{line,186}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
ancestors: [tls_connection_sup,ssl_connection_sup,ssl_sup,<0.165.0>]
messages: [{'$gen_call',{<0.371.0>,#Ref<0.0.2.660>},{new_user,<0.368.0>}}]
links: [<0.171.0>,#Port<0.9115>]
dictionary: [{ssl_pem_cache,ssl_pem_cache},{ssl_manager,ssl_manager}]
class Harness extends TestHarness<TransformerChannel> with TestHarnessAuthMixin<TransformerChannel>, TestHarnessORMMixin {
@override
ManagedContext get context => channel.context;
@override
AuthServer get authServer => channel.authServer;
Agent publicAgent;
Agent adminAgent;