Path.GetDirectoryName for D?

2018-10-18 Thread Dr.No via Digitalmars-d-learn
Are there a function like C#'s Path.GetDirectoryName() (https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getdirectoryname?redirectedfrom=MSDN=netframework-4.7.2#System_IO_Path_GetDirectoryName_System_String_) in D standard library or some dub package? just checking if there's one, so

Re: Process in parallel and output result to stdout theread-safely

2018-09-11 Thread Dr.No via Digitalmars-d-learn
On Monday, 10 September 2018 at 20:30:52 UTC, Dr.No wrote: On Saturday, 8 September 2018 at 14:26:45 UTC, ag0aep6g wrote: [...] Yes, it does only happens at line breaks. I hadn't realized that until you mentioned. It does gets in place of \r and \n, that's why there's all in one line when

Re: Process in parallel and output result to stdout theread-safely

2018-09-10 Thread Dr.No via Digitalmars-d-learn
On Saturday, 8 September 2018 at 14:26:45 UTC, ag0aep6g wrote: On 09/03/2018 08:13 PM, Dr.No wrote: But it in the middle of output, I got output like this: outjson = {"barCode":"20","ade":"20"}♪◙outjson = {"barCode":"X21","ade":"21"} also there's that extra ♪◙ character. Thos sounds

Re: Process in parallel and output result to stdout theread-safely

2018-09-08 Thread Dr.No via Digitalmars-d-learn
Does anyone have some tips to try trace the error with debug or so? I haven't fixed this issue yet... any help is very appreciated

Re: std.process: spawnProcess

2018-09-07 Thread Dr.No via Digitalmars-d-learn
On Friday, 7 September 2018 at 14:36:42 UTC, Russel Winder wrote: From what I can see, processes created with std.process: spawnProcess are not terminated when the creating process terminates, i.e. it seems Config.detached is the default for these process. Is there a way of all spawned

Process in parallel and output result to stdout theread-safely

2018-09-03 Thread Dr.No via Digitalmars-d-learn
so I'im doing an expansive operation with a file, to try speed up, i switch to using parallel but keeping in the otuput printing thread-safe. But for some reason, even using synchonized, it doesn't work as expected, for example, it output multiples results on same time, as in the example

Re: Is this a good idea?

2018-09-01 Thread Dr.No via Digitalmars-d-learn
On Saturday, 1 September 2018 at 17:08:25 UTC, Peter Alexander wrote: On Saturday, 1 September 2018 at 16:20:11 UTC, Dr.No wrote: why move flush to outside the synchronized block? flush should be thread safe. In general, yiu want as little code as possible to run under the lock. Not that

Re: Is this a good idea?

2018-09-01 Thread Dr.No via Digitalmars-d-learn
On Thursday, 30 August 2018 at 21:09:35 UTC, Peter Alexander wrote: On Thursday, 30 August 2018 at 19:59:17 UTC, Dr.No wrote: I would to process the current block in parallel but priting need to be theread-safe so I'm using foreach(x; parallel(arr)) { auto a = f(x); auto res = g(a);

Is this a good idea?

2018-08-30 Thread Dr.No via Digitalmars-d-learn
I would to process the current block in parallel but priting need to be theread-safe so I'm using foreach(x; parallel(arr)) { auto a = f(x); auto res = g(a); synchronized { stdout.writeln(res); stdout.flush(); } } Since f() and g() are some heavy functions, I'd

QWebView requesting QtE5WebEng32.so on windows

2018-07-21 Thread Dr.No via Digitalmars-d-learn
So I went to try out QWebView on Windows from this wrapper: https://github.com/MGWL/QtE5 all the examples went fine until I tried QWebView: https://github.com/MGWL/QtE5/blob/master/examples/webview.d I compile using this command line: dmd -m32 webview.d qte5.d -oflol but when I run I get

Re: Convert path to file system path on windows

2018-06-30 Thread Dr.No via Digitalmars-d-learn
Thank you very much u all guys.

Can I parse this kind of HTML with arsd.dom module?

2018-06-23 Thread Dr.No via Digitalmars-d-learn
This is the module I'm speaking about: https://arsd-official.dpldocs.info/arsd.dom.html So I have this HTML that not even parseGarbae() can del with: https://hostname.com/?file=foo.png=baa;>G! There is this spaces between "href" and "=" and "https..." which makes below code fails:

Re: How do I filter out this type?

2018-06-23 Thread Dr.No via Digitalmars-d-learn
On Friday, 22 June 2018 at 17:20:03 UTC, Steven Schveighoffer wrote: On 6/22/18 1:07 PM, Dr.No wrote:    static if(is(typeof(__traits(getMember, B, field) == A[]))) static if(is(typeof(__traits(getMember, B, field)) == A[])) Note the slight change in parentheses. -Steve

How do I filter out this type?

2018-06-22 Thread Dr.No via Digitalmars-d-learn
In the below code, "A[] found" is never printed. What's the proper way to check for this type? import std.stdio; import std.traits : FieldNameTuple; class A { } class B { string foo; string baa; A[] list; } void main() { static foreach(field; FieldNameTuple!B) {

Convert path to file system path on windows

2018-06-21 Thread Dr.No via Digitalmars-d-learn
How can I do that with D? In C# you can do that: var filename = @"C:\path\to\my\file.txt"; var file = new Uri(filename).AbsoluteUri; // file is "file:///C:/path/to/my/file.txt" How can I do that in D?

How can I enforce an parameter to be constant know at compile time?

2018-06-12 Thread Dr.No via Digitalmars-d-learn
I'd like help of compiler to check this: consider this: int f(int n) { m_n = n; } f(10); // ok f(myTampleteFunction!(compileTimeParameter)); // ok enum n = 10; f(n); // I won't use this, but should also be ok int x = 10; f(x); // error int g() { return 20; } f(g); // error How can I

run "thread" with memory space similar a new process

2018-06-01 Thread Dr.No via Digitalmars-d-learn
Thread is "limited" to local storage, so static variables (including the ones marked as __gshared in D) which are globals are shared between the threads. So, calling not pure functions which depend upon global variables prevent parallization for that global-dependence. (please tell me I got

Re: How do I make this function thread safe?

2018-06-01 Thread Dr.No via Digitalmars-d-learn
On Friday, 1 June 2018 at 02:30:34 UTC, Paul Backus wrote: On Thursday, 31 May 2018 at 19:26:12 UTC, Dr.No wrote: My application create some HTML which is then converted to PDF by wkhtmltopdf library. I'm trying to figure out how make the PDF generation run parallel, currently, it's running

How do I make this function thread safe?

2018-05-31 Thread Dr.No via Digitalmars-d-learn
My application create some HTML which is then converted to PDF by wkhtmltopdf library. I'm trying to figure out how make the PDF generation run parallel, currently, it's running linearly. My guess is wkhtmltopdf internal variables is preventing parallelization. But I'm new to parallization and

Re: question about keeeping reference to toStringz()

2018-05-30 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 20:43:48 UTC, Ali Çehreli wrote: On 05/30/2018 01:09 PM, Dr.No wrote: > consider a C function with this prototype: >> void foo(const char *baa); > > Does it means I should do: > >> string s = ...; >> auto cstring = s.toStringz; >> foo(cstring); > > rather just: > >>

question about keeeping reference to toStringz()

2018-05-30 Thread Dr.No via Digitalmars-d-learn
The documentation says: Important Note: When passing a char* to a C function, and the C function keeps it around for any reason, make sure that you keep a reference to it in your D code. Otherwise, it may become invalid during a garbage collection cycle and cause a nasty bug when the C code

How do I break from loop when using parallel()?

2018-05-28 Thread Dr.No via Digitalmars-d-learn
import std.parallelism : parallel; foreach(t; parallel(arr)) { if(!doSomething(t)) { return false; } } It reuturns the run time error:

Re: using wkhtmltopdf with D

2018-05-28 Thread Dr.No via Digitalmars-d-learn
On Monday, 28 May 2018 at 02:10:48 UTC, sarn wrote: On Monday, 28 May 2018 at 01:28:10 UTC, Dr.No wrote: What's likely the reason of the crash? mismatch between D and C memory alignment? From an ABI point of view, the raw pointers won't care about the memory structure they point to. The

using wkhtmltopdf with D

2018-05-27 Thread Dr.No via Digitalmars-d-learn
I'm trying to use wkhtmltopdf[1] with D. I converted this header[2] with little modification using htod tool which resulted in this[3]. The libray is passed to link using: pragma(lib, "wkhtmltox.lib"); (that file is in wkhtmltopdf\lib folder) and the module imported with: import pdf; but it

convert string to wchar[]

2018-05-26 Thread Dr.No via Digitalmars-d-learn
What's D's way to do that? I need it to be mutable array of wchar because a Windows function requires that. Alternative to go down to using pointers, which would be something like: wchar[] w = new wchar[s.length]; memcpy(w.ptr, s.ptr, s.length);

Re: How to convert ubyte[] to uint?

2018-05-23 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 23 May 2018 at 19:49:27 UTC, Jonathan M Davis wrote: On Wednesday, May 23, 2018 19:36:07 Dr.No via Digitalmars-d-learn wrote: [...] As the template constraint in the error message says, read requires an input range. Static arrays are not input ranges. You need to give

How to convert ubyte[] to uint?

2018-05-23 Thread Dr.No via Digitalmars-d-learn
read fails with both uint and ulong on 64bit platform: Error: template std.bitmanip.read cannot deduce function from argument types !(ulong)(ubyte[8]), candidates are: C:\ldc2-1.9.0-windows-x64\bin\..\import\std\bitmanip.d(3213,3): std.bitmanip.read(T, Endian endianness =

Can I work out error: reinterpreting cast from const(ubyte)* to const(uint)* is not supported in CTFE?

2018-05-21 Thread Dr.No via Digitalmars-d-learn
I'm trying to do some hashing at compile time with xxhash algorithm but I get this error: ..\..\..\AppData\Local\dub\packages\xxhash-master\xxhash\src\xxhash.d(39,37): Error: reinterpreting cast from const(ubyte)* to const(uint)* is not supported in CTFE this is line 39

How do I see the flags passed from dub to the compiler?

2018-05-21 Thread Dr.No via Digitalmars-d-learn
where's this stored?

Re: Temporary file creation for unittests

2018-05-21 Thread Dr.No via Digitalmars-d-learn
On Monday, 21 May 2018 at 15:16:11 UTC, Atila Neves wrote: On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote: Hi, What's the current official position on how to create temporary files for use during a unittest. I found Not official, but... import unit_threaded;

Re: Can I infer the type from this?

2018-05-19 Thread Dr.No via Digitalmars-d-learn
On Sunday, 20 May 2018 at 02:01:20 UTC, Alex wrote: On Sunday, 20 May 2018 at 01:41:03 UTC, Dr.No wrote: I'd like to pass a symbol as paramater (class static member0 and at same time get the type of this, something like this: template myTemp(alias s) { enum myTemp =

Can I infer the type from this?

2018-05-19 Thread Dr.No via Digitalmars-d-learn
I'd like to pass a symbol as paramater (class static member0 and at same time get the type of this, something like this: template myTemp(alias s) { enum myTemp = templateFunction!(??)(s.stringof); } the templateFunction has this signature: int templateFunction(T)(string

Re: How is == operator implemented for string type?

2018-05-19 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 18:56:26 UTC, Steven Schveighoffer wrote: On 5/16/18 2:45 PM, Dr.No wrote: where is the actual source code implementation? https://github.com/dlang/druntime/blob/7e3b4086fee8f2e2a6882942c677acc28df527ee/src/object.d#L3479 -Steve thanks

Re: Temporary file creation for unittests

2018-05-18 Thread Dr.No via Digitalmars-d-learn
On Friday, 18 May 2018 at 15:30:05 UTC, Uknown wrote: On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote: Hi, What's the current official position on how to create temporary files for use during a unittest. I found https://github.com/dlang/phobos/pull/5788 but it seems to be

How is == operator implemented for string type?

2018-05-16 Thread Dr.No via Digitalmars-d-learn
where is the actual source code implementation?

there's no gdc for windows?

2018-05-15 Thread Dr.No via Digitalmars-d-learn
Has gdc been supported for Windows? if so, where can I find it? I've only find Linux versions so far...

Re: How to curl!

2018-05-01 Thread Dr.No via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 22:51:01 UTC, IntegratedDimensions wrote: On Tuesday, 1 May 2018 at 22:08:50 UTC, Dr.No wrote: On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions wrote: Trying to curl basic stuff but std.net.curl isn't cooperating: curl

Is build a 64 bit version worth if I'm looking for better perfomance?

2018-05-01 Thread Dr.No via Digitalmars-d-learn
Looking for make application run fast as possible, aside optimization in the source code, is using 64 bit over 32 really worth?

Re: How to curl!

2018-05-01 Thread Dr.No via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions wrote: Trying to curl basic stuff but std.net.curl isn't cooperating: curl "https://www.googleapis.com/youtube/v3/channels; -G -d part=contentDetails -d forUsername=test -d key=somekey [...] Just a wild guess, do you have the SSL

Can I convert the Range returned by asUpperCase to ubyte[]?

2018-05-01 Thread Dr.No via Digitalmars-d-learn
I'm trying to do an optimization here: a hash function which expect a ubye[] array as argument, would just work if I cast string to ubyte[] but I need to convert it to upper case, so I'd like to do that lazily, so that the byte is converted to its upper case version soon as it's requested. I'm

Re: Get files from directory sorted by name

2018-04-27 Thread Dr.No via Digitalmars-d-learn
On Friday, 27 April 2018 at 14:48:00 UTC, Jesse Phillips wrote: On Thursday, 26 April 2018 at 16:59:45 UTC, Dr.No wrote: On Wednesday, 25 April 2018 at 19:25:11 UTC, Jesse Phillips wrote: On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote: Is there something implemented already to get

readonly member (but assignable at constructor time)

2018-04-26 Thread Dr.No via Digitalmars-d-learn
In C# you can have a readonly member assignable either at declaration or constructor time, like this: class C { readonly myClass mc; this() { mc = new myClass(); } void doSomething() { mc = new myClass(); // wrong! result in compiler error, mc is readonly } } Does D

What's wrong with this alias?

2018-04-26 Thread Dr.No via Digitalmars-d-learn
consider this: module report; // output an error message on stderr void error(A...)(string fmt, A args) { import colorize : fg, color, cwriteln, cwritefln, cwrite; stderr.cwrite("error: ".color(fg.yellow)); cwritefln(fmt.color(fg.yellow), args); } void

Re: Get files from directory sorted by name

2018-04-26 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 19:25:11 UTC, Jesse Phillips wrote: On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote: Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find how do that with

Re: Get files from directory sorted by name

2018-04-26 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 18:06:07 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 17:34:41 Dr.No via Digitalmars-d-learn wrote: Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find

Get files from directory sorted by name

2018-04-25 Thread Dr.No via Digitalmars-d-learn
Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find how do that with dirEntries()

Re: How to use std.meta.Filter?

2018-04-21 Thread Dr.No via Digitalmars-d-learn
On Saturday, 21 April 2018 at 17:15:47 UTC, Jonathan M Davis wrote: On Saturday, April 21, 2018 16:05:22 Dr.No via Digitalmars-d-learn wrote: import std.meta : Filter; enum isNotReservedSymbol(string name) = name != "none" && name != "lastToken"; enum string[] m

How to use std.meta.Filter?

2018-04-21 Thread Dr.No via Digitalmars-d-learn
import std.meta : Filter; enum isNotReservedSymbol(string name) = name != "none" && name != "lastToken"; enum string[] members = staticMembers!Token; static foreach(member; Filter!(isNotReservedSymbol, members)) {{ This return the error: Error: template instance

get literal symbol name without base class/struct as string

2018-04-17 Thread Dr.No via Digitalmars-d-learn
give structs like this: struct A { int a = 10; string s = "haha"; } struct B { A aDetails; } I'd like to do this and store that symbol name as string (my goal is store the member name); string memberName = magic(B.aDetails.s); writeln(memberName); // otuput

How do you check for nonempty string?

2018-04-13 Thread Dr.No via Digitalmars-d-learn
s.length > 0 or s !is null? used to C++/C#'s world I cautch myself doing something like this: if(s !is null && s.length > 0 && s[0] == '/) then a I remembered the D's way, which length is probably a function not a property (in the C++/C#'s sense, which needs this as first parameter, hence

Proper way to fix core.exception.UnicodeException@src\rt\util\utf.d(292): invalid UTF-8 sequence by File.readln()

2018-04-06 Thread Dr.No via Digitalmars-d-learn
I'm reading line by line the lines from a CSV file provided by the user which is assumed to be UTF8. But an user has provided an ANSI file which resulted in the error: core.exception.UnicodeException@src\rt\util\utf.d(292): invalid UTF-8 sequence (it happend when the user took the