Re: SQL Injection Attack Prevention

2020-02-27 Thread iwcoetzer
This also did not work ... method getresultThree(self: ResultEngine, connectionEngine: ConnectionEngine): SQLResults {.base.} = let results = connectionEngine.connection.dbq("SELECT * FROM dbo.DimContract WHERE EffectivePeriod >= ?value1", [("value1", 201906)])

Re: SQL Injection Attack Prevention

2020-02-27 Thread iwcoetzer
method getresultTwo(self: ResultEngine, connectionEngine: ConnectionEngine): SQLResults {.base.} = self.query = newQuery(connectionEngine.connection) self.query.statement = ("SELECT * FROM dbo.Contract WHERE EffectivePeriod >= ?value1", [("value1", 201906)])

Re: Thank you Templates

2020-02-27 Thread enthus1ast
Maybe also have a look at cligen ( [https://github.com/c-blake/cligen](https://github.com/c-blake/cligen) )

Re: Doubt! Proc and import

2020-02-27 Thread cumulonimbus
If you don't really care about speed - you could use the built in Nim compiler+virtiual machine as a script interpreter, (though IIRC there are limits by default that may surprise you and that can be removed, e.g. how many iterations a single loop can have is limited to 1,000,000 as this is

Can't deserialize recursive type from json - what am I doing wrong?

2020-02-27 Thread nhanb
I have a union type ContentNode can be either a P, Br, or Text. The P can have children of type ContentNode: type ContentNodeKind* = enum P, Br, Text ContentNode* = object case kind*: ContentNodeKind of P: pChildren*:

Share a paper: How to Print Floating-Point Numbers Accurately

2020-02-27 Thread foldl
> Arrogance definitely leads to ignorance. > \-- N/A [How to Print Floating-Point Numbers Accurately](http://kurtstephens.com/files/p372-steele.pdf) by Guy L. Steele Jr. and Jon L White. As a bonus, this paper also gives hints on how to read floating point numbers accurately.

Re: Karax: Change element value

2020-02-27 Thread hiteshjasani
Here's a better example. It's modified from some code I'm working on but should work. The H1 will update automatically as you type characters into the text field. The text field itself actually won't update without us explicitly changing its value using setInputText(). Not sure if that's

Re: Doubt! Proc and import

2020-02-27 Thread Divy
@kidandcat, I discovered the nim compiler api which seems perfect for my use. [https://forum.nim-lang.org/t/5994](https://forum.nim-lang.org/t/5994) Also, the example you provided just calls out the nim compiler without returning any exported proc inside it. (Because it's runtime) Is there any

Gedit syntax highlighting.

2020-02-27 Thread Divy
Ubuntu's inbuilt text editor Gedit is quite good for quick coding. I use the Python 3 highlighting for Nim but it would be good if we have one for Nim too. Or, is it already there?

Re: Karax: Change element value

2020-02-27 Thread jyapayne
@herdingSheep Based on @hiteshjasani's answer, this is a tested, working example: include karax / prelude import karax / [vstyles] var name: kstring = "Name will appear here" proc createDom(): VNode = result = buildHtml(tdiv): h1(id =

Thank you Templates

2020-02-27 Thread ggibson
I just wanted to say this language is fantastic. I just finished a -- to me -- medium-sized project for work yesterday that took about a week (including modifying & wrapping a C library to replace `httpclient` for static compiling with SSL/TLS, but that's another story...) and I had decided to

Re: Strange Macro Behavior

2020-02-27 Thread schmidh
Cool. Didn't realize there is getTypeImpl and getImpl. I'll try it out. Thanks.

Re: Strange Macro Behavior

2020-02-27 Thread Vindaar
I don't understand what you actually want to accomplish, but I'm pretty sure you don't actually want a generic macro. But your "would love to do that" idea actually works, with a small modification. Just don't use explicit types, but use varargs[typed]. Then you can extract the type

Re: Karax: Change element value

2020-02-27 Thread hiteshjasani
Don't know if this is the proper way to do it, but you can get/set the innerHTML. let n = getVNodeById("changeName") echo n.innerHTML n.innerHTML = kstring("my new string") Run

Strange Macro Behavior

2020-02-27 Thread schmidh
Following code runs into problems when using different types of Generators. A Generator is just a proc with no parameters that returns some type of value. [https://play.nim-lang.org/#ix=2cRz](https://play.nim-lang.org/#ix=2cRz) import macros, sugar type Generator[T] = ()

Re: Karax: Change element value

2020-02-27 Thread kidandcat
I dont think onkeyupenter is a valid event

Re: Doubt! Proc and import

2020-02-27 Thread kidandcat
You can't dynamically import a module in Nim because it is a statically compiled language, (you end with your binary, you don't distribute the source code) If you want to do that, you can compile your library as a shared library, but I'm 100% sure you don't need to do that to achieve what you

Re: DSLs and macros: custom function signature

2020-02-27 Thread cumulonimbus
If you insist (and I agree with Araq you probably shouldn't ... ), you should probably be aware of [https://nim-lang.org/docs/filters.html](https://nim-lang.org/docs/filters.html) which would allow you to do such a translation in a standard, compose-able manner -- which may boil down to just

Re: AcVim recommended for programmers

2020-02-27 Thread angluca
Use AcVim can prompt nim libs function, template, macro name ... now Easier to write nim code, Hope you like it :)

Re: Karax: Change element value

2020-02-27 Thread herdingSheep
Thank you kidandcat. But I still did not get it to work. I changed myText = "Name will appear here" to myText: kstring = "Name will appear here" as it said that it was expecting a string but was getting a kstring. Also found a typo I made myText = n.values to myText = n.value

Re: Karax: Change element value

2020-02-27 Thread kidandcat
`include karax / prelude import karax / [vstyles] var myText = "Name will apear here." proc onNameEnter(ev: Event; n: VNode) = if n.value.strip() != "": myText = n.values proc createDom(): VNode = result = buildHtml(tdiv): h1(id = "changeName"): text myText form: label(`for` = "fname"): text

Karax: Change element value

2020-02-27 Thread herdingSheep
How do I change an element valut at runtime? I know changeName.text = n.values is incorrect but what should it be? include karax / prelude import karax / [vstyles] proc onNameEnter(ev: Event; n: VNode) = if n.value.strip() != "": changeName.text

Re: SQL Injection Attack Prevention

2020-02-27 Thread Araq
> Finally - and most importantly as I've detailed above, db_odbc doesn't use > parameterisation and instead just uses string concatination, so injections > are still possible: >

Re: Is this possible?

2020-02-27 Thread Divy
Ooh! That seems perfect...I'll test that out. Thanks.

Re: DSLs and macros: custom function signature

2020-02-27 Thread vitreo12
I see your point, but I find `proc foo(args: ...): ... {.customMacro.}` to be not so user friendly compared to simply `def foo(args: ...):`. Especially considering that I am building this DSL also for teaching/learning purpose of DSP/audio algorithms, so I can expect people using it not to have

Re: DSLs and macros: custom function signature

2020-02-27 Thread Araq
Well Nim DSLs work better when they feel like Nim DSLs. In the macro you can transform and reinterpret `proc` declarations all you want, there is no need for `def`.

Re: DSLs and macros: custom function signature

2020-02-27 Thread vitreo12
What do you mean? I wouldn't want the users of my DSL to interface with the `proc` construct directly, but to deal with `my_func` (or `def`, or whatever name I come up with), as many things are abstracted in the macro to make the DSL work. By the way, the DSL is for DSP and audio synthesis,

Re: Is this possible?

2020-02-27 Thread enthus1ast
you can also consider creating shared object files and load them. Depending on your use case this might be "dynamic" enough?

Re: DSLs and macros: custom function signature

2020-02-27 Thread Araq
The idiomatic way is to use `proc foo(args: ...): ... {.customMacro.}`.

Re: DSLs and macros: custom function signature

2020-02-27 Thread vitreo12
I see. Well, it's kind of weird though that that specific syntax works with other symbols that are not `:`. I'm working towards an intermediate solution that creates temporary .nim files that turn `a : T = x` constructs into `a T = x` ones, and using these latter ones in the macro logic. It

Re: Is this possible?

2020-02-27 Thread Araq
See [https://github.com/nim-lang/Nim/blob/devel/tests/compilerapi/tcompilerapi.nim](https://github.com/nim-lang/Nim/blob/devel/tests/compilerapi/tcompilerapi.nim) and [https://github.com/nim-lang/Nim/tree/devel/tests/compilerapi](https://github.com/nim-lang/Nim/tree/devel/tests/compilerapi)

Re: Is this possible?

2020-02-27 Thread Divy
Alrightyy! Thanks all for the answer.

Re: Is this possible?

2020-02-27 Thread Divy
@yglukhov, I am keen to understand the embedding of nim compiler. Could you give a example for the same?

Re: DSLs and macros: custom function signature

2020-02-27 Thread Hlaaftana
If the lexer doesn't like it there's nothing you can do unless Nim can be changed to allow it. There are other things the lexer doesn't like outside of where they belong, such as open block statements that have commas, objects, enums, concepts, object case field: Type syntax, postfix * for

Re: Is this possible?

2020-02-27 Thread SolitudeSF
juan's snippet still resolves import at compiletime. nim is not python.

Re: Is this possible?

2020-02-27 Thread Hlaaftana
That's just another method of doing it at compile time. Nim only supports compile time importing. Because it has to compile modules. Compiling is done once for the whole program.

Re: Is this possible?

2020-02-27 Thread Divy
Thanks that helped me understand it better :) What do you have to say about @juancarlospaco 's answer?

Re: SQL Injection Attack Prevention

2020-02-27 Thread coffeepot
Hi @iwcoetzer, Araq is correct, your properQuote doesn't do anything. To get a big portion of SQL injection safety, always use parameterised queries. Never combine strings with SQL. As soon as you start combining text for queries, you're in trouble. For example, this is a bad idea:

Re: Is this possible?

2020-02-27 Thread yglukhov
I think there's some misunderstanding here. The short answer to "is this possible?" is no, this is not possible. Since nim is a compiled language, all imported modules have to be compiled and embedded in the resulting binary. It is possible in dynamic languages that offer eval of some sort, but

Re: Why not introduce the concept of Decimal in nim ???

2020-02-27 Thread JPLRouge
Thank you for the answer I understand, too bad it would have standardized

Re: Doubt! Proc and import

2020-02-27 Thread juancarlospaco
Just put all import at top of file and should work. Nim is Compiled, all import are resolved at compile time.

Re: Is this possible?

2020-02-27 Thread juancarlospaco
const some_module {.strdefine.} = "some_module" template makeAnImport(module: static[string]): untyped = import module makeAnImport(some_module) Run :)

DSLs and macros: custom function signature

2020-02-27 Thread vitreo12
Hello everyone! I am developing some DSLs using nim's macro system, and I would like to implement my own function syntax. My aim is to have the syntax to look quite similarly to Python's `def` ([https://docs.python.org/3/library/typing.html)](https://docs.python.org/3/library/typing.html\)).

Re: Doubt! Proc and import

2020-02-27 Thread trtt
Why do you want to import it at runtime?

Re: Doubt! Proc and import

2020-02-27 Thread Divy
That isn't what I wanted @kidandcat. To better explain my question: proc importNewModule(module: string) = import module # this is just for illustration, it won't work I know. How do I do that? something() Run And the module is something like this...

Re: How to get Nim running on iOS and Android using GLFM.

2020-02-27 Thread arnetheduck
Here's another way of compiling on Android natively - works great when you have an external monitor and keyboard connected to your phone (the wonders of usbc and bluetooth): [https://our.status.im/building-nimbus-on-android](https://our.status.im/building-nimbus-on-android)/

How to declare a thread-global variable?

2020-02-27 Thread trtt
What I want is a TableRef which would available for every thread. Read-only access is enough.

Re: Doubt! Proc and import

2020-02-27 Thread kidandcat
https://nim-lang.org/docs/tut1.html#modules

Doubt! Proc and import

2020-02-27 Thread Divy
So here is my code: proc runNimProcFromAnotherFile(filename: string) = #[ I need to import the filename and use the proc defined inside it...]# Run How do I import the file and return the proc inside it? Thanks.

Re: Is this possible?

2020-02-27 Thread xflywind
I have no idea.

Re: Is this possible?

2020-02-27 Thread Divy
Alright thanks anyway for the answer :) That atleast got me halfway...

Re: Is this possible?

2020-02-27 Thread Divy
How can I return the value that is returned in a proc inside the timeit_temp.nim?

Re: Is this possible?

2020-02-27 Thread xflywind
I mean if you want to import module dynaically, yon can write it directly into file or use when flag. for example, import streams, strformat let module = readline(stdin) tempFile = getTempDir() & "timeit_temp.nim" var temp = newFileStream(tempFile, fmWrite)

Re: Is this possible?

2020-02-27 Thread Stefan_Salewski
> please write Nim code like this Maybe I missed a lot, but I have no idea what that part of your answer may mean and how it may help for the initial question.

Re: SQL Injection Attack Prevention

2020-02-27 Thread Araq
Since your `properQuote` doesn't quote at all, it is neither correct nor safe. To prevent SQL injections, use the existing `db_*` modules from the stdlib.

Re: Uploading large files via httpclient request

2020-02-27 Thread adilh
Hello Zedeus, thanks for the pointer! I appreciate it! I see that your changes would be for a POST request. Would they also work for a PUT request? Many thanks and hope your day goes well, adil