Is there an alternative of `go get`

2020-08-07 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi everyone, `go get` in Golang world has a simple way to fetch and install binary ``` $ go get github/foo/bar.git $ export PATH=$PATH:$(go env GOPATH)/bin $ bar --help ``` This saves a lot of time and setup. Is that an alternative when using dub? Thanks a lot.

Re: Which Docker to use?

2018-10-19 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 23:15:53 UTC, Jon Degenhardt wrote: I need to use docker to build static linked Linux executables. My reason is specific, may be different than the OP's. I'm using Travis-CI to build executables. Travis-CI uses Ubuntu 14.04, but static linking fails on 14.04.

Which Docker to use?

2018-10-16 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I need to build some static binaries with LDC. I also need to execute builds on both platform 32-bit and 64-bit. From Docker Hub there are two image groups: * language/ldc (last update 5 months ago) * dlang2/ldc-ubuntu (updated recently) Which one do you suggest? Thanks a lot.

Dlang on OpenWrt

2018-08-02 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, can I build my program on OpenWrt? I haven't found any resources on internet maybe I'm missing something. Thanks a lot.

Is there a way to anonymously execute some sh script contents?

2018-08-01 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I have some big shell script that may require user input. Using `pipeProcess` doesn't work as `pipe` doesn't allow user to provide custom input (FIXME). I am creating some temporary files, put the script contents to that file and then invoke [code] spawnProcess([/path/to/shell,

Re: Why does not UFCS work for method defined inside unittest block?

2018-08-01 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 31 July 2018 at 08:42:28 UTC, Simen Kjærås wrote: From https://dlang.org/spec/function.html#pseudo-member: "A free function can be called with a syntax that looks as if the function were a member function of its first parameter type." [...] Thanks a lot Simen :)

Re: Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Ky-Anh Huynh via Digitalmars-d-learn
dmd version that I'm using: $ dmd --version DMD64 D Compiler v2.081.1-dirty Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright

Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Can I define a new quick function to use inside a unittest block? I have the following code: [code] auto foo(string[] sta) { return sta; } auto bar(string[] sta) { return sta; } auto h(string[] sta) { return sta.foo.bar; } unittest { import std.format; auto f = (string[] sta)

Re: Is it possible to have reproducible-builds?

2017-10-25 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Thursday, 26 October 2017 at 04:34:36 UTC, Ky-Anh Huynh wrote: Hi, I'd like to distribute binaries (compiled from Dlang sources) to my servers and users. This really helps end users because they don't need to rebuild things with custom dmd/dub setup. However, distributing things require

Is it possible to have reproducible-builds?

2017-10-25 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I'd like to distribute binaries (compiled from Dlang sources) to my servers and users. This really helps end users because they don't need to rebuild things with custom dmd/dub setup. However, distributing things require them to `trust` me, and this is another thing I want to avoid. Is

Re: Writing some built-in functions for Bash, possible?

2017-10-21 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 08:15:53 UTC, evilrat wrote: [...] This isn't the actual code but should give you a hint, the rest is up to you. Woh Thanks a ton. I can have some working code after a few hours :D

Re: Writing some built-in functions for Bash, possible?

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 03:48:01 UTC, Ky-Anh Huynh wrote: Some examples in C are in [2]. My experience: Dlang has `pipe` support however the syntax is not as clean as Bash :) Most of the times I see short (<1k loc) Bash scripts are easy to maintain than Ruby (and now D things)

Writing some built-in functions for Bash, possible?

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I'm using Bash heavily in my systems. Things become slow and slow when I have tons of scripts :) And sometimes it's not easy to manipulate data. You may have heard of recutils [1] which has a C extension to be loaded by Bash. Is it possible to write similar things in D, for Bash? I am

Re: How to modify process environment variables

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 08:42:09 UTC, Rene Zwanenburg wrote: On Tuesday, 17 October 2017 at 05:57:50 UTC, Ky-Anh Huynh wrote: On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote: you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there.

Re: How to modify process environment variables

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 11:49:32 UTC, Jacob Carlborg wrote: On 2017-10-17 06:51, Ky-Anh Huynh wrote: Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new

Re: How to modify process environment variables

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote: you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has

How to modify process environment variables

2017-10-16 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive:

How to embed static strings to a D program?

2017-10-15 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hello, I want to use some static contents in my program, e.g, a CSS file, a long listing. To help deployment process I'd like to have them embedded in the final binary file. Is there any convenient way to support this? Maybe I need a tool/library to load file contents and generate D-code at

Re: Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 10:05:34 UTC, Nicholas Wilson wrote: I'd just use dirEntries with SpanMode.shallow in combination with filter either in a loop or a recursive function like below. void foo(string path = "path") { foreach(e;

Re: What does ! mean?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote: See also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.html Thanks a lot. I will keep reading :)

What does ! mean?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I am from Ruby world where I can have `!` (or `?`) in method names: `!` indicates that a method would modify its object (`foo.upcase!` means `foo = foo.upcase`). ( I don't know if there is any official Ruby documentation on this convention though. ) In D I see `!` quite a lot. I have

Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Can I have a `break` option when using `dirEntries()` (similar to `break` in a loop)? I want to study sub-directories but if any sub-directory matches my criteria I don't to look further into their subdirectories ``` A/ -> matches criteria, stop here, go to next directory (B)

Re: How to list all process directories under /proc/

2017-09-19 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 18:32:06 UTC, Matt Jones wrote: On Tuesday, 19 September 2017 at 13:32:29 UTC, Ky-Anh Huynh wrote: Btw, is that a bit weird that range is not supported in glob pattern :) Is there a design reason for this? That is strange. But then again, every glob

Re: formattedRead can't work with tab delimiter input

2017-09-19 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 20:04:36 UTC, kdevel wrote: On Tuesday, 19 September 2017 at 13:28:22 UTC, Ky-Anh Huynh wrote: Hi, I want to read two fields from STDIN string key; double value; line_st.formattedRead!"%s %f"(key, value); Well it's so different from C. I would

Re: How to list all process directories under /proc/

2017-09-19 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 06:35:18 UTC, Matt Jones wrote: On Sunday, 17 September 2017 at 08:37:33 UTC, Ky-Anh Huynh wrote: [...] The problem with matching "[0123456789]*" is that it will match files like "1blah" and "8stuff". It looks like glob patterns are not robust enough to

formattedRead can't work with tab delimiter input

2017-09-19 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I want to read two fields from STDIN string key; double value; line_st.formattedRead!"%s %f"(key, value); However, if the input line contains \t and it doesn't contain any space, the code doesn't work as expected. If there is a space, it works well a[space]1 #

How to Skip some field/word in formattRead?

2017-09-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Is it possible to read just the second word from an input string and skip all others? "one two three".formattedRead!("%s %s", _, saveme) The point is I want to skip the first/third word (`one`, `third`) and read the second word (`two`) into the variable `saveme`. For now I have to

Re: How to list all process directories under /proc/

2017-09-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Sunday, 17 September 2017 at 08:32:24 UTC, Ky-Anh Huynh wrote: My bad. Range doesn't support. The correct pattern is [code] foreach (string fstatm; dirEntries("/proc/", "[0123456789]*", SpanMode.shallow)) { writefln("pid %s", fstatm); } [/code] Is there a way to make this

Re: How to list all process directories under /proc/

2017-09-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Sunday, 17 September 2017 at 08:15:58 UTC, Ky-Anh Huynh wrote: Hi, I want to list all processes by scanning /proc/. The following code doesn't work [code] foreach (string fstatm; dirEntries("/proc/", "[0-9]*", SpanMode.shallow)) { writefln("pid %s", fstatm); } [/code] as it

How to list all process directories under /proc/

2017-09-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I want to list all processes by scanning /proc/. The following code doesn't work [code] foreach (string fstatm; dirEntries("/proc/", "[0-9]*", SpanMode.shallow)) { writefln("pid %s", fstatm); } [/code] as it only list a few entries before exiting [code] pid /proc/9 pid

Re: Convert user input string to Regex

2017-09-16 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Saturday, 16 September 2017 at 03:23:14 UTC, Adam D. Ruppe wrote: On Saturday, 16 September 2017 at 03:18:31 UTC, Ky-Anh Huynh wrote: Is there a way to transform user input string to a regular expression? For example, I want to write a `grep`-like program import std.regex; auto re =

Convert user input string to Regex

2017-09-15 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Is there a way to transform user input string to a regular expression? For example, I want to write a `grep`-like program ``` mygrep -E '/pattern/i' file.txt ``` and here the user's parameter `/pattern/i` would be converted to a Regex object. Fyi, in Ruby, `to_regexp` is a useful gem:

Re: Unit-tests with stderr / stdout

2017-09-09 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Saturday, 9 September 2017 at 03:37:58 UTC, Ky-Anh Huynh wrote: Hi, As a system administrator I often have some small scripts/ programs that consume input and produce output for other system utilities. Something like `my_foo_program | awk ... | other_program`. As the tools write to

Re: Should `dub run` prints its output to STDERR?

2017-09-09 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Saturday, 9 September 2017 at 05:58:59 UTC, Ali Çehreli wrote: On 09/08/2017 09:51 PM, Ky-Anh Huynh wrote: > When I execute a program thanks to dub, `dub` also prints its > information to STDOUT: Try dub's --quiet command line switch. Ali That's perfect. Thanks a lot.

Should `dub run` prints its output to STDERR?

2017-09-08 Thread Ky-Anh Huynh via Digitalmars-d-learn
When I execute a program thanks to dub, `dub` also prints its information to STDOUT: [code] $ dub run dusybox:jq -- .status " 1" < /home/pi/df/acces.log |head -10 Building package dusybox:jq in /home/pi/projects/icy/dusybox/ Performing "debug" build using dmd for x86_64. dusybox:jq

Unit-tests with stderr / stdout

2017-09-08 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, As a system administrator I often have some small scripts/ programs that consume input and produce output for other system utilities. Something like `my_foo_program | awk ... | other_program`. As the tools write to STDOUT/STDERR, I haven't found a way to write unit tests for them. Should

Re: Problem with std.string.strip(): Can't use result in format routine

2017-09-05 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 13:56:20 UTC, Andrea Fontana wrote: I used `lines(stdin)` as in https://dlang.org/phobos/std_stdio.html#.lines . My source code is here https://github.com/icy/dusybox/blob/master/src/plotbar/main.d#L47 . Thanks for your support. I think formattedRead is

Re: Problem with std.string.strip(): Can't use result in format routine

2017-09-05 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 13:17:34 UTC, Azi Hassan wrote: Maybe it has something to do with how you read from STDIN. Can you show that part of the code to see if I can reproduce the issue ? I used `lines(stdin)` as in https://dlang.org/phobos/std_stdio.html#.lines . My source code

Problem with std.string.strip(): Can't use result in format routine

2017-09-05 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I read line from STDIN , and strip them [code] auto line_st = line.strip(); [/code] However, I can't use result in another format routine. Assume my input line is "foobar": [code] writeln("Stripped line is %s", line_st); [/code] This code only prints "Stripped line is ". If I use