How to implement a "Walrus" operator like in python 3.8 in Nim?

2019-02-08 Thread mrhdias
[https://www.python.org/dev/peps/pep-0572/](https://forum.nim-lang.org/postActivity.xml#https-www-python-org-dev-peps-pep-0572) # Python basic example def test(): return 1 x = test() if x == 1: print(x) # With python 3.8 Walrus operator: d

Re: How to implement a "Walrus" operator like in python 3.8 in Nim?

2019-02-08 Thread mrhdias
Thank you :-) Nim is a great programming language

Re: How to implement a "Walrus" operator like in python 3.8 in Nim?

2019-02-08 Thread mrhdias
If you change the "yes" procedure to return a integer as a example not work template `:=`(a, b): untyped {.dirty.} = let a = b a proc yes: int = 1 if x := yes(): echo x test.nim(7, 6) Error: type mismatch: got but expected 'bool'

Newbie question about reading asynchronous text file line by line

2019-02-11 Thread mrhdias
I'm trying to read a text file asynchronous line by line but the following code fails to compile import asyncdispatch, asyncfile, os proc main() {.async.} = var filename = getTempDir() / "test.txt" var file = openAsync(filename, fmWrite) await file.w

Re: Newbie question about reading asynchronous text file line by line

2019-02-11 Thread mrhdias
Sorry the second the redefinition of file in invocation of openAsync it's my mistake. This compile but I get the same error: import asyncdispatch, asyncfile, os proc main() {.async.} = var filename = "test.txt" var file = openAsync(filename, fmRead) while

Re: Newbie question about reading asynchronous text file line by line

2019-02-12 Thread mrhdias
I have created an issue [10641](https://github.com/nim-lang/Nim/issues/10641)

Error when test if a large number is prime!

2019-02-13 Thread mrhdias
When test if a large number is prime I get the following error: prime.nim(12, 14) Error: number out of range: '12548798547123658478' Nim is fast for scientific computing and I enjoy writing code in Nim, but I am a Nim newbie! How to make this work for big numbers? import math

Re: Error when test if a large number is prime!

2019-02-14 Thread mrhdias
Thanks for the hint!

How to speed up the upload of a big file with asynchttpserver!

2019-02-20 Thread mrhdias
This code is pretty simple and is a example, but is painfully slow for big files (10Mb)! How to read data chunks of request body to a temp file instead of reading everything at once to memory? import asynchttpserver, asyncdispatch proc handler(req: Request) {.async.} =

Re: How to speed up the upload of a big file with asynchttpserver!

2019-02-24 Thread mrhdias
Hi @dom96, I did an experiment (see [https://github.com/mrhdias/EnigmaHTTPServer](https://github.com/mrhdias/EnigmaHTTPServer)) to decode the multipart/data request body by doing the cache of the body. I do not know if it's the best approach, but it works and it's fast for large files

Re: How to speed up the upload of a big file with asynchttpserver!

2019-03-02 Thread mrhdias
I modified Dominik Picheta asynchttpserver library to try decode the post multipart request's. I'm a newbie in Nim programming, but the result can be seen here: [https://github.com/mrhdias/EnigmaHTTPServer](https://github.com/mrhdias/EnigmaHTTPServer) At this point it is possible

What is the best way to run a nim program as daemon?

2019-03-10 Thread mrhdias
This work: $ ./server -p 8080 &> ./logs/server.log & echo $! > ./server.pid; But is this the correct approach?

Re: What is the best way to run a nim program as daemon?

2019-03-11 Thread mrhdias
Thank you all for the suggestions. Just one more question: How do I catch a "KILL" or "HUP" or user abort signal (CTRL-C)?

Help with template!

2019-03-11 Thread mrhdias
This code works as expected. But I wanted to replace the "block routes:" with "routes:" only. Any idea how to do this? import asynchttpserver, asyncdispatch template via*(rule_path: string, reqMethods: seq[string], code_to_execute: untyped): untyped = if $req.reqMetho

Re: Help with template!

2019-03-12 Thread mrhdias
Thank you, it works :-) I tried the same thing, but without the pragma "{.dirty.}".

Passing a pointer to an array to a c function!

2019-03-14 Thread mrhdias
I'm trying binding libgd library with Nim, but I'm facing a problem with pointers. My interface: # https://libgd.github.io/manuals/2.2.5/files/gd-h.html#gdPoint type gdImagePtr* = ref object type gdPoint* = object x*: int y*: int

Re: Passing a pointer to an array to a c function!

2019-03-14 Thread mrhdias
Bingo Work!!! Tanks @yglukhov the solution is replace int with cint ;-) type gdPoint* = object x*: cint y*: cint Run

Re: Passing a pointer to an array to a c function!

2019-03-14 Thread mrhdias
c2nim not work very well :-( $ c2nim --dynlib:libgd --cdecl ./gd.h --out:gdtest.nim /home/hdias/development/tmp/gd.h(14, 62) Warning: comment 'version605b5d1778' ignored [CommentXIgnored] /home/hdias/development/tmp/gd.h(15, 62) Warning: comment 'version605b5d1778' ignored [

Re: Passing a pointer to an array to a c function!

2019-03-14 Thread mrhdias
Ok, you're right. But conversion is not trivial! [https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst](https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst)

Re: Passing a pointer to an array to a c function!

2019-03-14 Thread mrhdias
Thank you. It's a good starting point.

Re: Passing a pointer to an array to a c function!

2019-03-15 Thread mrhdias
You are right @moerm. The solution I found was to copy and paste a group of functions from the c file to another file and then run c2nim. Then copy and paste another group of functions and run the c2nim again. And repeat this procedure until the end of the c code.

How to compile and run a Nim program on the Android?

2019-03-29 Thread mrhdias
I tried to compile a test program following the steps indicated in this [post](https://forum.nim-lang.org/t/1866#11698), but it does not work. $ nim c --cpu:arm64 --passC:-fPIE --passL:"-fPIE -pie" test.nim $ adb devices List of devices attached 42044158c4bc8100devic

Re: How to compile and run a Nim program on the Android?

2019-03-29 Thread mrhdias
Not work :-( $ adb push test /storage/sdcard0/Download/test $ adb shell chmod a+x /storage/sdcard0/Download/test Bad mode $ adb shell 10|shell@android:/ $ chmod 0755 /storage/sdcard0/Download/test Unable to chmod /storage/sdcard0/Download/test: Operation not permi

Re: Nim + Flutter == bright future?

2019-03-30 Thread mrhdias
Another alternative: [https://kivy.org](https://kivy.org) Nim can speed up up this framework. The rapid adoption of Nim can pass through the mobile apps.

Re: How to compile and run a Nim program on the Android?

2019-03-30 Thread mrhdias
Yes I enable developer options and software from untrusted sources. I discovered that the problem is to write on the sdcard0. If I change the location and try to run it gives another error: not executable: magic 7F45 $ adb push test /data/local/tmp/test $ adb shell /data/local/

Re: How to compile and run a Nim program on the Android?

2019-03-30 Thread mrhdias
I tried to follow the recipe of this [post](https://forum.nim-lang.org/t/1866#11698) but without success :-( $ wget https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip $ unzip android-ndk-r19c-linux-x86_64.zip S YSROOT=/home/hdias/Downloads/android-n

Re: How to compile and run a Nim program on the Android?

2019-03-31 Thread mrhdias
With latest android-ndk and the information from this [post](https://forum.nim-lang.org/t/3575#22318) #!/bin/sh mkdir tmp cd tmp cp ../test.nim ./ git clone https://github.com/nim-lang/nim wget https://dl.google.com/android/repository/android-ndk-r19c-linux-

Re: How to compile and run a Nim program on the Android?

2019-04-02 Thread mrhdias
I know, but for testing I downloaded "android-sdk-ndk" directly from the source. Yes works for x86 architecture, but my phone is arm and many brands of mobile phones use arm.

Re: How to compile and run a Nim program on the Android?

2019-04-02 Thread mrhdias
I think it's not a root problem because it compiles on Android x86_64.

Re: How to compile and run a Nim program on the Android?

2019-04-03 Thread mrhdias
I finally succeeded :-) My android test phone is old. I found the solution [here](https://stackoverflow.com/questions/27338318/cannot-load-library-reloc-library1285-cannot-locate-rand) Work with API level 19! test.bin: 1 file pushed. 1.2 MB/s (142260 bytes in 0.109s) Hello Worl

Suggestions for gui frameworks to make an app in nim for android?

2019-04-03 Thread mrhdias
I saw this [page](https://github.com/VPashkov/awesome-nim) and tested the packages that are mentioned there (Game Development and GUI). Unfortunately none of them work on android (I just tested on arm64 Nougat API 24):-( For [SDL2](https://nimble.directory/search?query=sdl) there are many imple

Re: Suggestions for gui frameworks to make an app in nim for android?

2019-04-04 Thread mrhdias
I think the problem is not the cross compiler, I can compile and run a "Hello Wold" simple test. I use the NDK as shown below: /home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \ -I/home/hdias/tmp/android-ndk-r19c/toolcha

Re: Suggestions for gui frameworks to make an app in nim for android?

2019-04-04 Thread mrhdias
I tried to compile some [Examples](https://github.com/nim-lang/sdl2/tree/master/examples) from SDL Nim official package for android, but without success! Anyone have any ideas how to do it? $ /home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux

Re: Suggestions for gui frameworks to make an app in nim for android?

2019-04-04 Thread mrhdias
Yes is possible create a app in Nim for android and iOS the solution is [here](https://github.com/iffy/wiish) and works :-) After install the wiish package, sdk and ndk for android setup an app is easy: $ wiish init testapp $ nano -w testapp/dist/android/project/org.wiish.webvi

Re: Suggestions for gui frameworks to make an app in nim for android?

2019-04-05 Thread mrhdias
I've tried your solution, but it does not work. When I execute the command it gives the following result: $ nim --cc:clang --clang.exe:/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang --clang.linkerexe:/home/hdias/tmp/androi

Re: Show: dali — a pure-Nim indie assembler for Android .dex & .apk files

2019-05-14 Thread mrhdias
Fantastic work for a "hobby" project! I'm impressed!

Problem trying to compress the http response data!

2019-05-16 Thread mrhdias
I am trying to compress the responses that are sent by http: import asynchttpserver, asyncdispatch import zip/zlib proc handle(req: Request) {.async.} = if req.headers.hasKey("Accept-Encoding") and req.headers["Accept-Encoding"] == "gzip": let headers = new

Re: Problem trying to compress the http response data!

2019-05-17 Thread mrhdias
Not work with miniz package. The browser show the following message: This site can’t be reached The webpage at http://127.0.0.1:8080/ might be temporarily down or it may have moved permanently to a new web address. ERR_CONTENT_DECODING_FAILED

There are some library to display text in opengl easily?

2019-06-01 Thread mrhdias
I have tried with the [Nim freetype](https://github.com/jangko/freetype) library, but it does not work and there is no documentation. I found this page with an minimal example: [https://ralsina.me/weblog/posts/playing-with-nim.html](https://ralsina.me/weblog/posts/playing-with-nim.html) But it

Re: Nim + Flutter == bright future?

2019-06-07 Thread mrhdias
Why not Flutter in Nim? This post ([Thought Experiment: Flutter in Go](https://divan.dev/posts/flutter_go/)) show some directions to implement this idea! With DSL (Domain-specific Language) is possible build a Flutter widget tree in Nim?

Macro to create a dictionary (table) like in python!

2019-07-08 Thread mrhdias
Is it possible to create a dictionary like python by typing only: var a = {"key_1": "value_1", "key_2": "value_2"} Run Instead of? var a = {"key_1": "value_1", "key_2": "value_2"}.toTable Run or something similar to what is used by sequenc

Re: Macro to create a dictionary (table) like in python!

2019-07-09 Thread mrhdias
Great. Works. Thank you.

Re: Macro to create a dictionary (table) like in python!

2019-07-12 Thread mrhdias
What prevents it from being used only like this without "%", "@" or "toTable"? var a = {"key_1": "value_1", "key_2": "value_2"} Run It's simple and everyone understands!

Re: Macro to create a dictionary (table) like in python!

2019-07-13 Thread mrhdias
I did this small test and I don't see any problems or incompatibility. Can someone show me where the use of the "%" can fail? Can someone show me an example where the "%" is used in JSON as in tables "%{}"? import tables from strutils import `%` import json proc `%

Re: Data loss with async sockets

2019-07-26 Thread mrhdias
It is complicated at this time to use the asyncdispatch as it has several issues that have not been solved over time. At this time the Chronos is better maintained and doesn't have the same issues.

How to add a symbol to represent the infinity (∞)

2019-08-08 Thread mrhdias
The Perl 6 language has a symbol to represent infinity (∞). Anyone have any ideas on how I can implement it in nim? Just for fun! Use cases: import math import strformat proc is_prime(n: int64): bool = for i in 2 .. n-1: if (n mod i) == 0:

Re: How to add a symbol to represent the infinity (∞)

2019-08-08 Thread mrhdias
Thanks @leorize it's so easy! and work :-) const ∞ = high(BiggestInt) echo ∞ for number in -∞ .. ∞: echo number Run

Re: How to add a symbol to represent the infinity (∞)

2019-08-10 Thread mrhdias
Thank you @LeuGim for your effort in dealing with infinity... even if not really. I remembered another symbol with infinite decimal places (π), but there are many more. import math # const π = 3.141592653589793... const π = PI echo π Run These symbo

Re: How to add a symbol to represent the infinity (∞)

2019-08-11 Thread mrhdias
It's a matter of code readability and beauty :-) For example, modern code editors may replace the keyword "sqrt" with the symbol " **√** " when checking the syntax, but it would always be optional.

Re: How to add a symbol to represent the infinity (∞)

2019-08-12 Thread mrhdias
Typing these unicode symbols from the keyboard is not a big problem >From the [wikipedia](https://en.wikipedia.org/wiki/Unicode_input): "For >example, GTK+ is an ISO/IEC 14755-conformant system[citation needed]. The >beginning sequence is Ctrl+⇧ Shift+U and the ending sequence is ↵ Enter or >Sp

How do I make a table of tables in Nim?

2019-10-13 Thread mrhdias
Example: several tables containing the details of books where each entry corresponds to a different book.

Re: How do I make a table of tables in Nim?

2019-10-14 Thread mrhdias
Thanks :-)

How to create and manage a http users sessions?

2020-01-11 Thread mrhdias
I'm trying to create a session manager for a asyncrounous http server. I have a table with all created sessions. Each session should be deleted after a certain time if there are no user requests. The following prototype code (I don't know if it's correct) creates the sessions, but then when the

Re: How to create and manage a http users sessions?

2020-01-11 Thread mrhdias
Thanks, now it works. This is a prototype. I need to store the session in a cookie and check if it already exists. import asynchttpserver, asyncdispatch import tables import times import oids type Session = object map: TableRef[string, string]

Re: How to create and manage a http users sessions?

2020-01-11 Thread mrhdias
When the code is compiled gives the following warning message: template/generic instantiation of newTable from here and Warning: Cannot prove that 'result' is initialized. This will become a compile time error in the future. [ProveInit] How can I fix this? $ nim c -r test.nim

Re: How to create and manage a http users sessions?

2020-01-12 Thread mrhdias
I made some changes that corrected several warnings now it works as expected with cookies. But it still shows warnings like these: Warning: Cannot prove that 'n' is initialized. This will become a compile time error in the future. [ProveInit] Warning: 'set_session' is not GC-sa

Re: How to create and manage a http users sessions?

2020-01-12 Thread mrhdias
Thank you @enthus1ast and everyone for showing me the way. Now all code compiles without errors or warnings. import asynchttpserver, asyncdispatch import tables import times import oids import cookies import strformat import strtabs import strutils

How to upload large files efficiently and quickly with Jester?

2020-01-18 Thread mrhdias
I found this [code](https://github.com/dom96/jester/blob/master/tests/fileupload.nim) for uploading files, but it only works well for small files. With large files (100MB) it’s very slow and my cpu goes up to close to 100%! import os, re, jester, asyncdispatch, htmlgen, asyncnet

Re: How to upload large files efficiently and quickly with Jester?

2020-01-18 Thread mrhdias
Thanks @mashingan, but how do I use writeFromStream, can you show me a use case?

Re: How to upload large files efficiently and quickly with Jester?

2020-01-18 Thread mrhdias
I like the Jester but this issue is a problem when uploading multiple small videos to a website! Is there a well-documented nim web framework that supports the processing of large files?

Re: How to upload large files efficiently and quickly with Jester?

2020-01-19 Thread mrhdias
Thanks @mashingan, I tested the code and it is awesome :-) But @mashingan is right, the size of the files is different from the size of the uploaded file (I think it's an easy fix error)! Will the websocket work if I use the nginx as a frontend with ssl?

Can someone explain to me how to use the ".since" pragma?

2020-02-03 Thread mrhdias
Where can I find documentation about this pragma?

Can someone explain how to use the ".since" pragma?

2020-02-03 Thread mrhdias
In the following example, does it mean that the procedure with the pragma ".since" will be used starting with Nim 1.1? include "system/inclrtl" proc test() = echo "old test" proc test() {.since: (1, 1).} = echo "new test" test() R

Re: Can someone explain how to use the ".since" pragma?

2020-02-04 Thread mrhdias
Thanks for explaining!

Help binding the nghttp2 to something consumable by Nim!

2020-02-09 Thread mrhdias
Nim don't have a library that support http/2 protocol. I found this library and it already has a python binding. [https://github.com/nghttp2/nghttp2](https://github.com/nghttp2/nghttp2) Any ideas on how to achieve this for Nim?

Re: Help binding the nghttp2 to something consumable by Nim!

2020-02-09 Thread mrhdias
Thank @shashlick I will give it a try. But, my first approach was to use the c2nim and it works well. But, when I import the library it gives the following error: /home/hdias/test/nghttp2/nghttp2.nim(29, 16) Error: invalid token: _ (\95)| ---|--- ## Define WIN32 when build

Help to create a template/macro that reads small chunks of data from a stream.

2020-02-22 Thread mrhdias
I needed help to create a template and/or macro that would allow to read small chunks of data from a http body stream in an elegant manner. My idea can be seen in the following code: ### Replace this code block ### Begin let chunkSize = 8*1024 var

Re: Help to create a template/macro that reads small chunks of data from a stream.

2020-02-24 Thread mrhdias
Thanks @Hlaaftana but, unfortunately it doesn't work! /home/hdias/dev/tmp/test.nim(32, 25) template/generic instantiation of `async` from here /home/hdias/dev/test.nim(43, 10) template/generic instantiation of `forStream` from here /home/hdias/dev/tmp/test.nim(26, 24) templa

Re: Async web servers and database

2020-03-01 Thread mrhdias
I find this repos for mysql and postgresql: [https://github.com/wiml/nim-asyncmysql](https://github.com/wiml/nim-asyncmysql) [https://github.com/cheatfate/asyncpg](https://github.com/cheatfate/asyncpg)

Nim appears for the first time listed in the TIOBE Index!

2020-03-06 Thread mrhdias
[https://www.tiobe.com/tiobe-index](https://www.tiobe.com/tiobe-index) The Next 50 Programming Languages The following list of languages denotes #51 to #100. Since the differences are relatively small, the programming languages are only listed (in alphabetical order). (Visual) FoxPro, ABC, Act