Giter Site home page Giter Site logo

nimdays's Introduction

Nim Days

Nim Days is a project to document my journey with The Nim Programming Language

What is in it?

I'll try create multiple practical applications/libraries including:

  • Parsers for bencode, dmidecode, ini, redis protocol
  • Testing framework
  • Build system

Check TOC for complete summary

Publishing flow

  • To compile the sources please make sure to have mdbook in your $PATH
  • To regenerate the HTML files bash publish.sh

Contributions

Please feel free to open an issue or send a PR

nimdays's People

Contributors

andrewnc avatar defau1t avatar demotomohiro avatar hitoshi44 avatar icetortoise avatar ionling avatar jbpratt avatar weh avatar xmonader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nimdays's Issues

Suggestion: Keep chapters' format in linear order

As we can see from the screenshot, the chapters are not in linear order.

image

I have had this issue myself with LaTeX and the easiest way to fix it is by prefixing it with leading zeroes.

days01...
days02...
days03...
...
days10...

This way it respects the linear order should follow.

Very new person, can't get first code to compile

I did try almost all of the examples, and none would compile. I was wondering for 'finalized' source code so I can see what I am doing wrong. I also did try the 'shorturl' program, (created a new NIM file) then created shorturl.c in a directory, then 'nim c' and only found that I got :

Hint: used config file '/usr/local/Cellar/nim/1.0.0/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: shorturl [Processing]
/Users/tmunn/src/nim/shorturl/shorturl.nim(4, 8) Error: cannot open file: jester

Day 2 example isn't working

when copy&pasting your code, i get an IndexError. The problem starts here:

proc decode(this: Decoder,  source: string) : (BencodeType, int) =
    var curchar = source[0]
    var idx = 0
    while idx < source.len:
        curchar = source[idx]
        case curchar
        of 'i':
            let pair = this.decode_i(source[idx..source.len])
            let obj = pair[0]
            let nextobjpos = pair[1] 
            idx += nextobjpos
            return (obj, idx)
        of 'l':
            let pair = this.decode_l(source[idx..source.len])
            let obj = pair[0]
            let nextobjpos = pair[1] 
            idx += nextobjpos
            return (obj, idx)
        of 'd':
            let pair = this.decode_d(source[idx..source.len])
            let obj = pair[0]
            let nextobjpos = pair[1] 
            idx += nextobjpos
            return (obj, idx)
        else: 
            let pair = this.decode_s(source[idx..source.len])
            let obj = pair[0]
            let nextobjpos = pair[1] 
            idx += nextobjpos
            return (obj, idx)

source.len must give that error on string slicing, it should be len(source)-1. If i change that, the testcode compiles and works ... it seems.
The next problem is, that the decode_s method is only working, when len(source) < 10, otherwise:

testObjects[BencodeType(kind: btString, s:"this is a test")] = "14:this is a test"

results in:
image

tcp router question

I saw the Forwarder is defined like this:

type Forwarder = object of RootObj
  options*: ForwardOptions

and then there is a constructor proc:

proc newForwarder(opts: ForwardOptions):  ref Forwarder =
  result = new(Forwarder) 
  result.options = opts

and then Forwarder can be passed into processClient and serve with type ref Forwarder

and as I'm quite new to nim, I was confused with defining Fowarder in ref object, and the whole code like this:

type Forwarder = ref object of RootObj  
  options*: ForwardOptions
.
.
proc newForwarder(opts: ForwardOptions): Forwarder =
  result = new(Forwarder) 
  result.options = opts
.
.
proc serve(this: Forwarder) {.async.} =
...

the code is ok to be compiled, but I don't know if it's ok to do that, and the difference between the two way of defining object.

use tcp router with http port forwarding

I tried the code with forwarding to a http server, I first get the page displayed in browser, after several seconds I got the following error:

/nim-1.0.0/lib/pure/asyncfutures.nim(383)   read
  ]#
Exception message: index out of bounds, the container is empty
Exception type: [IndexError]

Tests

Any reason you don't write tests?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.