Re: DDoc generation

2020-09-21 Thread aberba via Digitalmars-d-learn
On Saturday, 19 September 2020 at 11:39:45 UTC, Jacob Carlborg 
wrote:
On Saturday, 19 September 2020 at 07:43:24 UTC, Russel Winder 
wrote:


Doesn't that then make the whole DDoc system fairly useless, 
despite it's use in Phobos?


Yes.  The problem is that most things in D are compared with C 
or C++. People are praising that the built-in support for unit 
tests and Ddoc are the best things that have happened since 
sliced bread. But if you compare with C or C++ the bar isn't 
very high.


--
/Jacob Carlborg


+1.

Couldn't agree more.


Re: Building LDC runtime for a microcontroller

2020-09-19 Thread aberba via Digitalmars-d-learn

On Friday, 18 September 2020 at 07:44:50 UTC, Dylan Graham wrote:

On Monday, 7 September 2020 at 19:12:59 UTC, aberba wrote:

[...]


I use D in an automotive environment (it controls parts of the 
powertrain, so yeah there are cars running around on D) on 
various types of ARM Cortex M CPUs, I think this will be the 
best way to extend D to those platforms.


Wow. Happy to hear this.

Do you attend our monthly D online meetups?



The existing runtime is PC-oriented. Embedded stuff doesn't 
need a GC or some of the more advanced features, but having 
things like classes, interfaces, dynamic arrays would make the 
development workload a lot easier.

+1




A lot of embedded stuff is done with RTOSs now that provide 
memory management and threading support, so having a flexible 
lightweight runtime with a generic backend (mem allocation, 
threads) that I can hook to the RTOS' libraries would be great.


I think Ali was also working on or at least talked about that OS 
(if I remember correctly) at Dconf, right?


Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread aberba via Digitalmars-d-learn

On Saturday, 19 September 2020 at 20:17:06 UTC, aberba wrote:

On Friday, 18 September 2020 at 22:31:09 UTC, mw wrote:

On Friday, 18 September 2020 at 00:07:12 UTC, wjoe wrote:

Are there other frameworks besides vibe that can do what I 
want?


Personally I use vibe.d for basic side projects. Looking to use 
it more going forward. But that's how I see it.


This is my personal collection of D web development packages. Let 
me know if I'm missing something.


https://gist.github.com/aberba/dcaf9102b35205080ad99a2af2c21142



Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread aberba via Digitalmars-d-learn

On Friday, 18 September 2020 at 22:31:09 UTC, mw wrote:

On Friday, 18 September 2020 at 00:07:12 UTC, wjoe wrote:

Are there other frameworks besides vibe that can do what I 
want?


Just FYI, there is also:

https://code.dlang.org/packages/hunt-framework


I never used myself, you need to investigate.


Yeah, I'm aware of hunt too. Its like laravel in php whilst 
vibe.d feels more like express in nodejs. Infact I believe Sonke 
wrote vibe.d after using express or similar framework by design.



And yes, almost all frameworks work in a certain way. Arsd cgi.d 
might be what you want if you want to it your way as its more 
low-level interface-wise.


I personally (and many others in the industry... judging by 
popularity of express (node.js) and the plentiful third-party 
libraries,..do prefer the router.get() design. Also having 
everything abstracted in a convenient and consistent way...is 
very desirable. vibe.d's web interface API is something I've 
always praised and thanks to how powerful D is compare to say 
JavaScript. Diet templates is also an example.


However that power is not tapped in enough (yet) to favour using 
D conveniently over node (js). And web developers are interested 
in getting things done (at least my kind of web devs) rather than 
getting it our way...or squeezing every bit of efficiency out of 
it. Part of why v8 is fast by default (for us).


Unike express (which is a thing layer with interface for 
third-parties to hook in and extend with libs), vibe.d became a 
monolith with everything included... making it harder to maintain 
and extend in other ways. Plus too much hard-coding by default 
currently. Unfortunately Sonke doesn't work on it like he used 
to...and its quite an huge accomplishment...the work he's done 
for D.



I wish vibe.d could be positioned and sponsored officially or by 
community cus its the killer app.


Staying lean and being extensible will open up for more 
innovation around it. Eg. a form handler for files library that 
works like how Ikod suggested...a customizable stream.



Unless you're doing usual routing and database things, using 
vibe.d for a full stack projects can lead to a dead end unless 
you're positioned to write your own stuff to supplement. Of 
course its only a matter of time before this change for the good.


Personally I use vibe.d for basic side projects. Looking to use 
it more going forward. But that's how I see it.


Re: vibe.d: How to get the conent of a file upload ?

2020-09-18 Thread aberba via Digitalmars-d-learn

On Friday, 18 September 2020 at 00:07:12 UTC, wjoe wrote:
On Thursday, 17 September 2020 at 22:33:46 UTC, Steven 
Schveighoffer wrote:

On 9/17/20 6:13 PM, aberba wrote:
On Thursday, 17 September 2020 at 21:57:37 UTC, Steven 
Schveighoffer wrote:

On 9/17/20 1:08 PM, wjoe wrote:

[...]


the `files` property actually does the processing only when 
you call it.


If you access the `bodyReader` property directly, you can 
process that data yourself. You can even register a web 
interface function with an `InputStream` parameter type, and 
it will be bound to the body data.


I'm not sure I understand how to do this and parser the files 
in memory.


So an HTTP request with form data will come in with the 
headers parsed, but the data is still on the network stream.


The first time you access `files`, it processes the stream 
data, and splits it into form data and file data, saves the 
files, and then gives you back the file dictionary so you can 
use them.


If instead, you access `bodyReader`, YOU get to process the 
form data and file data.




I've done this with my REST interface, though that's not 
form data.


That's not a great API, though. I would love to see vibe.d 
allow a direct call to vibe.inet.webform.parseFormData with 
a specific handler for files and form data.
Can we file an issue for this? Because I'm very interested in 
having this resolved


You can always file an issue! 
https://github.com/vibe-d/vibe.d/issues


There may already be one in there.

There's potential to results in out of memory condition. Its 
a know issues. A complete parser (like multer in nodejs) 
allowance you to limit file size as well for error handling.


Meh, this is D :) we should be able to just process the data 
and do whatever we want with it. What I would like to see is 
vibe provide the parsing of form data, and just give me the 
data as it comes (kind of like a SAX parser). Maybe just a 
property in the HTTPServerRequest that I can set that says 
"use this callback when you get Form File data".


I've done this with my REST interface, though that's not 
form data.


Can you share your code for this?


Heh, this is not form data, it's just file data, raw on the 
stream. So I have a function like:


```
class FileRestImpl
{
@path(":cat/:id/:uuid/upload")
@getAuth
void postUpload(HTTPServerResponse res, string _cat, int 
_id, string _uuid, InputStream stream, Nullable!string md5sum, 
NRMAuthInfo _authInfo)

{
...
}
}
```

You can see, I take an InputStream as a parameter -- the data 
comes in there. I just read it and save it to a file (in the 
correct location) anyway, verifying the md5sum is valid.


-Steve


Not a reply to this post in particular but to all the ones I've 
read so far.


If I understand correctly. Vibe parses the form data and writes 
all files to disk. Where to ?
Can I configure it ? I don't want libraries to just write data 
to my file systems without me setting this up. Nowhere did I 
find this behavior described in the docs.
And if not, how is data processed with a 10mb file upload 
followed by a few number fields ?
It needs to read all of the file data to get to the other data 
fields, doesn't it ?


I'm sorry this is completely counter intuitive. I can 
understand the memory/security risks and all but I have no 
intention to hack, DOS or however else disrupt my private 
server in my private network with garbage data. I just want to 
get the data in a byte[].


That's what I was trying to answer. When Steve said meh, he 
probably didn't get what I said. Probably its because of my typos.


This sort of convenience and productivity benefit is part of why 
I use Node.Js in the job when I need to get things doneand 
not D yet. There are several pieces and bits you can't write 
yourself when working on projects.


In this case you want to get the file(s) in memory...in the form 
of bytes (or buffer) and probably set a file size limit. Its all 
doable through a library but such a library doesn't exist in D 
yet. At least not that I know of.


Its why I mentioned that multer[1] in Node.Js able to do 
that...hence the advantage. Its built for the express 
framework...meaning such library can be built to work with 
vibe.d. Not everything can be built into vibe.d..and I think 
that'll even make it bloated for other uses case. Its need an 
ecosystem of third-party libraries.


In the case of the vibe.d form, data and files are handled using 
this implementation[2] so its a reference to such a form parser 
implementation...with support for a storage parameter for either 
a MemoryStore or SessionStore. Multer does it pretty cleanly.


1. Multer: https://www.npmjs.com/package/multer
2. 
https://github.com/vibe-d/vibe.d/blob/ebebfa827f568cc9bced4bec2b66edc043a8adf7/inet/vibe/inet/webform.d





Why does the lib not simply reject files that are unreasonably 
(configurable) big ?
Writing files to disk in order to then needing to copy them 
somewhere else or to read 

Re: vibe.d: How to get the conent of a file upload ?

2020-09-17 Thread aberba via Digitalmars-d-learn
On Thursday, 17 September 2020 at 21:57:37 UTC, Steven 
Schveighoffer wrote:

On 9/17/20 1:08 PM, wjoe wrote:

[...]


the `files` property actually does the processing only when you 
call it.


If you access the `bodyReader` property directly, you can 
process that data yourself. You can even register a web 
interface function with an `InputStream` parameter type, and it 
will be bound to the body data.


I'm not sure I understand how to do this and parser the files in 
memory.




I've done this with my REST interface, though that's not form 
data.


That's not a great API, though. I would love to see vibe.d 
allow a direct call to vibe.inet.webform.parseFormData with a 
specific handler for files and form data.
Can we file an issue for this? Because I'm very interested in 
having this resolved




I think you can agree that it's not feasible to store arbitrary 
sized file contents in memory. But it certainly can provide a 
mechanism to handle it as it's read.


-Steve


There's potential to results in out of memory condition. Its a 
know issues. A complete parser (like multer in nodejs) allowance 
you to limit file size as well for error handling.


I've done this with my REST interface, though that's not form 
data.


Can you share your code for this?


Re: vibe.d: How to get the conent of a file upload ?

2020-09-17 Thread aberba via Digitalmars-d-learn

On Thursday, 17 September 2020 at 16:32:55 UTC, WebFreak001 wrote:

On Thursday, 17 September 2020 at 16:00:33 UTC, wjoe wrote:
I found this [1] but unfortunately the post this refers to is 
a dead link and the content, unfortunately, didn't tell me 
anything that I didn't already find in the docs.


What I can get from the form is the form fields with content, 
the field name for the file upload and the file name. But the 
file name is useless to me because I need the file content.


Where is it stored ?

[1] https://aberba.com/2017/multiple-file-upload-in-vibe-d/


hi, you can access HTTPServerRequest.files which contains the 
uploaded file.


Example in real code: 
https://github.com/WebFreak001/ImageUploader/blob/master/source/app.d#L141-L159


Documentation: https://vibed.org/api/vibe.inet.webform/FilePart

Note: the file is only downloaded from the client / stored on 
disk once you access the files or the form property, though 
this isn't documented.


I don't believe the temp file behavior is customizable as it is 
hardcoded here to write to a temporary file (which is called on 
form parsing): 
https://github.com/vibe-d/vibe.d/blob/ebebfa827f568cc9bced4bec2b66edc043a8adf7/inet/vibe/inet/webform.d#L311


However if you really wanted to (but I'd advise against it) you 
could parse the form data from the HTTPServerRequest.bodyReader 
yourself



Yeah I think what he wants is a way to write the file into an 
in-memory buffer. This is especially necessary it some 
environments where you can write to disk at all.



How that's done, even in node.js is to use a middleware for 
parsing library to parse the headers in such way. I often use 
multer (which is also based on busybody) to do that in nodejs.


Unfortunately I haven't used D to that extent to need such a 
thing... I in never hit that problem.


I wonder if using a psuedo file handler will work for the 
in-memory buffer thing.




Re: Building LDC runtime for a microcontroller

2020-09-07 Thread aberba via Digitalmars-d-learn

On Monday, 7 September 2020 at 16:18:00 UTC, IGotD- wrote:
On Monday, 7 September 2020 at 15:23:28 UTC, Severin Teona 
wrote:

[...]


Use betterC, which is much better suited for microcontrollers 
than the full D. The disadvantage is that many great features 
are disabled in betterC.


[...]


How about an alternative runtime + standard library for embedded 
systems...with a least bare minimum. I've seen a number of 
efforts to get D to run in those environments but almost none of 
them is packaged for others to consume.


Re: Master Thesis using D Programming language.

2020-08-25 Thread aberba via Digitalmars-d-learn

On Monday, 24 August 2020 at 19:56:49 UTC, Tariq Siddiqui wrote:

Hello everyone,

I am looking for a master thesis topic using D Programming 
language. Earlier I choose Design by Introspection, but I did 
not find enough material in academic journals. DbI total 
material which I found is DConf Andrei talk and the similar 
talk at Google campus, which starts with 50 Deutsche Mark story 
and ends with explaining PbD, DbI and other Dlang internals. No 
doubt that Andrei's discussion was great. DbI as a topic is 
excellent, but as per my university requirements, I was not 
able to find five articles in the last five years in any 
academic journal, to start the initial discussion about the 
research topic.

Academic don't know innovation. Only history :)



I am still opened with my topic, next week, I have to submit my 
draft proposal. Till now, I did not meet my dissertation 
advisor.


Metaprogramming as suggested sounds interesting upon second 
thought. On Wikipedia, only D and C++ seems to have sufficient 
implementation among mainstream languages. With D's being 
exceptionally capable.


So you might want to do something around that...and how it 
impacts software development.




I am looking for something practical and less theoretical. I 
have found some thesis done using Rust, you guys as a language 
expert can these below projects be achievable using D 
Programming language.


Yep. Its does. Metaprogramming really has a very significant 
benefit in practice. And disign by introspection is one way it 
can be used.




Re: Master Thesis using D Programming language.

2020-08-25 Thread aberba via Digitalmars-d-learn

On Tuesday, 25 August 2020 at 16:52:17 UTC, aberba wrote:

On Monday, 24 August 2020 at 19:56:49 UTC, Tariq Siddiqui wrote:
Academic don't know innovation. Only history :)


Academia*


Re: vibe.d and my first web service

2020-08-21 Thread aberba via Digitalmars-d-learn

On Friday, 21 August 2020 at 09:50:38 UTC, ddcovery wrote:

On Friday, 21 August 2020 at 08:48:34 UTC, ddcovery wrote:

On Thursday, 20 August 2020 at 21:36:04 UTC, Andre Pany wrote:

[...]

Thanks a lot Andre,

I opened immediately the issues to receive some feedback:

[...]


EDIT: 23 days ago new vibe.d (0.9.0) was released... Testing 
with it memory problem has disappeared!!!


+1 to vibe.d :-)


I'm glad you came around.


Re: BetterC + WASM Update

2020-08-19 Thread aberba via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:

Hi all,

I'd like to make a WASM project, and looking into options.


It's scattered in several places including
https://gist.github.com/skoppe/7617ceba6afd67b2e20c6be4f922725d

Are you aware of Spasm?
https://github.com/skoppe/spasm



Re: vibe.d and my first web service

2020-08-17 Thread aberba via Digitalmars-d-learn

On Thursday, 13 August 2020 at 09:54:06 UTC, Mr. Backup wrote:
On Wednesday, 12 August 2020 at 13:46:06 UTC, James Blachly 
wrote:


Unfortunately the problem still occurs with Vibe.d 0.9.0

IMO **this is the single most important problem to fix** for 
vibe.d -- if the most basic of examples (indeed, supplied by 
dub itself) fails so spectacularly, the casual new user will 
not spend the time to find out why this is happening, but 
instead move on. The ctrl-C non-termination bug has existed 
since at least 2015 from what I can tell from the forums.




As a casual new novice, I really like dlang as such, and I 
think it should be the most widespread and popular language in 
the world. And as soon as I came across it, I wanted to use it 
in my project. But it has many packages for the same things, 
but these packages are unfinished. Everyone creates their own. 
You start comparing them and don't know what to choose for your 
job and then you find out that you should have chosen another 
and then find out that you should have written it yourself. And 
then I finally done it in golang in a while. I think the dlang 
community should focus on creating a quality standard library.


We live in the 21st century where there are web technologies 
everywhere around us, so I think that the http package should 
be part of a standard library.



It takes time. I was comparing packages available in D compared 
to say nodejs which I've been using for a while.


Very few important ones are missing. The others too lack some 
documentation. Other than that, you get pretty much what you 
need. Except cloud sdks.


also using vibe.d has some missing pieces on how to do certain 
things... that I agree we Users need to do writing about them.


You're also right that people keep rolling their own 
implementations. Most people here are really good and can roll 
their own so its quite tempting...plus reading someone's code and 
implementation can be a lil...sometimes. except rolling your own 
means it'll be half baked and undocumented.


Also I suspect lot of community members primary don't do web 
stuff primarily.


If you ask me, I'll say vibe.d is the most solid and feature 
complete web framework at the moment...code, docs, libraries. 
It's not perfect but its never been a blocker. That's if you know 
your way around it. Sonke is a pretty cool guy.


Will be nice if he had a GitHub sponsor or something for vibe.d

Hunt framework is also your laravel D alternative.






Re: Autodecode?

2020-08-16 Thread aberba via Digitalmars-d-learn

On Sunday, 16 August 2020 at 20:53:41 UTC, JN wrote:
Related to this thread: 
https://forum.dlang.org/post/xtjzhkvszdiwvrmry...@forum.dlang.org


I don't want to hijack it with my newbie questions. What is 
autodecode and why is it such a big deal? From what I've seen 
it's related to handling Unicode characters? And D has the 
wrong defaults?


https://forum.dlang.org/thread/qitnkf$2736$1...@digitalmars.com?page=1


Re: I just discovered an alternative use of the `in`-operator

2020-08-07 Thread aberba via Digitalmars-d-learn

On Friday, 7 August 2020 at 21:02:03 UTC, Per Nordlöw wrote:

On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote:

[1] https://dlang.org/spec/expression.html#is_expression


I bet there a several places in Phobos where this feature isn't 
but could be used.


I feel same. That there's a clever use of certain D features 
waiting to be discovered.


How does D's templated functions implementation differ from generics in C#/Java?

2020-08-07 Thread aberba via Digitalmars-d-learn
Syntactically they look the same (although D's can do more 
things) so I'm trying to understand how why in D it's called 
template but in languages like C#/Java they're generics.



I guess I have fair understanding of D's code generation but 
isn't it same as what what is available in those languages too? 
How are the implementation different?


Re: How do I convert a Base64 image url string to a png/jpg image file?

2020-07-30 Thread aberba via Digitalmars-d-learn

On Thursday, 30 July 2020 at 12:28:08 UTC, Adam D. Ruppe wrote:

On Thursday, 30 July 2020 at 12:22:46 UTC, aberba wrote:

[...]


I don't think I wrote it as a library yet, but the idea is 
pretty simple: they all start with "data:" so you look for that.


Then there's a type after that, so you read the string until 
the next ; character. It will be like image/png or image/jpeg.


Then there's the semicolon and the string "base64,".

After that, the rest of the string is base64 data.

```
import std.base64;
ubyte[] data = Base64.decode(rest_of_string);
```

And now that you have the data you can write it to a file:


⅞iii> import std.file;

std.file.write("filename.png", data);
```

And that should make the file you want.


Thank Adam.


How do I convert a Base64 image url string to a png/jpg image file?

2020-07-30 Thread aberba via Digitalmars-d-learn
So I have a base64 image url string and I'm trying to generate a 
png,jpg image file from it.


I'm able to decode it to a buffer but the trouble is getting it 
from buffer to an actual image file. Any library function 
combination I can use?


Re: Contributing to D wiki

2020-07-27 Thread aberba via Digitalmars-d-learn

On Monday, 27 July 2020 at 11:39:32 UTC, John Burton wrote:

On Wednesday, 15 July 2020 at 22:18:47 UTC, H. S. Teoh wrote:
On Wed, Jul 15, 2020 at 09:27:22PM +, tastyminerals via 
Digitalmars-d-learn wrote: [...]

[...]


Why not?  It's a *wiki*.  Wikis are intended for the user 
community (i.e. you & me) to go and edit.  That's the whole 
point of a wiki.  If that wasn't the intention we wouldn't 
have set up a wiki in the first place.


I tried looking there for information and examples of getting 
glfw3
statically linked into my program using LDC and didn't really 
find anything.


I wonder if adding a page for static linking tips would be 
useful as it seems to be problematic and compiler and 
environment dependent? Perhaps I should go ahead and see if I 
can make a page and see if anyone objects :P


I believe it'll be a useful addition. Please do that.


Re: How DerelictCL works

2020-07-21 Thread aberba via Digitalmars-d-learn

On Tuesday, 21 July 2020 at 12:00:03 UTC, bioinfornatics wrote:

Dear,

I would like to use OpenCL in D. Thus I try to use DerelictCL.
But I fail to use it I encounter this error message:
--
/opt/jonathan/jonathan-dlang_ldc2092/root/usr/include/d/derelict/opencl/constants.di(835):
 Error: genCLVectorTypes cannot be interpreted at compile time, because it has 
no available source code
/opt/jonathan/jonathan-dlang_ldc2092/root/usr/include/d/derelict/opencl/constants.di-mixin-835(835):
 Error: declaration expected, not <
--

[...]



Have you install the libopencl** dev dependencies?


Re: How Install and Configure DCD (D Completion Daemon) on Sublime Text?

2020-07-20 Thread aberba via Digitalmars-d-learn

On Monday, 20 July 2020 at 18:08:02 UTC, Marcone wrote:
How Install and Configure DCD (D Completion Daemon) on Sublime 
Text?

I need auto complete for the Dlang in Sublime Text.


Recently tried sublime myself for D since its quite lightweight 
compared to VS code for when I need to write something quick. 
Turns out most of the packages are outdated as everyone moved 
from it to something else...VS Code.


See https://wiki.dlang.org/IDEs if you want alternatives.


Re: How can I get Phobos Runtime Library docummentation in PDF?

2020-07-18 Thread aberba via Digitalmars-d-learn

On Saturday, 18 July 2020 at 00:23:22 UTC, Marcone wrote:
I need full Phobos Runtime Library docummentation in only one 
PDF file.


I'm not sure how to generate docs in a single html page but 
there's external services or tools to terms HTML files into PDF 
and much it all into one. This can be automated with a script.


Ddoc generates a docs folder containing HTML pages.

wkhtmltopdf is one command line tool you can use on Linux to 
generate PDF from html.


For combining PDFs, see some options at 
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf


For now I'm not aware of an all-in-one tool to do that.


Re: How to generate ddoc html?

2020-07-18 Thread aberba via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 20:50:14 UTC, Pavel Shkadzko 
wrote:
I've been skimming through https://dlang.org/spec/ddoc.html in 
order to understand how can one use ddoc to generate nice 
htmls. [...]


This post contains information on how to do that.

https://dlang.org/blog/2017/03/08/editable-and-runnable-doc-examples-on-dlang-org/



Re: How to generate ddoc html?

2020-07-18 Thread aberba via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 20:50:14 UTC, Pavel Shkadzko 
wrote:
I've been skimming through https://dlang.org/spec/ddoc.html in 
order to understand how can one use ddoc to generate nice 
htmls. I tend to use markdown to log some daily work or copy 
down code examples. For learning purposes I wanted to try ddoc 
for this but could not find any information on ddoc.html page 
on how to actually generate the html page. I guessed that dmd 
should have a switch to generate docs and was correct: dmd 
mylogs.dd -D would generate mylogs.html.


[...]


Yeah, I figured the ddoc documentation doesn't help much with 
this. And its true we need to document that part.


Re: D Wiki: run.dlang.io integration?

2020-07-16 Thread aberba via Digitalmars-d-learn

On Thursday, 16 July 2020 at 14:17:10 UTC, WebFreak001 wrote:

On Thursday, 16 July 2020 at 13:54:56 UTC, aberba wrote:

On Thursday, 16 July 2020 at 13:41:31 UTC, aberba wrote:

On Thursday, 16 July 2020 at 09:47:02 UTC, WebFreak001 wrote:

[...]


Since its based on WikiMedia, searched an came up with this 
[1] to embed in iframe


1. https://www.mediawiki.org/wiki/Extension:Iframe


Also the D Tour uses codemirror [1] which has an extension for 
wikimedia [2]


1. https://codemirror.net/index.html
2. https://www.mediawiki.org/wiki/Extension:CodeMirror


Yeah an extension combining CodeMirror and adding another tab 
or splitting the container for the output, executed by 
run.dlang.io would be a cool addition to the wiki and would not 
be blocked as easily as iframes.


From my quick lookup, its seems after embedded in your WikiMedia 
instances, it exposes a JavaScript API to monitor change and then 
execute the code. If run.dlang.io has a rest API of some kind, 
have to look up how it's done in tour, then its a matter of 
showing the code in a bottom div.


Not familiar with the WikiMedia extension system but having it as 
a reusable component will be the ideal approach.




I rather we go for a modernized wiki platform.




Re: D Wiki: run.dlang.io integration?

2020-07-16 Thread aberba via Digitalmars-d-learn

On Thursday, 16 July 2020 at 13:41:31 UTC, aberba wrote:

On Thursday, 16 July 2020 at 09:47:02 UTC, WebFreak001 wrote:

[...]


Since its based on WikiMedia, searched an came up with this [1] 
to embed in iframe


1. https://www.mediawiki.org/wiki/Extension:Iframe


Also the D Tour uses codemirror [1] which has an extension for 
wikimedia [2]


1. https://codemirror.net/index.html
2. https://www.mediawiki.org/wiki/Extension:CodeMirror


Re: D Wiki: run.dlang.io integration?

2020-07-16 Thread aberba via Digitalmars-d-learn

On Thursday, 16 July 2020 at 09:47:02 UTC, WebFreak001 wrote:
Is there a way to integrate some kind of "run this source code" 
button into the D wiki using run.dlang.io?


If there isn't, it would be nice to add this kind of thing as 
plugin with the possibility of also including the editor so you 
never need to leave the wiki. (like on the D Tour)


Since its based on WikiMedia, searched an came up with this [1] 
to embed in iframe


1. https://www.mediawiki.org/wiki/Extension:Iframe


Re: Vibe.d and NodeJs with Express

2020-07-15 Thread aberba via Digitalmars-d-learn

On Wednesday, 15 July 2020 at 04:19:57 UTC, bauss wrote:

On Sunday, 12 July 2020 at 19:16:32 UTC, aberba wrote:
3) packages, now it might be better though. But I've always 
felt that there's not a lot of people using D for complete web 
dev projects...



I implement most things I need myself;


That's when you have time and compelling reason to do that. Most 
at times I don't. And dub packages mostly works fine...why I like 
it when there's several options to choose from.


Contributing to D wiki

2020-07-15 Thread aberba via Digitalmars-d-learn
So I'm looking to make changes to the D wiki but I'm not sure who 
to talk to about such changes.


Currently: Move all other IDEs low-quality down (maybe to Others) 
and focus on just the few that really works (IntelliJ, Visual 
Studio Code and Visual Studio). Instead of many options that 
don't work, why not focus on they few that works?





Re: Error: `std.uni.isUpper` conflicts with `std.ascii.isUpper`

2020-07-15 Thread aberba via Digitalmars-d-learn

On Wednesday, 15 July 2020 at 07:01:34 UTC, WebFreak001 wrote:

On Tuesday, 14 July 2020 at 20:37:53 UTC, Marcone wrote:

[...]


Additionally to the other answers telling you how to fix it, 
it's important to know why it happens in the first place:


[...]


Without reading this very explanation, how would one know whilst 
reading docs?


Re: How can I make executeShell ask for Admin Elevation?

2020-07-13 Thread aberba via Digitalmars-d-learn

On Monday, 13 July 2020 at 00:57:02 UTC, Marcone wrote:

On Sunday, 12 July 2020 at 02:10:11 UTC, Marcone wrote:
I don't want start program with admin elevation, but ask user 
for admin permission when some function is called.


alias runas = compose!(x => to!bool((cast(int) x) > 32), x => 
ShellExecute(null, "runas", "cmd", cast(wchar*) "/c \"cd /d %s 
&& %s\"".format(getcwd(), x).to!wstring, null, 
SW_HIDE).WaitForSingleObject(WAIT_TIMEOUT));


runas("netsh winhttp set proxy 127.0.0.1:9666")


Can you put it into a small dub package?


Re: Vibe.d and NodeJs with Express

2020-07-12 Thread aberba via Digitalmars-d-learn

On Sunday, 12 July 2020 at 10:01:54 UTC, greatsam4sure wrote:
I am thinking of building an App with Vibe. D or NodeJS but my 
topmost priority is speed and ease of development due to third 
party libraries integration. I know Vibe. D is faster than 
NodeJS and I love to use Dlang. My question is can I eat my 
cake and have it if I go with Dlang and Vibe. D. I have being 
able to use jQuery and bootstrap with vibe. D and it work well. 
My believe is that most JavaScript library will work with Vibe. 
D out of the box. The application with use database heavily, 
can I work easily with database in vibe. D. For me I would love 
to use D for it raw power and speed.


Please this is a post to criticize D but to encourage me to use 
it. I need pros and cons


It depends. Most cases nodejs will work just fine for performance 
reasons.


Im my last major side project I tried to use vibe.d and even 
though I enjoy using D, I was slowed down by...


1) figuring vibe.d APIs out,

2) compilation speed (considering using something like nodemom, 
the nodejs express server just restarts on save)... I believe 
there's a way to do that in vibe.d by using a program that 
monitors file changes but wasn't a low hanging fruit so I just 
recompiled manual. Was very annoying but something like LDC or 
GDC would have made it worst. Compilation speed is very important 
for quick iterations... something you'll be doing 1000s of times.


3) packages, now it might be better though. But I've always felt 
that there's not a lot of people using D for complete web dev 
projects... packages was lacking. When doing a full stack job you 
then realise having packages for just about everything you need, 
gets the job done. Honestly was my main major issue. Yeah, main 
major :) Tried to build "sanival" for form data validation 
server-side (like validator.js) but gave up as project idea fell 
apart. Was very early stage...not much code was written then.  
Since then I haven't had chance to use D for such.


4. Help resources and people to ask for help. Now community is 
increasing so I'm sure it shouldn't be an issue. D community is 
very welcoming and helpful. That I really appreciate. However 
there's not a lot people doing web or stuff to Google. I did 
start blogging about D for web dev on my website to improve this. 
Random people actually liked it... considering my stuff are meh :)



That was about two yrs ago. New packages are now in dub. Even 
then every language suffers from sdks for interfacing with cloud 
services. AWS S3, Google services etc. Frankly something that 
makes nodejs very compelling cus there's packages for just about 
everything.



D is enjoyable to use nevertheless. I'm looking at doing another 
side project when time permits...or even continue my blog series 
(aberba.com)



So for me...its not mostly about the language itself but how I'm 
able to get things done.



I'm looking to improve resources discovery and availability in D 
for beginners too. Something I keep thinking about. Will 
hopefully share something soon.


Re: D Plugin for Visual Studio Code [was Re: Visual D 1.0.0 released]

2020-07-04 Thread aberba via Digitalmars-d-learn

On Saturday, 4 July 2020 at 19:52:42 UTC, Arafel wrote:

On 4/7/20 19:58, Paul Backus wrote:


You're looking for code-d:

https://github.com/Pure-D/code-d


Thanks! I'm trying it, although at least with VSCodium and 
Linux I had to build from sources, it didn't show by searching 
in the marketplace.


It DOES appear in the marketplace, its what I'm using. Just  
search for D programming or something. Its the most popular one 
there.


 One would assume such information is obvious to find but it is 
not. Unless you're already familiar with the ecosystem.


Re: How to implement Canceleable spawn() from parent

2020-07-01 Thread aberba via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 14:43:40 UTC, Steven Schveighoffer 
wrote:

On 6/30/20 10:15 AM, Simen Kjærås wrote:

[...]


My thinking is I don't want regular consumers using the package 
to think about the technicality of thread_joinAll() at all.


Thinking about putting it in a mixin like:

mixin KeepRunning;

Or something


Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread aberba via Digitalmars-d-learn

On Tuesday, 30 June 2020 at 12:48:32 UTC, Simen Kjærås wrote:

On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote:

On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote:

On 6/29/20 4:34 PM, aberba wrote:

> So with this, without the Thread.sleep() to block main from
exiting, the
> spawned thread  will terminate immediately.

You can call core.thread.thread_joinAll at the end of main.
So I tried that initially but my (){ writeln(...) } wasn't 
printing anything in console. Could that be related to stdout 
buffering? The program kept running though.






So I guess the error is elsewhere, but I'm not sure where and 
how.


Yeah, you're right. I changed receiveTimeout() to receive() to 
try something and forgot to change it back.


Jeez, I hate myself.

Thanks.


So how can I now hide the core.thread.thread_joinAll so the 
library user doesn't have to type it themselves in main() ? I 
don't see how that can be done.




Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread aberba via Digitalmars-d-learn

On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote:

On 6/29/20 4:34 PM, aberba wrote:

> So with this, without the Thread.sleep() to block main from
exiting, the
> spawned thread  will terminate immediately.

You can call core.thread.thread_joinAll at the end of main.
So I tried that initially but my (){ writeln(...) } wasn't 
printing anything in console. Could that be related to stdout 
buffering? The program kept running though.





Another way would be to wait for a worker's exit by looking for 
LinkTerminated but you need to start the thread with 
spawnLinked:


Read that too, but doesn't seem like the desired behavior I want.


So here's the thing, unlike JavaScript, the D behavior seems to 
be like a while(bool){} has to be placed directly within the 
scope of main. Was thinking as long my while loop in 
setInterval() was running, spawn() will be kept alive.


It seem both vibe.d and arsd have a similar setInterval() 
implementation and they both require using their event loop to 
keep the program alive.


In my case, wanted setInterval() to behave like it's own event 
loop without placing it in a while(bool){} loop in main()




Re: How to implement Canceleable spawn() from parent

2020-06-29 Thread aberba via Digitalmars-d-learn

On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote:

On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote:


   [...]



The error you're getting is because you're passing a pointer to 
a delegate instead of a delegate.


[...]


So with this, without the Thread.sleep() to block main from 
exiting, the spawned thread  will terminate immediately. How do I 
keep it from happening? Keep it running continuously?


From the docs, it says OwnerTerminated exception gets thrown when 
the sending thread (e.i. main) is terminated.


Thrown on calls to receive if the thread that spawned the 
receiving thread has terminated and no more messages exist.




Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn

On Sunday, 28 June 2020 at 23:39:07 UTC, Stanislav Blinov wrote:

On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote:


I believe this:

StopWatch sw;
sw.start;

works becuse D structs are initialized by default, right?
I've never actually done it this way. Little details.


Yup. You can also do a

auto sw = StopWatch(AutoStart.yes);

and not have to call `start` explicitly.


Interesting. I should look into Phobos more.


Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn

On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote:

On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote:

On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote:

 Thanks.

I believe this:

StopWatch sw;
sw.start;


works becuse D structs are initialized by default, right?
I've never actually done it this way. Little details.


So I checked receiveTimeout() when I was looking for what I could 
use. I wish there was an example in the docs.


https://dlang.org/library/std/concurrency/receive_timeout.html


Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn

On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote:

On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote:

 Thanks.

I believe this:

StopWatch sw;
sw.start;


works becuse D structs are initialized by default, right?
I've never actually done it this way. Little details.


How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn

Trying to implement a setInterval() that I can cancel using:

Tid tid = setInterval(2000, (){ writeln("hello");})

And then I can do:

stopInterval(tid);


With something like this:

stopInterval(Tid tid) {
send(tid, "cancel");
}

import std.stdio : writeln;
import std.concurrency : receive, spawn, thisTid, Tid;

auto setInterval(long milliseconds, void delegate() callback)
{
auto worker(long mls, void delegate() cb)
{
import core.thread.osthread : Thread;
import std.datetime : seconds, msecs;

writeln("Starting ", thisTid, "...");

bool done = false;

receive((string text) {
   writeln("Received string: ", text);
   done = true;
});

do
{
// or receive() comes here?

Thread.sleep(mls.msecs);
cb();
}
while (!done);
}

// I guess issue is with the callback
Tid id = spawn(, milliseconds, );

return id;
}



Getting error:

Error: template std.concurrency.spawn cannot deduce function from 
argument types !()(void delegate(Tid id) @system, Tid), 
candidates are:
/usr/include/dmd/phobos/std/concurrency.d(460,5):spawn(F, 
T...)(F fn, T args)

  with F = void delegate(Tid) @system,
   T = (Tid)
  must satisfy the following constraint:
   isSpawnable!(F, T)


Am I even using the right tool here?


Re: Light-weight runtime

2020-06-28 Thread aberba via Digitalmars-d-learn

On Sunday, 28 June 2020 at 07:09:53 UTC, Виталий Фадеев wrote:

I want light-weight runtime !

How to ?


If you have access to Google translate or any equivalent tool, 
you may use it to write in Russian language and copy+paste the 
English here. I think that'll really help.


I always give deep respect to people with different native 
languages who're trying really well to write English here. 
Considering someone of us learnt and wrote English in school but 
still suck at it. My biggest problem is typos.



--;;::
Now I think your question was discussed recently here 
https://forum.dlang.org/thread/gxtgbthyytukmqmzp...@forum.dlang.org


Re: How to work Get & Set text in clipboard in Windows ?

2020-06-22 Thread aberba via Digitalmars-d-learn

On Saturday, 20 June 2020 at 19:39:56 UTC, Vinod K Chandran wrote:

On Saturday, 20 June 2020 at 13:46:05 UTC, Dennis wrote:



Thanks a lot. Well, i thought it should be a one liner like-
Clipboard.SetText(sText)
But after reading your reply, i realized that this is D, not a 
scripting language. :)


It would be a one-liner if it was an api. Such utility APIs are 
quite missing in D.


How about putting them together into a package?


Re: Arduino and MCU Support

2020-06-19 Thread aberba via Digitalmars-d-learn

On Friday, 19 June 2020 at 11:57:01 UTC, frasdoge wrote:
I am looking to use D for microcontroller programming due to 
its benefits over C in workflow and general language features.


I was wondering what the current state of this is, especially 
with regards to AVR. An example of the MCUs I would like to 
develop with include anything from 8 bit ATmega328p to 32 bit 
ESP32.


The ESP32 can be programmed in C, C++, micropython and Lua, so 
I'm hoping there's at least some compatibility there.


Once you get it to work, please document something for use by 
others. Its quite unfortunate this is not well documented.


Re: Why is there no std.stream anymore?

2020-06-18 Thread aberba via Digitalmars-d-learn
On Thursday, 18 June 2020 at 15:03:38 UTC, Steven Schveighoffer 
wrote:

On 6/18/20 10:53 AM, aberba wrote:
On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven 
Schveighoffer wrote:

On 12/11/17 6:33 PM, Seb wrote:

[...]
Since iopipe was mentioned several times, I will say a couple 
things:


[...]



I should really try iopipe this time round. I think I avoided 
toying with it because the making conventions put me off. 
Don't remember about the docs and available examples though.


I have made some updates that are probably not reflected yet in 
the docs. But let me know if there are any stumbling blocks. I 
intend to make the iopipe + std.io (from Martin) a more 
user-friendly library in the near future.


-Steve


Will discuss in the GH issue


Re: Why is there no std.stream anymore?

2020-06-18 Thread aberba via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven 
Schveighoffer wrote:

On 12/11/17 6:33 PM, Seb wrote:

[...]
Since iopipe was mentioned several times, I will say a couple 
things:


[...]



I should really try iopipe this time round. I think I avoided 
toying with it because the making conventions put me off. Don't 
remember about the docs and available examples though.


Re: Alpine support for D

2020-06-09 Thread aberba via Digitalmars-d-learn

On Wednesday, 10 June 2020 at 01:06:30 UTC, aberba wrote:

On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote:
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or 
packages added to the repo?


Tradionally you'd run D on something like Ubuntu, etc but 
Alpine is lightweight which is a good thing when building 
docker containers. Alpine uses a different C runtime musl?? 
among other things whilst D uses use libc. So I believe we now 
have bindings musl too to get D to work on Alpine.


https://en.m.wikipedia.org/wiki/Musl


Re: Alpine support for D

2020-06-09 Thread aberba via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote:
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or 
packages added to the repo?


Tradionally you'd run D on something like Ubuntu, etc but Alpine 
is lightweight which is a good thing when building docker 
containers. Alpine uses a different C runtime musl?? among other 
things whilst D uses use libc. So I believe we now have bindings 
musl too to get D to work on Alpine.


Re: Control flushing to stdout... core.osthread.Thread + arsd.terminal

2020-06-05 Thread aberba via Digitalmars-d-learn

On Friday, 5 June 2020 at 12:28:17 UTC, Adam D. Ruppe wrote:

On Friday, 5 June 2020 at 11:45:31 UTC, aberba wrote:
How can I make Thread.sleep() only run AFTER "Wait, signing 
you in ..." is written (force flushed) to stdout?


just use explicit `terminal.flush();` any time you want the 
output to appear immediately.


Terminal does its own aggressive buffering internally (which I 
kinda regret) and only flushes with 1) it is full or 2) you ask 
for input, unless you call that flush function.


Ooop. Forgot to say thanks. Thanks, works as expected now.

Didn't come to mind to lookup from terminal docs. Thought it was 
a Dlang/OS problem.


Re: Control flushing to stdout... core.osthread.Thread + arsd.terminal

2020-06-05 Thread aberba via Digitalmars-d-learn

On Friday, 5 June 2020 at 12:28:17 UTC, Adam D. Ruppe wrote:

On Friday, 5 June 2020 at 11:45:31 UTC, aberba wrote:
How can I make Thread.sleep() only run AFTER "Wait, signing 
you in ..." is written (force flushed) to stdout?


just use explicit `terminal.flush();` any time you want the 
output to appear immediately.


Terminal does its own aggressive buffering internally (which I 
kinda regret) and only flushes with 1) it is full or 2) you ask 
for input, unless you call that flush function.


Why was the initial decision to handle buffering that way in 
terminal?


Control flushing to stdout... core.osthread.Thread + arsd.terminal

2020-06-05 Thread aberba via Digitalmars-d-learn
I have this code which take two inputs. I expect "Wait, signing 
you in ..." to be written to stdout before Thread.sleep() kicks 
in but it somehow doesn't follow that sequence. I believe its a 
normal stdout behaviour since its buffered.


How can I make Thread.sleep() only run AFTER "Wait, signing you 
in ..." is written (force flushed) to stdout?


import core.thread.osthread, std.datetime;
import arsd.terminal;

void main()
{
auto terminal = Terminal(ConsoleOutputType.linear);
terminal.setTitle("App");

// this is possible too but you MUST have an indexed png 
which might be hard to make if you aren't ready for it.

// terminal.changeWindowIcon("assets/icon.png");

terminal.writeln("hi");

auto got = terminal.getline("Username: ");
auto code = terminal.getline("Password: ");

const timeInSeconds = 5;
terminal.writeln("Wait, signing you in ...");


Thread.sleep(timeInSeconds.seconds);


terminal.writeln("username is ", got);
terminal.writeln("code is ", code);
}



Re: Is there a list of things which are slow to compile?

2020-06-05 Thread aberba via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 17:02:35 UTC, H. S. Teoh wrote:
On Wed, Jun 03, 2020 at 09:36:52AM +, drathier via 
Digitalmars-d-learn wrote:
I'm wondering if there's a place that lists things which are 
slower/faster to compile? DMD is pretty famed for compiling 
quickly, but I'm not seeing particularly high speed at all, 
and I want to fix that.


The two usual culprits are:
- Recursive/chained templates
- Excessive CTFE

Note that while the current CTFE engine is slow, it's still 
reasonably fast for short computations. Just don't write nested 
loops or loops with a huge number of iterations inside your 
CTFE code, and you should be fine. And on that note, even 
running std.format with all of its complexity inside CTFE is 
reasonably fast, as long as you don't do it too often; so 
generally you won't see a problem here unless you have loop 
with too many iterations or too deeply-nested loops running in 
CTFE.


Templates are generally reasonably OK, until you use too many 
recursive templates. Or if you chain too many of them together, 
like if you have excessively long UFCS chains with Phobos 
algorithms. Short chains are generally OK, but once they start 
getting long they will generate large symbols and large numbers 
of instantiations. Large symbols used to be a big problem, but 
ever since Rainer's fix they have generally been a lot tamer. 
But still, it's something to avoid unless you can't help it.


Recursive templates are generally bad because they tend to 
produce a super-linear number of instantiations, which consume 
lots of compiler memory and also slow things down. Use too many 
of them, and things will quickly slow to a crawl.


Worst is if you combine both deeply-nested templates and CTFE, 
like std.regex does. Similarly, std.format (which includes 
writefln & co) tends to add 1-2 seconds to compile time.


Another is if you have an excessively long function body, IIRC 
there are some O(n^2) algorithms in the compiler w.r.t. the 
length of the function body. But I don't expect normal code to 
reach the point where this begins to matter; generally you 
won't run into this unless your code is *really* poorly written 
(like the entire application inside main()), or you're using 
excessive code generation (like the mixin of a huge 
procedurally generated string).


Identifier lengths are generally no problem unless you're 
talking about 100KB-long identifiers, which used to be a 
problem until Rainer implemented backreferences in the 
mangling. But I don't expect normal code to generate symbols of 
this order of magnitude unless you're using excessively-long 
UFCS chains with nested templates. Identifier length generally 
doesn't even register on the radar unless they're ridiculously 
long, like tens or hundreds of KB long -- not something a human 
would type. What humans would consider a long identifier, like 
Java-style names that span 50 characters, are mere round-off 
error and probably don't even make a measurable difference. The 
problem really only begins to surface when you have 10,000 
characters in your identifier or larger.


Comments are not even a blip on the radar: lexing is the 
fastest part of the compilation process.  Similarly, aliases 
are extremely cheap, it's not even on the radar. Delegates have 
only a runtime cost; they are similarly unnoticeably cheap 
during compilation.  As are Variants, unless you're running 
Variants inside CTFE (which I don't think even works).



T


I'm thinking about a resource hub for D with information like 
these. Can I use this information? ...of course I'll reference 
this thread and you can always call for changes.


Re: I want Sublime 3 D auto import !

2020-06-03 Thread aberba via Digitalmars-d-learn

On Monday, 1 June 2020 at 17:28:16 UTC, Johannes Loher wrote:

On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote:

[...]


Demanding stuff usually doesn't work in this community. The 
usual answer is something like this: If you care about this, 
implement it yourself or pay somebody to do it.


Depends on how you interpret it.


Re: Best way to learn 2d games with D?

2020-03-16 Thread aberba via Digitalmars-d-learn

On Tuesday, 17 March 2020 at 03:13:02 UTC, aberba wrote:
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer 
wrote:
I want to try and learn how to write 2d games. I'd prefer to 
do it with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? 
Should I just start with another language and then migrate to 
D later? Anyone recommend any specific tutorial/book?


-Steve


https://github.com/DerelictOrg/DerelictSFML2 is the most up to 
date D binding to SFML library. Now that the maintainer is 
saying bindbc is better, I'm not sure the way to go.


Will we ever get a bindbc-sfml?


By the way, the maintainer of DSFML went very far by creating a 
great website with docs and tutorials at http://www.dsfml.com/


You can still use DSFML with an older compiler by installing and 
using with something like DVM 
(https://code.dlang.org/packages/dvm)


Re: Best way to learn 2d games with D?

2020-03-16 Thread aberba via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer 
wrote:
I want to try and learn how to write 2d games. I'd prefer to do 
it with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? 
Should I just start with another language and then migrate to D 
later? Anyone recommend any specific tutorial/book?


-Steve


https://github.com/DerelictOrg/DerelictSFML2 is the most up to 
date D binding to SFML library. Now that the maintainer is saying 
bindbc is better, I'm not sure the way to go.


Will we ever get a bindbc-sfml?


By the way, the maintainer of DSFML went very far by creating a 
great website with docs and tutorials at http://www.dsfml.com/





Re: Best way to learn 2d games with D?

2020-03-16 Thread aberba via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer 
wrote:
I want to try and learn how to write 2d games. I'd prefer to do 
it with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? 
Should I just start with another language and then migrate to D 
later? Anyone recommend any specific tutorial/book?


-Steve


Its sad we still don't have a really great framework/engine for 
developing 2d games in D...even with many options in C available. 
It seems the casual game community/fan is missing here.


Re: Best way to learn 2d games with D?

2020-03-16 Thread aberba via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer 
wrote:
I want to try and learn how to write 2d games. I'd prefer to do 
it with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? 
Should I just start with another language and then migrate to D 
later? Anyone recommend any specific tutorial/book?


-Steve


Over the years, I've seen so many 2d game frameworks/engine get 
started and abandoned here. I would recommend DSFML if you can 
get it to work. I really like the SFML API design. With that 
said, here are some I looked at:


https://code.dlang.org/packages/d2dgame (based on SDL2 by 
WebFreak001, not sure how mature it is though, see a demo at 
https://github.com/WebFreak001/D2DGame/blob/master/example/source/app.d)



https://code.dlang.org/packages/dagon (Mostly 3d, but can do 
3d/2d games too. The most advanced of any D game 
engine/framework. Tonne of work poured into it)


https://code.dlang.org/packages/pixelperfectengine (retro games, 
I have seen several YouTube demos by the dev)


https://code.dlang.org/packages/godot-d (Godot is quite 
popular..used in commercial game. Not sure how good and easy to 
use this binding is though)


https://themindofmurilomiranda.blogspot.com/2020/01/space-invaders-game-example-to-learn.html
 (Murilo Miranda has this tutorial he pulled together after working tirelessly 
and asking many question on using Adam's arsd package here, I like this guy's 
tenacity)



Re: Using D for Raspberry Pi expirements

2019-09-29 Thread aberba via Digitalmars-d-learn

On Sunday, 29 September 2019 at 16:26:48 UTC, Aldo wrote:

On Sunday, 29 September 2019 at 11:36:00 UTC, aberba wrote:
On Thursday, 26 September 2019 at 00:09:30 UTC, Mike Franklin 
wrote:

[...]


I have no idea how to do that from D. Any help/resources on 
that?


Maybe you can use this dub package? 
http://code.dlang.org/packages/dgpio


I'm using a D app on a raspberry Pi to open my house portal for 
1 year now. It works perfectly. The "hardest" part is the 
compilation.


I tried this guide yesterday: 
https://wiki.dlang.org/Programming_in_D_tutorial_on_Embedded_Linux_ARM_devices and it worked perfectly fine. I compiled my app from Windows with a Debian (from the windows store) and uploaded my executable compiled with ARM target.


Thanks. Appreciate.


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-29 Thread aberba via Digitalmars-d-learn

On Thursday, 26 September 2019 at 16:30:39 UTC, Andre Pany wrote:
On Wednesday, 25 September 2019 at 17:03:51 UTC, Ron Tarrant 
wrote:
On Wednesday, 25 September 2019 at 13:52:48 UTC, 
bioinfornatics wrote:


I think I misunderstood your need but are lo looking for dub 
tool with its repository https://code.dlang.org/


I don't think so, but I could be wrong. I tried reading up on 
dub, but got lost in the docs, so I really don't understand 
what all it can do.


Dub is a tool for developers, I understand your requirements 
that you want target end customers of your applications. 
Therefore dub is the wrong tool for this job.


To be more precise, gtkd is a wrapper for GTK. Gtkd is not 
interesting in this context, but the dependency on gtk. On 
windows you have the possibility to either publish your 
application with GTK dlls or to run gtk setup routine as part 
of your application setup routine or just say in your readme 
that the customer needs to run GTK setup on there own.


On posix (linus, macos) of course you can also say in your 
readme that the customer should run apt-get ... to install gtk 
(here I do not have much knowledge on packaging).


Kind regards
Andre


I will immediately abandon any app that provides this sort of 
incomplete experience to use unless I have my developer hats 
on...or I really have not other choice.


Re: Using D for Raspberry Pi expirements

2019-09-29 Thread aberba via Digitalmars-d-learn
On Thursday, 26 September 2019 at 00:09:30 UTC, Mike Franklin 
wrote:

On Wednesday, 25 September 2019 at 23:56:45 UTC, aberba wrote:
I'm looking for resources on using D for basic Raspberry Pi 
programming...stuff like turning on and off an LED light. I 
believe it requires being able to call the Raspberry OS core 
APIs from D as available in Python.


Anyone here tried something like that using D?


I haven't tried with D yet, but I use C# and mono calling into 
the pigpio C library (http://abyz.me.uk/rpi/pigpio/pdif2.html) 
and it workes great.  You should be able to do the same with D.


Mike


I have no idea how to do that from D. Any help/resources on that?


Re: Using D for Raspberry Pi expirements

2019-09-29 Thread aberba via Digitalmars-d-learn
On Thursday, 26 September 2019 at 17:26:25 UTC, Dave Chapman 
wrote:

On Thursday, 26 September 2019 at 00:10:40 UTC, aberba wrote:

[...]


I've been using 
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ . It 
is a C library written by Bartosz Golaszewski. He is actively 
working on it. The latest update is a week old. It has the 
advantage that you don't have to use sudo to access the gpio 
pins. It comes with a set of tools written in C that I have 
been converting to D. Since my knowledge of both D and C is 
weak it has taken me some time to get things going. I have a 
hand written D bindings file that is incomplete and of amateur 
quality. So far I have converted 2 of the 6 command line tools 
that Bartosz Golaszewski provided to to work with the library.


David Chapman


your code... can you push it to GitHub so I can check it out?


Re: Using D for Raspberry Pi expirements

2019-09-25 Thread aberba via Digitalmars-d-learn

On Wednesday, 25 September 2019 at 23:56:45 UTC, aberba wrote:
I'm looking for resources on using D for basic Raspberry Pi 
programming...stuff like turning on and off an LED light. I 
believe it requires being able to call the Raspberry OS core 
APIs from D as available in Python.


Just found this package dating back from May 2016...let's see 
what it can do 
(https://github.com/fgheorghe/D-Lang-Raspbian-GPIO-Module)




Anyone here tried something like that using D?





Using D for Raspberry Pi expirements

2019-09-25 Thread aberba via Digitalmars-d-learn
I'm looking for resources on using D for basic Raspberry Pi 
programming...stuff like turning on and off an LED light. I 
believe it requires being able to call the Raspberry OS core APIs 
from D as available in Python.


Anyone here tried something like that using D?


Re: gtkDcoding Blog Post for 2019-03-29 - Grid

2019-03-29 Thread aberba via Digitalmars-d-learn

On Friday, 29 March 2019 at 14:25:16 UTC, Ron Tarrant wrote:

I'm having trouble replying to the thread I usually use, so...

There's a new tutorial for using a GTK Grid. You can find it 
here: http://gtkdcoding.com/2019/03/29/0022-grids.html


Have shared gtkdcoding.com with some folks and they like it, keep 
it coming!!




Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-20 Thread aberba via Digitalmars-d-learn

On Monday, 19 November 2018 at 21:39:22 UTC, Adam D. Ruppe wrote:
On Monday, 19 November 2018 at 21:23:31 UTC, Jordi Gutiérrez 
Hermoso wrote:

What's the reasoning for allowing this?


The mistake is immediately obvious when you run the program, so 
I just don't see it as a big deal. You lose a matter of 
seconds, realize the mistake, and fix it.


What is your proposal for handling it? The ones usually put 
around are kinda a pain to use.


Does D have a linter which warns about certain style of coding 
like this?


Re: How do I install a library?

2018-11-10 Thread aberba via Digitalmars-d-learn

On Thursday, 8 November 2018 at 23:51:39 UTC, bachmeier wrote:

On Thursday, 8 November 2018 at 23:43:38 UTC, Murilo wrote:

It finally worked, but I can't just compile it normally, I 
have to use dub run, I wish it were something simple that I 
just download into the folder and then use an import statement 
and then compile it like any other program. I wish it were as 
simple as using std.stdio for example.


Unfortunately your stuck with Dub if you want to use D. It's an 
awful experience compared to Python and other scripting 
languages, so I understand what you're saying, but most people 
around here think Dub is the way to go.



Stop bashing dub. Its completely fine for me. I don't get what OP 
mean by "simple" but:


dub init
add package name
dub run

... doesn't look "not simple" to me.


Re: Building GUI projects with D

2018-11-02 Thread aberba via Digitalmars-d-learn

On Saturday, 20 October 2018 at 15:40:07 UTC, karis njiru wrote:
Hi. Am a computer science student from Kenya and decided to use 
D for my class project on Principles of Programming Languages. 
Am having a lot of fun with D but have come across an issue. I 
have been using Visual D for the past 2 months for my coding 
but after a lot of research i found out that i cannot build GUI 
projects with visual D. So i took on Entice Designer which for 
the past week has been a nightmare for me to compile my code 
error being the system cannot find the path in the command 
prompt specified. I have installed DMD and DFL lots of times 
but there is still the same issue. Please help


Hi, Nice meeting you. I assume your on Window.


There

1. DlangUI which is the easiest (for beginners) in my experience: 
https://github.com/buggins/dlangui


2. QT (great documentation): 
https://forum.dlang.org/thread/leviwswvvcnqberaf...@forum.dlang.org#post-nk9alu:241tvq:241:40digitalmars.com


3. GTK-d would be what you'll use if on Linux:
https://github.com/gtkd-developers/GtkD/wiki/Installing-on-Windows



By the way, I'm from Ghana. Its good to know someone in Kenya is 
interested in D. You may hit me by email karabutawo...@gmail.com 
(Github: https://github.com/aberba)




Re: How to implement D to HTML pages ?

2018-10-03 Thread aberba via Digitalmars-d-learn
On Monday, 1 October 2018 at 19:29:56 UTC, Aurélien Plazzotta 
wrote:

Hello guys,

I would like to implement a forum and a blog within my website 
(currently including only HTML, CSS and JS, written without 
CMS), using D and SQL but I really don't know how to proceed. 
How can I integrate D into HTML pages? Are there any kind of 
include's commands like PHP ?


Also, do I have to use vibe.d ? Or is it optional? I admit I 
didn't read the book yet (D Web Development), but only 
"Programming in D", which doesn't deal much with website 
workflow.


Finally, what database system do you recommand to interact with 
for data-oriented website purpose? Perhaps, there are some 
standard or tierce-party librairies or ORM for PostgreSQL or 
SQLite ?


Thanks for all the light anyone will be willing to spread :)


Nothing get you simpler with Vibe.d than my blog[1]. I've done a 
series of tutorials for beginners but straight to the point.


1. https://aberba.netlify.com/
2. 
https://aberba.netlify.com/2016/hello-world-app-with-the-vibe.d-web-framework/

3. https://aberba.netlify.com/2016/form-upload-in-vibe-d/
4. https://aberba.netlify.com/2017/multiple-file-upload-in-vibe-d/
5. https://aberba.netlify.com/2018/using-vibe-d-web-interface/


Re: Constructing text with astericks

2018-05-31 Thread aberba via Digitalmars-d-learn

On Wednesday, 30 May 2018 at 23:11:06 UTC, Adam D. Ruppe wrote:

On Wednesday, 30 May 2018 at 22:57:06 UTC, aberba wrote:

How will you approach this problem in D idiomatically?


Well, I never bother with "idiomatically", so I can't speak to 
that, but a simple solution that would work is to realize that 
what you're basically asking for here is a bitmap.


Each letter in your "font" would be a little bitmap that you 
copy into a destination buffer - itself a larger bitmap.


Then, when it is complete, you can draw the destination buffer 
line by line to the screen.


The data for your font may just be a bunch of string arrays in 
source, or an actual bitmap file you create outside the program 
and load at runtime or something like that. Just remember that 
you can't just `buffer ~= letter` - you need to do line by line 
since the two bitmaps will have different sizes.


That doesn't sound like a trivial thing to do. Ha ha


Constructing text with astericks

2018-05-30 Thread aberba via Digitalmars-d-learn
I've been given a challenge to write texts using asterisks to 
form the letters. D happen to have an unlimited amount of idioms 
yet i'm out out ideas as to the simplest approach. Task is to 
basically take a piece of text and write them as asterisks to the 
console.


*  *
*  *
*  *
*  *
*  *

First solution I found was to create a class for each 
letter...like new A(), new B() and implement the logic withing 
each class. This doesn't scale and i'll have to write about 24 or 
more classes.


Another complex but "makes sense" solution will be to use a GRID 
system like old digital watches but i'll need a more complex grid 
to draw complex letters using a dictionary of REPOPULATED indexes 
of asterisk for each word. First use the length of the string to 
compute the grid size and iterate over each character to 
indentify the dictionary of a letter's indexes to use:


*
***
**   **
***
**  ***
**   ***  (an R using a more complex Grid)


How will you approach this problem in D idiomatically?


Re: What's the purpose of the 'in' keyword ?

2018-05-30 Thread aberba via Digitalmars-d-learn

On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
On Sunday, May 27, 2018 16:28:56 Russel Winder via 
Digitalmars-d-learn wrote:
On Sun, 2018-05-27 at 13:10 +, Adam D. Ruppe via 
Digitalmars-d-learn



- Jonathan M Davis


Jonathan, which font were you using in your DConf powerpoint 
presentation for source code? It made the code look really 
nice...and also you have good naming skills.





Re: Testing D database calls code for regression

2018-03-19 Thread aberba via Digitalmars-d-learn

On Monday, 19 March 2018 at 00:56:26 UTC, H. S. Teoh wrote:
On Sun, Mar 18, 2018 at 07:51:18PM +, aberba via 
Digitalmars-d-learn wrote:

On Friday, 16 March 2018 at 21:15:33 UTC, H. S. Teoh wrote:
> On Fri, Mar 16, 2018 at 08:17:49PM +0000, aberba via 
> Digitalmars-d-learn wrote:

> > [...]
> 
> The usual way I do this is to decouple the code from the 
> real database backend by templatizing the database driver.  
> Then in my unittest I can instantiate the template with a 
> mock database driver that only implements the bare minimum 
> to run the test.
> 
> [...]


Mocking a fake database can also be huge pain. Especially when 
something like transactions and prepared statements are 
involved.


It depends on what your test is looking for.  The idea is that 
the mock database only implements a (small!) subset of a real 
database, basically just enough for the test to run, and 
nothing more.  Of course, sometimes it may not be easy to do 
this, if the code being tested is very complex.




Imagine testing your mock for introduced by future extension.


If you find yourself needing to test your mock database, then 
you're doing it wrong.  :-D  It's supposed to be helping you 
test your code, not to create more code that itself needs to be 
tested!


Basically, this kind of testing imposes certain requirements on 
the way you write your code. Certain kinds of code are easier 
to test than others.  For example, imagine trying to test a 
complex I/O pipeline implemented as nested loops. It's 
basically impossible to test it except as a blackbox testing 
(certain input sets must produce certain output sets). It's 
usually impractical for the test to target specific code paths 
nested deep inside a nested loop. The only thing you can do is 
to hope and pray that your blackbox tests cover enough of the 
code paths to ensure things are correct. But you're likely to 
miss certain exceptional cases.


But if said I/O pipeline is implemented as series of range 
compositions, for example, then it becomes very easy to test 
each component of the range composition. Each component is 
decoupled from the others, so it's easy for the unittest to 
check all code paths. Then it's much easier to have the 
confidence that the composed pipeline itself is correct.


I/O pipelines are an easy example, but understandably, in 
real-world code things are rarely that clean.  So you'll have 
to find a way of designing your database code such that it's 
more easily testable. Otherwise, it's going to be a challenge


The thing about functional programming where functions are 
decoupled/testable doesn't seem to apply to database call code. I 
guess its because databases introduces a different 
state...another point of failure.


no matter what.  No matter what you do, testing a function made 
of loops nested 5 levels deep is going to be very hard.  
Similarly, if your database code has very complex 
interdependencies, then it's going to be hard to test no matter 
how you try.
My code logic is a mix of file uploads which leads to saving file 
info into db. And some general queries... my worry has been 
adding a feature which might cause a regression in another rearly 
executed code...its feels like I have to test all features/rest 
calls after every major change. Don't know how others do 
this...when there's some tight coupling involved.




Anyway, on the more practical side of things, depending on what 
your test is trying to do, a mock database could be as simple 
as:


struct MockDb {
string prebakedResponse;
auto query(string sql) {
if (sql == "SELECT * FROM data")
return prebakedResponse;
else if (sql == "UPDATE * SET ... ")
prebakedResponse = ...
else
assert(0, "Time to rewrite your unittest :-P");
}
}

I.e., you literally only need to implement what the test case 
will actually invoke. Anything that isn't strictly required is 
fair game to just outright ignore.


Also, keep in mind that MockDb can be a completely different 
thing per unittest. Trying to use the same mock DB for all 
unittests will just end up with writing your own database 
engine, which kinda defeats the purpose. :-P  But the ability 
to do this depends on how decoupled the code is.  Code with 
complex interdependencies will generally give you a much harder 
time than more modular, decoupled code.



T





Re: Testing D database calls code for regression

2018-03-18 Thread aberba via Digitalmars-d-learn

On Friday, 16 March 2018 at 21:15:33 UTC, H. S. Teoh wrote:
On Fri, Mar 16, 2018 at 08:17:49PM +, aberba via 
Digitalmars-d-learn wrote:

[...]


The usual way I do this is to decouple the code from the real 
database backend by templatizing the database driver.  Then in 
my unittest I can instantiate the template with a mock database 
driver that only implements the bare minimum to run the test.


[...]


Mocking a fake database can also be huge pain. Especially when 
something like transactions and prepared statements are involved.


Imagine testing your mock for introduced by future extension.


Testing D database calls code for regression

2018-03-16 Thread aberba via Digitalmars-d-learn
How will you test D code which makes calls to database to detect 
bugs and regression. Unlike where you can inject data like assert 
(2+1 == 3), database interfacing code will be crazy... Or there's 
some mocking available for such cases. Especially when more 
features are developed on top.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread aberba via Digitalmars-d-learn

On Friday, 16 March 2018 at 17:11:17 UTC, visitor wrote:

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


There's also gtkd sourceview :
https://github.com/gtkd-developers/GtkD/tree/master/generated/sourceview


I think you mean Gtk web view. It comes from WebKit.


Re: VibeD Rest Interface Generator

2018-03-04 Thread aberba via Digitalmars-d-learn

On Saturday, 3 March 2018 at 02:32:11 UTC, Mario wrote:
So I've been learning D since the day 11 (I posted for first 
time here) and now I've decided to try Vibe.D to make my 
company API.


The fact is that I've achieved to do it (according to the 
provided code) and it works! But it shows a default message and 
on the startup. So I'd like to know how can I set it to receive 
the HTTP(s) request, analyze the body and get the data through 
a database (we will probably use MongoDB).


If you can help me with this, I'd be grateful. Best regards, 
Mario :-)


The "examples" folder of vibe.d code on Github has demo on using 
HTTPS, mongodb query and many others. Check it out.


Re: Vibe.d no more using static this() {}

2018-02-25 Thread aberba via Digitalmars-d-learn

On Sunday, 25 February 2018 at 01:15:06 UTC, Seb wrote:

On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote:
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop.


"Recently"?
FWIW this has been phased out a long time ago ;-)
That's how I've been doing it 
http://aberba.com/2016/form-upload-in-vibe-d/


---

0.7.23 (2015)

Definition of either VibeCustomMain or VibeDefaultMain is now 
a hard requirement - this is the final deprecation phase for 
VibeCustomMain


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-10

Added a compile time warning when neither VibeCustomMain, nor 
VibeDefaultMain versions are specified - starts the transition 
from VibeCustomMain to VibeDefaultMain


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-14


0.7.30 (2016)

Added runApplication as a single API entry point to properly 
initialize and run a vibe.d application (this will serve as 
the basis for slowly phasing out the VibeDefaultMain 
convenience mechanism)


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-4


I should take these changelogs seriously and read into details.


---



Why that change?


In short, because there are too many problems with starting the 
eventloop by default without stating so and requiring the user 
to know what's going on. I don't know all the reasons, but one 
example that comes to my mind is that if you use Vibe.d for a 
simple curl-like script, you might be wondering why it never 
exits.
Also you mention `static this` in your title, but usually 
`shared static this` should be used.

Oh. I've been using "static this". Noted.



There are also other concerns, e.g. the @safe-ty of the 
eventloop is never checked when you use the default main method.



Hence, in 2014 VibeDefaultMain was introduced to move away 
VibeCustomMain (which required the user to take explicit action 
when the eventloop shouldn't run).


Nowadays, a user neds to choose whether to use the default main 
loop (versions "VibeDefaultMain") or call 
runEventLoop/runApplication, but "VibeDefaultMain" with shared 
static this is deprecated.


static this seemed clean though :)



Re: Vibe.d no more using static this() {}

2018-02-23 Thread aberba via Digitalmars-d-learn

On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote:
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop. Why that change?


Like:

#!/usr/bin/env dub
/+ dub.sdl:
name "hello_vibed"
dependency "vibe-d" version="~>0.8.0"
+/
import vibe.d;

void main()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;

listenHTTP(settings, (req, res) { res.writeBody("Hello 
Vibe.d: " ~ req.path); });

runApplication();
}


Vibe.d no more using static this() {}

2018-02-23 Thread aberba via Digitalmars-d-learn
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop. Why that change?


Re: countUntil to print all the index of a given string.

2018-02-20 Thread aberba via Digitalmars-d-learn

On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote:

On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote:

[...]


Just thought of a much better/simpler solution for that last 
case that also doesn't force you to read all data (which might 
be impossible when dealing with infinite ranges):


import std.range;
import std.algorithm;

a[]
 .enumerate   // get tuples (index, 
value)
 .filter!(t => t[1] == "Test2")   // keep only if value == 
"Test2"
 .map!(t => t[0]) // keep only the index 
part

 .writeln;

Completely lazy.


How does one detect an operation as lazy or not?  Is the some 
compile-time or runtime check for that?


My guess is by referring to the docs function signature.


Re: vib.d suppress 404 for no content written

2018-02-14 Thread aberba via Digitalmars-d-learn

On Wednesday, 14 February 2018 at 14:58:14 UTC, Seb wrote:
On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson 
wrote:

I have an endpoint that is a post:

void postStuff(HTTPServerRequest req, HTTPServerResponse res)
{
// do some stuff with req
res.statusCode = 200;
}

I do not write anything to res (deliberately) but want to set 
the status code.


However it returns 404, because no content is written.
How can I make it return 200?

FWIW its a member of a web interface class.

Thanks
Nic


You mean `writeVoidBody`

See Also: https://github.com/vibe-d/vibe.d/issues/2065


Seb,  are you the one doing the vibe.d demo collections?


Re: DLangUI Drag and Drop support?

2018-02-06 Thread aberba via Digitalmars-d-learn

On Saturday, 3 February 2018 at 18:06:30 UTC, Andres Clari wrote:

Hi, is there support for drag and drop in dlangui??
I haven't found anything on the docs, issues or forums.

I'm building a project that requires support for dropping URLs 
from the browser into a ListWidget. Is this possible with 
dlangui at all?


Can you please file an issue in the github repo. Its very active 
so it's possible support will be implemented sooner.


Re: How to proceed with learning to code Windows desktop applications?

2018-01-30 Thread aberba via Digitalmars-d-learn

On Tuesday, 30 January 2018 at 18:41:57 UTC, I Lindström wrote:

On Tuesday, 30 January 2018 at 05:56:51 UTC, DanielG wrote:
There are far too many options for Windows GUI programming, so 
we probably need a bit more information about any constraints 
that are important to you.


For example:

- do you specifically want something that works well with D? 
or are you open to other languages?


- are you just wanting to learn desktop programming in 
general? (Like the concepts involved) Or do you have a 
specific thing you want to create?


I would personally suggest Delphi to somebody who wants to 
write Windows desktop apps and learn about event-driven 
development, howeverrr the language (Object Pascal) is 
insufferably archaic compared to something like D. But it is 
definitely the cleanest, least-overwhelming method of writing 
native Win32 applications for somebody with no prior 
experience.


Then there's all the modern Microsoft stuff 
(WPF/XAML/WinRT/etc), but you pretty much have to use either 
.NET or C++ for that.


I have a specific thing I want to create and I could do it in a 
console but it'd be very clunky to use, but at the moment I 
need to learn the basic stuff for this. I'd like to use D as 
I've grown quite fond of it after my earlier attempts at first 
Perl, then Python, C++ and now D for the past year and a half. 
For some reason D feels the most... homey and comfortable of 
the languages I've tried.


There is a D GUI library called DlangUI at 
https://github.com/buggins/dlangui. The README file show some 
basic examples on how to use it. More demo apps are in the 
"examples" folder. Looking through those examples can really 
help. It works on windows and will work on Mac and Linux too. I 
use it on Linux and its quite impressive.


Some people here have used it to develop commercial softwares. 
I'm in a process of learning and creating a much nicer theme for 
it. Not much progress for now.


Decimal handling for currency (precision)

2017-11-23 Thread aberba via Digitalmars-d-learn
Some suggest working with the lowest currency denomination to 
avoid decimal precision handling and only convert to the highest 
denominations (decimal) when displaying. I've also seen some use 
decimal value handling libraries.


I'm thinking lowest denominations will result in extremely large 
values that D's type system cannot store (if such large values 
makes sense or can happen with money in real life).


What will be your advise on the type to use by default, the 
currency denominations (100p instead of 1.0 dollars), and cost of 
computation.


Re: Day of week from date

2017-09-29 Thread aberba via Digitalmars-d-learn
On Friday, 29 September 2017 at 03:42:18 UTC, Jonathan M Davis 
wrote:
On Friday, September 29, 2017 04:32:44 rikki cattermole via 
Digitalmars-d- learn wrote:

On 29/09/2017 4:25 AM, Joel wrote:
> With a given date, I want to know what day it is (like 
> Sunday, Monday,

> etc).
>
> I had a look up on std.datetime, and core.time, but they 
> don't seem to have a function for it.


https://dlang.org/phobos/std_datetime_date.html#.DateTime.dayOfWeek


Date and SysTime also have that function. So, whether you're 
creating one of those types manually - e.g. Date(2012, 7, 19) - 
or getting it from the system clock - e.g. Clock.currTime() - 
dayOfWeek will give you the day of the week for that particular 
object. TimeOfDay is the only time point type in std.datetime 
that does not have dayOfWeek, but that's because it makes no 
sense given that it simply represents a time of day.


- Jonathan M Davis


The documentation of std.datetime is very confusing at first. 
Monotime, Clock, DateTime, SysTime (deprecated?) ... can confuse 
you even though their names seems obvious when you're used to 
And then there's secs, mins, etc and those undocumented ones.




How and what do you use for server to server (secure, fast) communication?

2017-09-12 Thread aberba via Digitalmars-d-learn

I'm planning to use in a stateless microservices setup.


Re: Web servers in D

2017-09-12 Thread aberba via Digitalmars-d-learn

On Friday, 25 August 2017 at 05:25:09 UTC, Hasen Judy wrote:
What libraries are people using to run webservers other than 
vibe.d?


Don't get me wrong I like the async-io aspect of vibe.d but I 
don't like the weird template language and the fact that it 
caters to mongo crowd.


I think for D to a have good web story it needs to appeal to 
serious backend developers, not hipsters who go after fads 
(mongodb is a fad, jade/haml is a fad).


I probably need to combine several libraries, but the features 
I'm looking for are:


- Spawn an HTTP server listening on a port, and routing 
requests to functions/delegates, without hiding the details of 
the http request/response objects (headers, cookies, etc).


- Support for websockets

- Runs delegates in fibers/coroutines

- Basic database connectivity (No "orm" needed; just raw sql).

- When iterating the result set of a sql query, has the ability 
to automatically map each row against a struct, and throw if 
the structure does not match.


- More generally, map any arbitrary object (such as json) to a 
struct. Something like Zewo/Reflection package for swift[0].


[0]: https://github.com/Zewo/Reflection

I feel like Vibe.d satisfies my first 3 requirements, but for 
the rest I will probably have to look for something else.


In 2017, backend developers are more likely to write 
microservices which expose rest/graphQL APIs and put them in 
dockers containers Unless you're a full stack developer, 
you'll not be using jade/diet (at least not enough to be tempted 
to use something else).


Its still sucks there's no object storage api for D. Are you guys 
still building monolithic web servers?


Re: How to build GUI-based applications in D ?

2017-08-05 Thread aberba via Digitalmars-d-learn

On Thursday, 3 August 2017 at 10:02:19 UTC, ashit wrote:

On Tuesday, 1 August 2017 at 16:12:45 UTC, Dukc wrote:

On Tuesday, 1 August 2017 at 15:18:12 UTC, ashit wrote:
i couldn't set control's width and height (Button widget) 
shows error. maybe it works a different way.


1. Try layoutHeight/width. Remember to set it for the main 
widget too, not just the children of it.


2. DlangUI is not intended to define sizes in pixels as a 
standard practice. Instead, use layouts and layout sizes. This 
is intended to courage you to make your program 
resolution-agnostic.


But I'm a beginner at this topic too. Take these with a grain 
of salt


thank you Dukc

it worked, i should adapt with this different naming style. (as 
comparing to C#)

[yesterday]
but today, when i went to create another project, it failed.
i get this message:

D:\ashit\documents\D\simpled>dub init simpled dlangui
Couldn't find package: dlangui.

it works without the "dlangui" option, but then when i execute 
run command:


D:\ashit\documents\D\simpled>dub run
Performing "debug" build using dmd for x86.
simpled ~master: building configuration "application"...
source\app.d(2,8): Error: module dlangui is in file 'dlangui.d' 
which cannot be

read
import path[0] = source
import path[1] = C:\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\dmd2\windows\bin\..\..\src\druntime\import
dmd failed with exit code 1.

this is the path i have extracted the dlangui files:

D:\ashit\software\D Compiler\DlangUI\dlangui-master

how to define dlangui for DUB?


The DlangUI docs has you covered with everything you need to set 
it up both on the github README file or the github wiki.


Its just:

dub init PROJECT_NAME dlangui


This will create project and add dlangui as dependency. Creating 
a project requires Internet connection to download the dlangui 
package. You may also add dlangui as a dependency in the 
project's dub.json file.


Re: Auto-decoding

2017-07-15 Thread aberba via Digitalmars-d-learn

On Saturday, 15 July 2017 at 05:54:32 UTC, ag0aep6g wrote:

On 07/15/2017 06:21 AM, bauss wrote:

[...]


1) Drop two elements from "Bär". With auto-decoding you get 
"r", which is nice. Without auto-decoding you get [0xA4, 'r'] 
where 0xA4 is the second half of the encoding of 'ä'. You have 
to know your Unicode to understand what is going on there.


[...]


So what is the current plan? :)


Re: Application settings

2017-07-07 Thread aberba via Digitalmars-d-learn

On Friday, 7 July 2017 at 19:40:35 UTC, FoxyBrown wrote:
What's the "best" way to do this? I want something I can simply 
load at startup in a convenient and easy way then save when 
necessary(possibly be efficient at it, but probably doesn't 
matter).


Simply json an array and save and load it, or is there a better 
way?


Ideally, I'd like to store the settings as part of the binary 
to keep everything together but that poses a few issues I think.


Setting are not kept in binary (usually). Normally the installer 
would take care of creating a folder somewhere with a 
JSON/XML/SQlite file which stores settings.


Re: Creating and loading D plugins in D app

2017-06-03 Thread aberba via Digitalmars-d-learn

On Friday, 2 June 2017 at 16:36:34 UTC, H. S. Teoh wrote:
On Fri, Jun 02, 2017 at 12:19:48PM +, Adam D. Ruppe via 
Digitalmars-d-learn wrote:

On Friday, 2 June 2017 at 11:09:05 UTC, aberba wrote:
> 1. Get shared libs to work in D (the best approach for all D 
> code)


I have done very little with this myself but other people have 
so it is doable.

[...]

This is not directly related to the OP's question, but recently 
I wrote a program that, given a user-specified string, 
transforms it into D code using a code template, invokes dmd to 
compile it into a shared object, loads the shared object using 
dlopen(), and looks up the generated function with dlsym() to 
obtain a function pointer that can be used for calling the 
function. The shared object is unloaded after it's done.


Will be of much use to me to see the brief instructions for this. 
I saw the C style on Wikipedia.


Seems the functions loaded needs to be casted from void* to a 
type... before calling. Didn't quite understand that part.




So it's definitely doable, in the sense that I've successfully 
generated D code, compiled it into a shared library, loaded it 
into the running executable, and can call the code.  Of course, 
in my case, the code template is relatively simple so I don't 
have to worry about things like module ctors, shared data, 
non-TLS globals, or GC use.  If you're planning to support 
those features, you might need to do a bit more work after 
calling dlopen(). At the very least you'd have to use dlsym() 
to look up module ctor symbols and run them before calling any 
other functions in the shared object, and you may have to 
initialize druntime in the shared object too, if it's 
statically linked.


That seem like D with its features will be lot of work if I'm 
using loaded code that way.


How about exposing standard interface/apis for loaded object's 
code to query info about the main app at runtime, similar to COM 
(if that's how if even works)


I'm not sure what happens if it's dynamically linked, or if it 
uses its own copy of the GC.



Does D work different from C in that regard?

In any case, this is all possible, it just takes someone to dig 
into the details and write the code to make it all work.  Then 
publish it on github or dub, and the rest of us can reap the 
benefits too. ;-)



T





Re: Creating and loading D plugins in D app

2017-06-03 Thread aberba via Digitalmars-d-learn

On Friday, 2 June 2017 at 16:36:34 UTC, H. S. Teoh wrote:
On Fri, Jun 02, 2017 at 12:19:48PM +, Adam D. Ruppe via 
Digitalmars-d-learn wrote:

[...]

[...]

This is not directly related to the OP's question, but recently 
I wrote a program that, given a user-specified string, 
transforms it into D code using a code template, invokes dmd to 
compile it into a shared object, loads the shared object using 
dlopen(), and looks up the generated function with dlsym() to 
obtain a function pointer that can be used for calling the 
function. The shared object is unloaded after it's done.


[...]

Blog on it?


Re: Creating and loading D plugins in D app

2017-06-02 Thread aberba via Digitalmars-d-learn

On Thursday, 1 June 2017 at 23:24:13 UTC, aberba wrote:
Want to create and load plugins written in D into a D app at 
run-time, the kind that can make api calls or extended main app 
with other functionality.


I'm currently interested in it for a vibe.d app. How does these 
stuff work?


Plugin system c++ 
http://blog.nuclex-games.com/tutorials/cxx/plugin-architecture/


Re: Creating and loading D plugins in D app

2017-06-02 Thread aberba via Digitalmars-d-learn

On Friday, 2 June 2017 at 12:19:48 UTC, Adam D. Ruppe wrote:

On Friday, 2 June 2017 at 11:09:05 UTC, aberba wrote:
1. Get shared libs to work in D (the best approach for all D 
code)


I have done very little with this myself but other people have 
so it is doable.


1. some kind of embeddable interpreter for a scripting 
language like (a mini js engine) which exposes callable native 
D APIs at runtime


My script.d does this kind of thing
http://dpldocs.info/experimental-docs/arsd.script.html#examples

it is slow though.


Performance doesn't matter now.

Can source of script be reloaded at runtime?

Do I have to wrap external APIs in the "global" object passed as 
argument to "interpreter()"


I'm trying to implement a plugin system for a vibe.d server where 
plugins can be installed to provide additional http routes: 
extending server functionality.





Re: Creating and loading D plugins in D app

2017-06-02 Thread aberba via Digitalmars-d-learn

On Friday, 2 June 2017 at 02:05:23 UTC, Stefan Koch wrote:

On Thursday, 1 June 2017 at 23:24:13 UTC, aberba wrote:
Want to create and load plugins written in D into a D app at 
run-time, the kind that can make api calls or extended main 
app with other functionality.


I'm currently interested in it for a vibe.d app. How does 
these stuff work?


It works using shared libraries.


I just read it on Wikipedia. An alternative is to use a 
scripting/interpreted language. Working with such approach feels 
unnatural in D (considering pyd, lua-d).



A more sustanable approach would be:

1. Get shared libs to work in D (the best approach for all D code)

1. some kind of embeddable interpreter for a scripting language 
like (a mini js engine) which exposes callable native D APIs at 
runtime


None of which is within my current ability.


Re: Creating and loading D plugins in D app

2017-06-02 Thread aberba via Digitalmars-d-learn

On Friday, 2 June 2017 at 02:05:23 UTC, Stefan Koch wrote:

On Thursday, 1 June 2017 at 23:24:13 UTC, aberba wrote:
Want to create and load plugins written in D into a D app at 
run-time, the kind that can make api calls or extended main 
app with other functionality.


I'm currently interested in it for a vibe.d app. How does 
these stuff work?


It works using shared libraries.


Oops


Creating and loading D plugins in D app

2017-06-01 Thread aberba via Digitalmars-d-learn
Want to create and load plugins written in D into a D app at 
run-time, the kind that can make api calls or extended main app 
with other functionality.


I'm currently interested in it for a vibe.d app. How does these 
stuff work?


Re: Code improvement for DNA reverse complement?

2017-05-25 Thread aberba via Digitalmars-d-learn

On Friday, 19 May 2017 at 07:46:13 UTC, Stefan Koch wrote:

On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote:
I am solving this problem http://rosalind.info/problems/revc/ 
as an exercise to learn D. This is my solution:


https://dpaste.dzfl.pl/8aa667f962b7

Is there some D tricks I can use to make the 
`reverseComplement` function more concise and speedy? Any 
other comments for improvement of the whole solution are also 
much appreciated.


I think doing a switch or even a if-else chain would be faster 
then using an AA.


As part of your work on newCTFE, you are in a position to write a 
book titled "Fast D", about code that compiles, execute fast and 
efficiently.


Re: Is there websocket client implementation for D

2017-05-21 Thread aberba via Digitalmars-d-learn

On Wednesday, 25 March 2015 at 15:46:31 UTC, Adam D. Ruppe wrote:

On Wednesday, 25 March 2015 at 07:12:56 UTC, thedeemon wrote:
It's for server side, but probably contains stuff you need for 
client too.


Yeah, I've been meaning to write a client for a while but 
haven't gotten around to it yet. What you do is make a HTTP 
request with a particular header, and if the server likes it, 
you're OK and can send messages. If not, the failure should be 
gracefully reported.


Could probably write it up in a couple hours if I had a 
couple hours :(


How about now?


WebSocket lib

2017-05-21 Thread aberba via Digitalmars-d-learn
Which one would you recommended for working with browser socket 
client and D-based client (abstracted aoi)?


  1   2   >