std.net.curl and POST-requests with files

2023-05-10 Thread Vindex via Digitalmars-d-learn
The [std.net.curl](https://dlang.org/phobos/std_net_curl.html) module provides these functions: ```d T[] post(T = char, PostUnit)(const(char)[] url, const(PostUnit)[] postData, HTTP conn = HTTP()) T[] post(T = char)(const(char)[] url, string[string] postDict, HTTP conn = HTTP()) ``` How can

mixin template

2022-05-23 Thread Vindex via Digitalmars-d-learn
I have this code: ``` import std.array, std.exception, std.stdio; mixin template RealizeException() { this(string msg, string file = __FILE__, size_t line = __LINE__) { super(msg, file, line); } } class WrongUsage : Exception { mixin RealizeException; this(string[]

Re: Filling an array at compile time

2022-02-09 Thread Vindex via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:01:15 UTC, Anonymouse wrote: On Wednesday, 9 February 2022 at 08:12:52 UTC, Vindex wrote: [...] I would do this. ``` import std; alias Record = Tuple!(string, string, string); static immutable string[][] table = () { string[][] table; string

Filling an array at compile time

2022-02-09 Thread Vindex via Digitalmars-d-learn
Will the loop (foreach) run at compile time? How can I make it work at compile time? ``` import std.csv, std.stdio; alias Record = Tuple!(string, string, string); immutable string[][] table; shared static this() { string csvText = import("file.csv"); foreach (record;

Re: Structured binding declaration (like in C++)

2021-10-14 Thread Vindex via Digitalmars-d-learn
On Thursday, 14 October 2021 at 15:29:13 UTC, MoonlightSentinel wrote: On Wednesday, 13 October 2021 at 20:02:05 UTC, Vindex wrote: Is there a decomposition for tuples and other data structures? No, but you can emulate it, e.g. by using AliasSeq: ```d import std.meta : AliasSeq; import

Structured binding declaration (like in C++)

2021-10-13 Thread Vindex via Digitalmars-d-learn
Is there a decomposition for tuples and other data structures? For example, ``` auto t = tuple(1, "2"); auto (x, y) = t; // or auto (x, y) = t.expand; ```

Re: Including a file

2021-07-18 Thread Vindex via Digitalmars-d-learn
On Sunday, 18 July 2021 at 17:31:24 UTC, Adam D Ruppe wrote: On Sunday, 18 July 2021 at 17:28:07 UTC, Vindex wrote: Error: file "thing.json" cannot be found or not in a path specified with -J You need to specify the path where it is found with the -J switch to the compiler. Like `ldc2 -J.

Re: Including a file

2021-07-18 Thread Vindex via Digitalmars-d-learn
On Sunday, 18 July 2021 at 17:31:24 UTC, Adam D Ruppe wrote: On Sunday, 18 July 2021 at 17:28:07 UTC, Vindex wrote: Error: file "thing.json" cannot be found or not in a path specified with -J You need to specify the path where it is found with the -J switch to the compiler. Like `ldc2 -J.

Including a file

2021-07-18 Thread Vindex via Digitalmars-d-learn
One of my library modules (for example, libmylib) has the line `immutable string jsonText = import("thing.json")` When I try to build a program with this (already installed) library I see error ``` ldc2 source/main.d -ofmyprogram -L-l:libmylib.so.0 Error: file "thing.json" cannot be found

Re: Dimensions in compile time

2021-02-08 Thread Vindex via Digitalmars-d-learn
Thanks everyone! The solution that works for me now looks like this: template ndim(T) { static if (std.traits.isArray!T) { static if (is(typeof(T.init[0]))) { alias SubArrayType = typeof(T.init[0]); enum ndim = ndim!SubArrayType + 1; } else

Dimensions in compile time

2021-02-08 Thread Vindex via Digitalmars-d-learn
size_t ndim(A)(A arr) { return std.algorithm.count(typeid(A).to!string, '['); } Is there a way to find out the number of dimensions in an array at compile time?

Re: std.net.curl and HTTP.responseHeaders

2021-02-04 Thread Vindex via Digitalmars-d-learn
Thank you! For other sites, the first solution somehow worked (I did it following the example from the documentation).

std.net.curl and HTTP.responseHeaders

2021-02-03 Thread Vindex via Digitalmars-d-learn
Header requests to Wikipedia give 405 error for some reason. ``` import std.stdio, std.net.curl; void main() { auto url = "https://en.wikipedia.org/wiki/Passenger_pigeon;; auto http = HTTP(); options(url, http); writeln(http.responseHeaders); } ``` Output: ```

Re: HTTP-methods and encoding

2018-04-08 Thread Vindex via Digitalmars-d-learn
On Sunday, 8 April 2018 at 06:51:22 UTC, ikod wrote: On Saturday, 7 April 2018 at 23:54:21 UTC, Vindex wrote: On Saturday, 7 April 2018 at 15:58:14 UTC, Seb wrote: On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote: There is an error on some sites when using HTTP-methods

Re: HTTP-methods and encoding

2018-04-07 Thread Vindex via Digitalmars-d-learn
On Saturday, 7 April 2018 at 15:58:14 UTC, Seb wrote: On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote: There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post): std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8 Is

HTTP-methods and encoding

2018-04-07 Thread Vindex via Digitalmars-d-learn
There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post): std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8 Is there a beautiful way around it? For the GET-method I use the download() and readText(). But for the POST-method I

Re: Static library building

2018-03-19 Thread Vindex via Digitalmars-d-learn
On Monday, 19 March 2018 at 14:31:05 UTC, Adam D. Ruppe wrote: On Monday, 19 March 2018 at 14:07:52 UTC, Vindex wrote: dmd main.d -L-L. -L-l:mod.a It still needs to know where to find the import file to get D information like names and types out of it that aren't in the lib (well they sorta

Static library building

2018-03-19 Thread Vindex via Digitalmars-d-learn
'main.d': import pack.mod; void main() { fn("Hello"); } 'mod.d': module pack.mod; void fn(string s) { import std.stdio; writeln("Hello"); } Both files are in the same directory. So all is well: dmd main.d mod.d So all is bad: dmd mod.d -lib dmd main.d -L-L. -L-l:mod.a main.d(1):