Re: how to install the new dmd on Mac M1?

2022-08-25 Thread MichaelBi via Digitalmars-d-learn

On Friday, 26 August 2022 at 00:55:05 UTC, Nicholas Wilson wrote:

On Friday, 26 August 2022 at 00:34:30 UTC, MichaelBi wrote:
when using ldc2, has this error "ld: library not found for 
-lssl" after dub build --compiler=ldc2


So where is your ssl library located and how (if at all) are 
you telling the compiler/linker where to find it?


I installed openssl and also export the path of lib, but still 
got that errors...


Re: how to install the new dmd on Mac M1?

2022-08-25 Thread MichaelBi via Digitalmars-d-learn
On Thursday, 25 August 2022 at 15:19:56 UTC, Steven Schveighoffer 
wrote:

On 8/25/22 10:44 AM, MichaelBi wrote:
On Thursday, 25 August 2022 at 14:37:01 UTC, Steven 
Schveighoffer wrote:

[...]


it's simple as following:

-iMac ~ % curl -fsS https://dlang.org/install.sh | bash -s dmd
Unsupported Arch arm64


So install.sh is checking the architecture, and failing because 
the OS reports it as arm64.


```sh
case $(uname -m) in
x86_64|amd64) ARCH=x86_64; MODEL=64;;
aarch64) ARCH=aarch64; MODEL=64;;
i*86) ARCH=x86; MODEL=32;;
*)
fatal "Unsupported Arch $(uname -m)"
;;
```

You could change the line that starts with `aarch64` to 
`aarch64|arm64`


That might work. I'm not sure, because really you want x86_64 
for dmd (there is no aarch64 or arm64 build of dmd).


Have you tried using the dmg package?

-Steve


you are right, the package install is OK. but after running dub 
build --compiler=dmd, the error of "ld: library not found for - 
lssl" is still there...


Re: how to install the new dmd on Mac M1?

2022-08-25 Thread MichaelBi via Digitalmars-d-learn

On Thursday, 25 August 2022 at 16:06:49 UTC, Ben Jones wrote:
On Thursday, 25 August 2022 at 15:19:56 UTC, Steven 
Schveighoffer wrote:

On 8/25/22 10:44 AM, MichaelBi wrote:
On Thursday, 25 August 2022 at 14:37:01 UTC, Steven 
Schveighoffer wrote:

On 8/25/22 10:19 AM, MichaelBi wrote:



Is there a reason you want to use DMD specifically?  If you use 
homebrew then `brew install ldc dub` will just works for dub 
projects, and to explicitly run the compiler just use `ldc2` 
instead of `dmd`.  LDC is actually an ARM executable and 
outputs ARM executables.  I assume it's easy to install ldc 
without homebrew, but I haven' tried.


when using ldc2, has this error "ld: library not found for -lssl" 
after dub build --compiler=ldc2


Re: how to install the new dmd on Mac M1?

2022-08-25 Thread MichaelBi via Digitalmars-d-learn
On Thursday, 25 August 2022 at 14:37:01 UTC, Steven Schveighoffer 
wrote:

On 8/25/22 10:19 AM, MichaelBi wrote:
I downloaded the new dmd 2.1 on Mac, but with fail message of 
"unsupported Arch arm64". how can I do? thanks.


DMD is x86 only. M1 macs can run x86 via rosetta.

I haven't had this specific problem. Can you list the actual 
commands you are running, and the output from the system?


-Steve


it's simple as following:

-iMac ~ % curl -fsS https://dlang.org/install.sh | bash -s dmd
Unsupported Arch arm64


how to install the new dmd on Mac M1?

2022-08-25 Thread MichaelBi via Digitalmars-d-learn
I downloaded the new dmd 2.1 on Mac, but with fail message of 
"unsupported Arch arm64". how can I do? thanks.


how to set REST path for gcloud api in vibe.d?

2022-06-14 Thread MichaelBi via Digitalmars-d-learn
I need to use gcloud NLP api which has the url and endpoint like 
this 
"https://language.googleapis.com/v1beta2/documents:analyzeSentiment;. The ":" between documents and analyzeSentiment make a lot trouble for me. Just don't know how to setup the @path in RestInterface for such endpoint. I tried many, including `/documents:analyzeSentiment` but all failed, cannot go to the right path...


any idea? thank in advance.


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread MichaelBi via Digitalmars-d-learn

On Friday, 13 May 2022 at 06:43:30 UTC, rikki cattermole wrote:


On 13/05/2022 6:23 PM, MichaelBi wrote:

     render!("index.dt", showData());


There ya go, template arguments are run at compile time.


Unh, then how to dynamically generate pages by using vibe.d


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread MichaelBi via Digitalmars-d-learn

On Friday, 13 May 2022 at 06:12:01 UTC, rikki cattermole wrote:


Okay that is fine, now we need to see where showData is being 
called.


thanks, here's the code:

import vibe.vibe;
import std.process;
import std.conv : to;

void main()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["0.0.0.0"];
readOption("port|p", , "Sets the port used 
for serving HTTP.");
readOption("bind-address|bind", 
[0], "Sets the address used for serving 
HTTP.");

auto router = new URLRouter;
router.get("*", serveStaticFiles("public/"));
router.registerWebInterface(new ContentController);
auto listener = listenHTTP(settings, router);

scope (exit)
{
listener.stopListening();
}

runApplication();
}

class ContentController
{
void index()
{
render!("index.dt", showData());
}
}

struct Camera{
	@name("_id") BsonObjectID id; // represented as "_id" in the 
database

string brand;
string model;
}

Camera[] showData(){
auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");
MongoCollection cameras = eqpdb["cameras"];
Camera[] cs;
auto results = cameras.find();
foreach(rec;results) cs ~= deserializeBson!Camera(rec);
return cs;
}


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread MichaelBi via Digitalmars-d-learn

On Friday, 13 May 2022 at 06:01:29 UTC, rikki cattermole wrote:


On 13/05/2022 5:52 PM, MichaelBi wrote:

struct Camera{
 @name("_id") BsonObjectID id; // represented as "_id" in 
the database

 string brand;
 string model;
}

the structure is mapping of database field structure. how to 
resolve?


That code isn't the cause of your issue (its fine, no CTFE 
needed).


We would need see more of your code surrounding:

auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");


here is the code:

Camera[] showData(){
auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");
MongoCollection cameras = eqpdb["cameras"];
Camera[] cs;
auto results = cameras.find();
foreach(rec;results) cs ~= deserializeBson!Camera(rec);
return cs;
}




Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-12 Thread MichaelBi via Digitalmars-d-learn

On Friday, 13 May 2022 at 05:41:33 UTC, rikki cattermole wrote:

On 13/05/2022 5:18 PM, MichaelBi wrote:

     i have code here:
     auto uri = environment.get("MONGODB_URI");
     MongoClient conn = connectMongoDB(uri);
     MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");

the "MONGODB_URI" showed above already put into heroku's app 
config as the 'key' and there is a paired 'value'. so the uri 
is to extract the value which is to use for app to establish 
mongodb connection.


and above code with error msg here: Error: `getenv` cannot be 
interpreted at compile time, because it has no available 
source code


That part of the code is probably fine.

Basically you have to be careful that:

auto uri = environment.get("MONGODB_URI");

Isn't being executed during compilation.

Stuff that typically cause this is anything that initializes a 
variable.


Globals:

shared Foo foo = Foo(...);

Class fields:

class Foo {
Bar bar = Bar(...);
}


yes, then should be this?

struct Camera{
	@name("_id") BsonObjectID id; // represented as "_id" in the 
database

string brand;
string model;
}

the structure is mapping of database field structure. how to 
resolve?


Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-12 Thread MichaelBi via Digitalmars-d-learn
there are online documents of heroku on how to access config var 
value from code, and several code samples without D. link here: 
https://devcenter.heroku.com/articles/config-vars#accessing-config-var-values-from-code.


i have code here:
auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");

the "MONGODB_URI" showed above already put into heroku's app 
config as the 'key' and there is a paired 'value'. so the uri is 
to extract the value which is to use for app to establish  
mongodb connection.


and above code with error msg here: Error: `getenv` cannot be 
interpreted at compile time, because it has no available source 
code


so don't know how to make change. thanks in advance!


Re: range result in Tuple! and how to convert into assocArray by sort?

2022-05-09 Thread MichaelBi via Digitalmars-d-learn

On Tuesday, 10 May 2022 at 04:21:04 UTC, Ali Çehreli wrote:

On 5/9/22 20:38, rikki cattermole wrote:

> [...]

Yes! :)

Assuming the data is indeed validated in some way, the 
following should be even faster. It validates the data after 
the fact:


[...]


this is cool! thanks for your time and i really like your book 
Programming in D :)


Re: range result in Tuple! and how to convert into assocArray by sort?

2022-05-09 Thread MichaelBi via Digitalmars-d-learn

On Tuesday, 10 May 2022 at 03:38:08 UTC, rikki cattermole wrote:
If I am understanding the problem correctly, this is a super 
expensive method for doing something pretty simple. Even if it 
is a bit more code, this won't require memory allocation which 
in this case wouldn't be cheap (given how big DNA tends to be).


string s = "ACGTACGT";

uint[4] counts;

foreach(char c; s) {
switch(c) {
case 'A':
case 'a':
counts[0]++;
break;
case 'C':
case 'c':
counts[1]++;
break;
case 'G':
case 'g':
counts[2]++;
break;
case 'T':
case 't':
counts[3]++;
break;
default:
assert(0, "Unknown compound");
}
}

writeln(counts);


yes, thanks. understood this. the problem for me now is after 
learning D, always thinking about using range and function 
composition...and forgot the basic algorithm :)


range result in Tuple! and how to convert into assocArray by sort?

2022-05-09 Thread MichaelBi via Digitalmars-d-learn

s is the string, and print result as following:

s.array.sort!("athen how to transfer into 
[['A',231],['C',247],['G',240],['T',209]]? tried map!, but can 
only sortout key or value... tried array(), but result is not 
sorted then...thanks in advance.


Re: Deploy vibe.d application on Heroku : App not compatible with buildpack

2022-05-09 Thread MichaelBi via Digitalmars-d-learn

On Monday, 28 June 2021 at 16:25:20 UTC, vnr wrote:

On Monday, 28 June 2021 at 16:14:07 UTC, Andre Pany wrote:

On Monday, 28 June 2021 at 13:53:05 UTC, vnr wrote:

[...]


Hi,

Heroku is Cloud Foundry? If yes, you can make use of the 
binary buildpack or deploying your app as container too.


Kind regards
Andre


Thank you :) Via your explanation and some further research on 
my part, I was able to solve the problem!


Hi, i am also using heroku and encounting same problem, could you 
kindly share the details of how you solve this? thanks!


curl error msg

2022-02-19 Thread MichaelBi via Digitalmars-d-learn
when running the example in the std.net.curl on my windows, got 
following msg:


std.net.curl.CurlException@std\net\curl.d(4239): Failed to load 
curl, tried "libcurl.dll", "curl.dll"


does it mean i don't have those dll files? thx.


Re: how to handle very large array?

2022-02-14 Thread MichaelBi via Digitalmars-d-learn

On Saturday, 12 February 2022 at 20:31:29 UTC, H. S. Teoh wrote:
On Sat, Feb 12, 2022 at 06:41:14PM +, Era Scarecrow via 
Digitalmars-d-learn wrote:

[...]

[...]

That was not my point. My point was to question whether the OP 
has discovered the insight that would allow him to accomplish 
his task with a LOT less space than the naïve approach of 
storing everything in a gigantic array.  Substituting an AA for 
a gigantic array matters little as long as the basic approach 
remains the same -- you have only modified the implementation 
details but the algorithm is still a (highly) suboptimal one.



--T


thanks, you are all correct. i just change the algorithm and use 
the AA, previously using the naïve method...:), now solved 
perfectly. thanks again.


Re: how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn

On Wednesday, 9 February 2022 at 19:48:49 UTC, H. S. Teoh wrote:

[...]


thanks, very helpful! i am using a assocArray now...


Re: how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn

On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote:
day6 of the advent of code 2021 needs to handle an array of 
10^12 length, or even bigger... plus change elements and append 
elements. normal implementation such as length, appender and 
ref element etc, seems cannot handle that big array? is there 
any alternative data structure or algorithm can handle such 
large array properly? thanks.


got outofmemory error:
core.exception.OutOfMemoryError@src\core\lifetime.d(126): Memory 
allocation failed


Re: how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn

On Wednesday, 9 February 2022 at 10:05:23 UTC, MichaelBi wrote:

On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote:
day6 of the advent of code 2021 needs to handle an array of 
10^12 length, or even bigger... plus change elements and 
append elements. normal implementation such as length, 
appender and ref element etc, seems cannot handle that big 
array? is there any alternative data structure or algorithm 
can handle such large array properly? thanks.


got outofmemory error:
core.exception.OutOfMemoryError@src\core\lifetime.d(126): 
Memory allocation failed


https://adventofcode.com/2021/day/6#part2

"Suppose the lanternfish live forever and have unlimited food and 
space. Would they take over the entire ocean?


After 256 days in the example above, there would be a total of 
26984457539 lanternfish!


How many lanternfish would there be after 256 days"

26984457539 in above is the array length.


how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn
day6 of the advent of code 2021 needs to handle an array of 10^12 
length, or even bigger... plus change elements and append 
elements. normal implementation such as length, appender and ref 
element etc, seems cannot handle that big array? is there any 
alternative data structure or algorithm can handle such large 
array properly? thanks.


Re: why there is a [] at the end of assocArray

2022-01-19 Thread MichaelBi via Digitalmars-d-learn

On Wednesday, 19 January 2022 at 16:36:36 UTC, Ali Çehreli wrote:

On 1/19/22 06:06, michaelbi wrote:
On Wednesday, 19 January 2022 at 13:21:32 UTC, Stanislav 
Blinov wrote:
On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi 
wrote:



[...]



[...]


...because there's an empty line at the end of input.txt?


i got it, though i still don't know where the [] come from. i 
just add strip here: a=>a.idup.strip


Works for me on Linux. Perhaps there is an issue with Windows 
line endings?


In any case, the .strip above would not be eliminating empty 
lines; you need to filter them out e.g. with


  byLine.filter!(line => !line.empty)

Aside: Instead of copying the lines with .idup explicitly, 
there is .byLineCopy that already does that.


Ali


I am using windows.
Thanks a lot for introducing those funcs. Now I am feeling the 
D’s quite interesting and powerful :)


Re: how to print "111000" out into 0b111000

2022-01-19 Thread MichaelBi via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 15:41:31 UTC, Brian Callahan 
wrote:

On Wednesday, 19 January 2022 at 15:01:29 UTC, michaelbi wrote:

as captioned... thx.


```d
import std.stdio;
import std.conv;

void main()
{
writefln("0b%b", to!int("111000", 2));
}
```


Got it, thanks


how to print "111000" out into 0b111000

2022-01-19 Thread michaelbi via Digitalmars-d-learn

as captioned... thx.


Re: why there is a [] at the end of assocArray

2022-01-19 Thread michaelbi via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 13:21:32 UTC, Stanislav Blinov 
wrote:

On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi wrote:

	foreach(line; > 
File("input.txt").byLine.map!(a=>a.idup).array.transposed)



so why there is a [] at the end of assocArray printed? thanks.


...because there's an empty line at the end of input.txt?


i got it, though i still don't know where the [] come from. i 
just add strip here: a=>a.idup.strip


why there is a [] at the end of assocArray

2022-01-19 Thread michaelbi via Digitalmars-d-learn

input:
00100
0
10110
10111
10101
0
00111
11100
1
11001
00010
01010

code:
void main()
{
	foreach(line; 
File("input.txt").byLine.map!(a=>a.idup).array.transposed){

auto sortgroup = line.array.strip.sort.group.assocArray;
writeln(sortgroup);
}
}

output:
['1':7, '0':5]
['1':5, '0':7]
['1':8, '0':4]
['1':7, '0':5]
['1':5, '0':7]
[]

so why there is a [] at the end of assocArray printed? thanks.