Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-05 Thread rumbu via Digitalmars-d-learn


I'm not sure if this works quite as intended, but I was at 
least able to produce a UTF-16 decode error rather than a UTF-8 
decode error by setting the file orientation before reading it.


import std.stdio;
import core.stdc.wchar_ : fwide;
void main(){
auto file = File("UTF-16LE encoded file.txt");
fwide(file.getFP(), 1);
foreach(line; file.byLine){
writeln(file.readln);
}
}


fwide is not implemented in Windows: 
https://msdn.microsoft.com/en-us/library/aa985619.aspx





Re: Mysql-native - full database backup

2017-01-05 Thread Geert via Digitalmars-d-learn

On Thursday, 5 January 2017 at 21:47:55 UTC, Daniel Kozák wrote:
Geert via Digitalmars-d-learn 
 napsal Čt, led 5, 2017 v 
3∶13 :

[...]


[...]


Nice function. Thanks!


Re: Mysql-native - full database backup

2017-01-05 Thread Daniel Kozák via Digitalmars-d-learn
Geert via Digitalmars-d-learn  
napsal Čt, led 5, 2017 v 3∶13 :

On Thursday, 5 January 2017 at 01:16:09 UTC, crimaniak wrote:

On Monday, 2 January 2017 at 15:29:08 UTC, Geert wrote:

Hi!

How can i create a full database backup using mysql-native for D?
 Too common question. Do you have problems with driver usage? Do you 
have problems with database backup schema?


Sorry for not being specific, my english it's not quite good. I 
thought i could use a specific mysql-native method (like 
"execProcedure") for making database backups, but it seems it doesn't 
have it.


Anyway, i ended up using mysqldump with executeShell function:

string query = "mysqldump -uroot -ptest_pass test_db > 
/home/user/mydb_backup.sql";

executeShell(query);


For those who use lampp:

string query = "/opt/lampp/bin/mysqldump -uroot -ptest_pass test_db > 
/home/user/mydb_backup.sql";

executeShell(query);


Yep, usin mysqldump is fine I've been using it for a quite time now

void synchronizeDatbase(string host, string port, string portDst, 
string dbName)

{
   import std.process: spawnShell, wait;

   writefln("Host: %s, DB: %s", host, dbName);
   auto pid = spawnShell("mysqldump --max_allowed_packet=1024M -C -h " 
~ host ~ " -P" ~ port ~
 " -u" ~ credentials.user ~ " -p" ~ 
credentials.pwd ~
 " -R --add-drop-database --skip-triggers 
--ignore-table=cars.history -B " ~ dbName ~ " |" ~
 " mysql -u" ~ credentials.user ~ " -p" ~ 
credentials.pwd ~

 " -h 127.0.0.1 -P" ~ portDst);
   wait(pid);
}




Re: Parsing a UTF-16LE file line by line?

2017-01-05 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/4/17 6:03 AM, Nestor wrote:

Hi,

I was just trying to parse a UTF-16LE file using byLine, but apparently
this function doesn't work with anything other than UTF-8, because I get
this error:

"Invalid UTF-8 sequence (at index 1)"

How can I achieve what I want, without loading the entire file into memory?

Thanks in advance.


I have not tested much with UTF16 and std.stdio, but I don't believe the 
underlying FILE * being used by phobos has good support for it.


In my testing, for instance, byLine with a non-ascii delimeter didn't 
work at all.


On Windows 64-bit, MSVC simply ignores any attempts to change the width 
of the stream.


I wouldn't hold out much hope for this to be fixed.

-Steve


Re: Sorted ranges in combined sorted order?

2017-01-05 Thread Ali Çehreli via Digitalmars-d-learn

On 12/31/2016 02:28 PM, Matthew Gamble wrote:

> Please let me know if you have any suggestions.

I've seen this just now. Random and trivial observations:

- Assigning to _minPosResult could be in a separate function like 
prepareMinPosResult() called from multiple places


- There could be a unittest for an empty array (and an empty range element)

- It's personal taste and not obvious from its documentation but 
minPos() and most (all?) other Phobos algorithms can take proper lambdas 
as well:


_source.minPos!((a, b) => a.front() < b.front())()

> P.S. Ali, I a big fan of your book on D; it was the first book I read on
> D and gave me a great start. :)

Very happy to hear that! :)

Ali



Re: Resources for using std.allocator

2017-01-05 Thread bachmeier via Digitalmars-d-learn

On Wednesday, 4 January 2017 at 04:50:55 UTC, xtreak wrote:
I am newbie to D learning it for sometime using Ali's book. I 
came across std.experimental.allocator and read through 
http://dlang.org/library/std/experimental/allocator/building_blocks.html . Can someone explain me the actual benefits of using this and if so any benchmarks explaining the advantage. Maybe its too advanced for me as a beginner now its just I am curious over the usage and applications with a simple hello world like example explaining what this library will accomplish. I asked it previously at https://www.reddit.com/r/programming/comments/4hti33/dconf_2016_is_streaming_right_now/d2satic/ but still I don't understand the exact applications of the same.


I'd say it's one of those things where if you are asking about 
it, you probably don't need it. I don't think there is such a 
thing as "hello world"[1] because memory allocation is an 
advanced topic. Maybe a better question is what you plan to do 
with D, because in my opinion, most users don't need to worry 
about it.


[1] There might be "hello world" for usage, but not for 
motivation.


Re: Does anyone know of an sdl-mode for Emacs?

2017-01-05 Thread Atila Neves via Digitalmars-d-learn

On Wednesday, 4 January 2017 at 18:50:21 UTC, Russel Winder wrote:
On Wed, 2017-01-04 at 17:24 +, Atila Neves via 
Digitalmars-d-learn wrote:
It's getting tedious editing dub.sdl files with no editor 
support. If nobody's written one, I will.




Emacs has an sdlang-mode. It's on MELPA so installable via 
packages.


Huh. I guess I search for sdl-mode when I didn't find it. Thanks!

Atila


Re: Stack Space & Ackermann

2017-01-05 Thread Era Scarecrow via Digitalmars-d-learn

On Thursday, 5 January 2017 at 07:30:02 UTC, H. S. Teoh wrote:
Nonetheless, even if you optimize said code paths, you still 
won't be able to get any sane results for m>4 or anything 
beyond the first few values for m=4. The Ackermann function is 
*supposed* to be computationally intractible -- that's what it 
was designed for. :-P


 Yeah I know. The function as written is as it was shown on the 
video and explained, and is badly formed. Memoize did give me 
real quick results up to 4,1; But it's obvious getting anything 
better is impossible as things stand.


 Still it did bring up how to handle needing larger stack spaces, 
which I've wondered about with wanting to make large structures 
on the stack so I wouldn't have to rely on actually allocating 
anything and not having to clean it up afterwards. Simpler, 
cleaner & faster memory management in my mind.