Novice parallelization question

2024-07-24 Thread morturo
It is not efficient to accomplish this task in the browser. The JS method for handling threads is by using workers, and even if it is possible to abstract over it, the cost will be too high.

Cheap exceptions, opinionated error handling

2024-06-04 Thread morturo
This looks like the complete opposite approach used by Zig. It's limited, and I don't like that. I'd rather go with the Zig approach—an enum that grows at compile time, without the Rust problem of converting results.

Which IDE to use in 2024?

2024-05-23 Thread morturo
Helix is quite good and easy to set up. The only problem is that I couldn't get it working with Nim.

get object field by variable

2024-05-06 Thread morturo
It should be possible to use macro magic to do that though.

Would Nim modules or available Nim web frameworks suffice for an e-commerce back-end?

2024-02-23 Thread morturo
Can you tell me more about the "problems" with async? As much as I dislike closures, that is not a problem in itself.

`nph` opinionated formatter v0.4

2024-02-09 Thread morturo
"don't-waste-a-line", but... let x = somevariable .function0(32) .function1(42) Run and not let x = somevariable .function0(32) .function1(42) Run

Hexagonal Architecture, Domain Driven Design, and Event Sourcing in Nim

2024-01-16 Thread morturo
This is not related. I've seen this pattern many times at work, and I really can't figure it out. Why is this happening? I may be missing something... proc credit*(self: WalletDomain, walletId: UUID, transactionId: string, coins: int): Wallet = try: result = self

9999999999999999.0 – 9999999999999998.0

2024-01-11 Thread morturo
it works with decimal but not with floats import decimal/decimal let a = newDecimal(".0") let b = newDecimal("9998.0") echo a - b Run

`nph` opinionated formatter v0.3

2024-01-09 Thread morturo
May be consistent but is ugly af.

Sum types, 2024 variant

2024-01-02 Thread morturo
This is great! I've been waiting for something like this for a long time.

Nimforum custom theme

2023-12-09 Thread morturo
Too much freedom is a curse. The outcome it would achieve can be attained by using a client-side extension like Stylus. This dark theme is awesome, by the way.

Ideas about strings

2023-11-30 Thread morturo
Good enough for me! I hope we can have more control over lifetimes in the future.

How to prevent nim language server plugin from spawning multiple instances of nimsuggest

2023-08-08 Thread morturo
If you are using vscode, try add this line on you `settings.json`: `"nim.project": ["./src/main.nim"],` It solves the spawning problem and also the extreme cpu usage.

unsure about lifetime-tracking hooks

2023-08-07 Thread morturo
I'm trying to understand how the [lifetime-tracking hooks](https://nim-lang.github.io/Nim/destructors.html) work, but I'm not sure if I'm doing it correctly. The code below is an implementation of a slab (an array with reusable slots). It is almost an exact copy of the [example](https://nim-lan

Rc[T] implementation

2023-08-01 Thread morturo
type Rc[T] = object data: ptr T refs: ptr int proc rc[T](value: sink T): Rc[T] = result.data = cast[ptr T](alloc(sizeof(T))) copyMem(result.data, addr value, sizeof(T)) result.refs = cast[ptr int](alloc(sizeof(int))) result.refs[] = 1

converter not working unless I explicitly use it

2023-07-22 Thread morturo
I have a converter, from `proc(Request, string)` to `proc(Request)`, but the compiler refuses to accept it unless I explicitly call it. The code below works fine, but if I remove `.toRequestHandler()` it won't compile. What am I doing wrong? import mummy, mummy/routers pro

Using pragmas to generate methods

2022-09-22 Thread morturo
I need to generate 2 methods for each type marked by a pragma. Can anyone show me how to begin? import std/macros macro serializable*(td) = result = td type SignInPacket {.serializable.} = ref object email: string password: string

How to get cursor position?

2022-09-16 Thread morturo
We have a way to set the cursor position ([setCursorPos](https://nim-lang.org/docs/terminal.html#setCursorPos%2CFile%2Cint%2Cint)), but no way to get the cursor position.

Any way to prevent GC from collecting some values?

2022-09-15 Thread morturo
Thanks man, that's what I need.

Any way to prevent GC from collecting some values?

2022-09-15 Thread morturo
I need to pass some data to an external env as a pointer and use this pointer later, but GC will collect this value since there is no ref.

I need to alloc a string

2022-08-12 Thread morturo
I'm feeling stupid now

I need to alloc a string

2022-08-12 Thread morturo
I need to alloc a string of size N, I'm currently using `repeat('\0', n)` to do this, any better way?

downloading big files

2022-07-28 Thread morturo
If anyone have the same problem in the future (download big files), here is my solution: It's a simple and single purpose script to download files (no proxy or redirect support).

downloading big files

2022-07-25 Thread morturo
I need to download big files and I have this code: proc pipeTo(input: Stream, output: Stream, chunkSize = 512) = var buff = repeat("\0", chunkSize) while true: let len = input.readDataStr(buff, 0..https://i.imgur.com/7DBlgbw.png) In theory, it should download a ch

streams and memory usage

2022-07-25 Thread morturo
I have this code: proc pipeTo(input: Stream, output: Stream, chunkSize = 512) = var buff = repeat("\0", chunkSize) while true: let len = input.readDataStr(buff, 0..

Export to android

2022-06-21 Thread morturo
I need to export my app to android and I'm using a lib written in C (enet), how would I do that? Can I just import the .so file normally if I compile the lib using NDK?

Question about pointers

2022-06-20 Thread morturo
Thanks man

Question about pointers

2022-06-20 Thread morturo
I have this code: let buff = alloc(4) let srcBuff = [25'u8, 0, 0, 0] copyMem(buff, srcBuff.unsafeAddr, 4) let value = cast[ptr int32](buff)[] dealloc(buff) echo $value Run Does `value` is now a 'managed' var? Can i safelly dealloc the buffer like I

read and write from/to seq[byte]

2022-06-19 Thread morturo
Thanks, I will change that.

read and write from/to seq[byte]

2022-06-19 Thread morturo
I need to read and write from/to a seq[byte] but something is wrong e.e BinaryWriter: BinaryReader: I'm testing with this code: import ./binaryWriter let writer = newBinaryWriter(256) writer.write(25'i32)

How to copy dir using nimscript?

2022-06-18 Thread morturo
I have a `config.nims` and I want to copy a dir to the bin dir using a task but I'm getting this error: `Error: this proc is not available on the NimScript/js target; usage of 'copyDir' is an {.error.} defined at...` I tried to use the `copy` command like this: `copy ./res ./bin` but it doesn't

Learning threads

2022-06-15 Thread morturo
Can anyone tell me what am I missing here? I'm trying to learn about nim types and threads. I made this small example and theoretically it should work. The output is: Thread started! Input: 1 Handling command... Result sent back. Thread stopped! Run Th

could not load: lua(|5.1|5.0).dll

2022-06-11 Thread morturo
I created a lua lib using nim but only works if I put the lua dll in the same dir as the lib. I'm not embedding lua. Any ideas about how to solve this? If I remove the dll I get the error `could not load: lua(|5.1|5.0).dll`.

Problem with --threads:on

2022-05-16 Thread morturo
I tried without nimble, using this line `nim c --colors:on --path:C:\Users\psore\.nimble\pkgs\lua-1.0 -o:.\bin\server.exe .\src\main.nim` to compile my server, this will compile the binary and I can run int with no problems, but if I include `--threads:on` and compile it, will run and close imm

Problem with --threads:on

2022-05-15 Thread morturo
This is really strange and disappointing, with a `nim.cfg` inside `src` folder with just `--threads:on` inside I can, inside my "main" nim file have this line `var thread: Thread[int]`, and it will compile but the "Hello World!" message won't appear. If I rename the `nim.cfg` to `package_name.cf

Problem with --threads:on

2022-05-15 Thread morturo
[nim.cfg](https://i.imgur.com/U5IwpEO.png) [package_name.cfg](https://i.imgur.com/WSse4IT.png) Two prints showing the result, as you can see the `.cfg` file is inside the `src` folder.

Problem with --threads:on

2022-05-15 Thread morturo
I create a new project and did all those steps again, the problem seem to be with the `nim.cfg`, if I'm using `package_name.cfg` it works properly but if I'm using `nim.cfg` it doesn't works.

Problem with --threads:on

2022-05-15 Thread morturo
I'm using `nimble run` and I have a `nim.cfg` at `src` folder with `--threads:on` inside.

Problem with --threads:on

2022-05-15 Thread morturo
Just started a new project to learn about threads with nim. when isMainModule: echo("Hello, World!") Run When I compile and run it prints "Hello, World!", but if I compile with `--threads:on` nothing happens. What am I missing here?