Re: SHA256 Signature

2024-06-18 Thread Erdem via Digitalmars-d-learn

On Tuesday, 18 June 2024 at 06:49:24 UTC, Vahid wrote:


How can I create a SHA256 signature hash in D?


Does this do what you want?


```d
import std.digest.md;
import std.digest.sha;
import std.stdio;

void main()
{
auto key = makeDigest!SHA256();
key.put(cast(ubyte[])"çorba");
auto result = key.finish();
writeln(result.toHexString());
}
```



Re: Why is the following failing?

2024-01-25 Thread Erdem via Digitalmars-d-learn

On Thursday, 25 January 2024 at 16:07:44 UTC, Stefan Koch wrote:

On Thursday, 25 January 2024 at 15:39:08 UTC, ryuukk_ wrote:

```D
void main()
{
char[32] id = 0;
id = "hello";
}

```

this works fine, and that is what i expect for the example 
above..


Raise a bug, I'll fix it.


buna benzer bir hata https://www.oyunlaroyna.org/ sitesinde vardı 
oyun sitesi gerçi ama kaynaklarından sorunu çöze bildim tam 
olarak nerede kullanmak istediğinizi iletirseniz yardmıcı olurum


Re: Using .require for struct types

2022-09-13 Thread Erdem via Digitalmars-d-learn

On Sunday, 11 September 2022 at 21:01:27 UTC, Salih Dincer wrote:
On Saturday, 10 September 2022 at 16:33:03 UTC, Erdem Demir 
wrote:
I wish I could use ref DListOfA returnVal =  but we can't 
in D.


Can you please suggest alternatives?


I think you should try advanced update. Your flexibility and 
what you can do are limited by your dreams. A couple delicious 
code:


```d
import object, std.container;

struct A
{
double val;
bool isBig;
}

void main()
{
    alias  DListOfA = DList!A;
    DListOfA returnVal;
    //DListOfA[string] temp;/*
    DListOfA[string] temp = [
        "a": DListOfA( A(0) )
    ];//*/
    
    auto a = A(6, true); // replacement element
    temp.update("a", {
        return DListOfA( A(0) ); // not updated: unsucceeded 
but initialized

    }, (ref DListOfA v) {
        v = DListOfA( a ); // existing v has been replaced
        returnVal = v;
assert(returnVal.front == a);
    });
    assert(is(typeof(temp["a"]) == DList!A));
}
```
SDB@79


I really like the possibilities of update as well but the 
overhead is too much especially in this example. I am sorry to 
say I found old "in" usage less complicated than that even I 
think "in" is complicated. I liked the Steven's solution all this 
code can be done via 2 lines only.





Re: Using .require for struct types

2022-09-13 Thread Erdem via Digitalmars-d-learn
On Saturday, 10 September 2022 at 18:39:55 UTC, Steven 
Schveighoffer wrote:

On 9/10/22 12:33 PM, Erdem Demir wrote:


Can you please suggest alternatives?



Use a pointer.

```d
DListOfA *returnVal = (...);
returnVal.insert(a);
```

-Steve


Actually that could be answer I am seeking for I will try it.


Re: Using .require for struct types

2022-09-13 Thread Erdem via Digitalmars-d-learn

On Saturday, 10 September 2022 at 18:38:40 UTC, Ali Çehreli wrote:

On 9/10/22 09:33, Erdem Demir wrote:

>  DListOfA returnVal = temp.require("a",
DListOfA());--> I wish I
> could use ref DListOfA here

But keeping a reference to a temporary would not work because 
the life of that temporary ends by the end of that expression 
(practically, at the semicolon).


An option is to allocate the object dynamically with new (and 
store DListOfA* in the associative array). Then the GC would 
keep it alive as long its pointer was in the associative arrray.


But a better option is to just forget about it because D 
already takes care of rvalues by blitting (bit-level copying) 
them by default. Everything just works... :) It is not 
expensive either. For example, your struct is very cheap to 
copy.


But I am probably missing the reason why you want a ref there. 
Perhaps there are even better options.


Ali


In the code sample I posted I need returnVal.insert(a); have an 
effect on DListOfA[string] temp; but if returnVal is a rvalue 
copy I can't accomplish this right?


I see your point about ref would have been assign to a temp val, 
thanks for pointing out.





Why libmir has to add its own algorithm functions

2020-05-01 Thread Erdem via Digitalmars-d-learn

As can be seen in the link below :

http://mir-algorithm.libmir.org/mir_algorithm_iteration.html

Libmir provides almost the same function as std. Why is benefit 
of doing that? Wouldn't it be better to not duplicate std stuff?


Erdem


Cross product in lib mir or lubeck

2020-05-01 Thread Erdem via Digitalmars-d-learn

Hi,

I am looking for cross product function in libmir or lubeck. But 
I couldn't find it.

Does anyone know if it exists or not?

Erdem


Profiling the memory in D

2019-12-04 Thread Erdem via Digitalmars-d-learn
I am used to have cool tools like valgrid massif to visualize the 
memory usage from C++ but in D it seems I am blind folded looking 
for the problem.


Until now I tried:

--vgc option which show million things which makes it not useful
--build=profile-gc
which seems to slow down my program like *200 times and I have 
some operation depending on time which makes creating the real 
case of the application impossible. The observation itself effect 
the experiment very badly.


Since this options are not useful for me, I tried to put debug 
logs in critical places to estimate where I am losing memory. I 
couldn't find a D native call to get the memory usage of the 
program. I had to call a shell command which also slows down the 
app. This slow down causes me to not be able to put this debug 
log too many places or in critical loops.


I manage to narrow it down a bit. Than I wanted to check the 
object instances to find out which objects are getting bigger. I 
tried
GC.sizeOf() which always prints 0. GC.sizeOf also does not 
works with associative arrays , I don't see any usefull case than 
GC.sizeOf(array.ptr).


That is the background of my questions and my questions are:

Is there a better way to visualize the memory in D something like 
valgrid massif?


profile-gc literally makes to program not do anything due to slow 
down is there any way to profile-gc in a faster fashion?


Is there a native function which will return the memory usage of 
my program?


Is there a function to return sizes of AAs and even class 
instances ?


Erdemdem





Libharu D binding harud unicode support

2017-03-01 Thread Erdem via Digitalmars-d-learn
How should one use libharu d binding in unicode mode. Consider 
this basic example.


import std.stdio;

import harud;
import harud.c;

void main()
{
   void  errorCallback(uint error_number, uint detail_number)
   {
  writefln("err %x, %s, (num %x)"
, error_number
, getErrorDescription(error_number),
detail_number);
   }

   Doc pdf = new Doc();   ///  New pdf document
   Font helvetica = pdf.getFont("Helvetica");
   writeln("build font");

   Page page = pdf.addPage(); /// Add a new page to the document

   writeln("page width:", page.width);

   auto status = page.setFontAndSize(helvetica, 60);   /// Set 
the current font and size for the page

   writeln("set font width:", 60, " status", status);

   status = page.beginText(); /// Begin text mode
   writeln("begin ", status);

   status = page.showText("üçÇÜÖöĞğIı"); /// Print text to the 
page

   writeln("show ", status);

   page.endText(); /// End text mode

   pdf.saveToFile("./hello.pdf"); /// Write to disk
}

As you'd see I'd like to be able to write some Turkish characters 
to pdf file using libharu D binding.(a.k.a. harud)


Re: Gtkd how to filter TreeView according to user input

2017-01-17 Thread Erdem via Digitalmars-d-learn

On Tuesday, 17 January 2017 at 19:07:21 UTC, Ali Çehreli wrote:

On 01/17/2017 01:25 AM, Erdem wrote:

> void main(string[] args)
> {
> Main.init(args);
> new MyWindow();
> Main.run();
> }

I have no experience with Gtkd but the code inside main looks 
fundamentally wrong. One would expect you to do something with 
the MyWindow object:


auto w = new MyWindow();

And then use 'w' but I don't know how.

Ali


Thanks. The problem is already solved. You may look at this 
thread:


http://ddili.org/forum/post/12453

Ben D diline biraz önce göndermiştim :)

Erdem




Gtkd how to filter TreeView according to user input

2017-01-17 Thread Erdem via Digitalmars-d-learn
I'd like to filter Treeview data according to user input. How 
should I do that?


When I run this program it gives segmentation fault error.

import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.Entry;
import gtk.EditableIF;
import gtk.TreeModelFilter;
import gtk.TreeView;
import gtk.HBox;
import gtk.VBox;
import gtk.Label;
import gtk.ListStore;
import gtk.TreeViewColumn;
import gtk.CellRendererText;
import gtk.TreeModel;
import gtk.TreeIter;

import std.conv;
import std.stdio;

class MyWindow: MainWindow
{
Box mainBox;
Entry filterEntry;
TreeModelFilter filter;
TreeIter iter;

this()
{
super("TreeView Example");
setSizeRequest(500, 200);
filterEntry = new Entry();
auto filterLabel= new Label("Artist search");
auto tree = new TreeView();
auto box = new VBox(false, 0);

auto dataModel = new ListStore([GType.STRING, 
GType.STRING]);


auto artistColumn = new TreeViewColumn("Artist", new 
CellRendererText(), "text", 0);

tree.appendColumn(artistColumn);
auto songColumn = new TreeViewColumn("Song title", new 
CellRendererText(), "text", 1);

tree.appendColumn(songColumn);

iter = dataModel.createIter();
dataModel.setValue(iter, 0, "This is a test");
dataModel.setValue(iter, 1, "Sample song");

iter = dataModel.createIter();
dataModel.setValue(iter, 0, "This is a test");
dataModel.setValue(iter, 1, "Another song");

iter = dataModel.createIter();
dataModel.setValue(iter, 0, "Another artist");
dataModel.setValue(iter, 1, "Test song");

filter = new TreeModelFilter(dataModel, null);
filter.setVisibleFunc(cast(GtkTreeModelFilterVisibleFunc) 
& filterTree, null, null);


tree.setModel(filter);

auto mainBox = new HBox(false, 0);
mainBox.packStart(filterLabel, false, false, 5);
mainBox.packStart(filterEntry, true, true, 5);
box.packStart(mainBox, false, false, 5);
box.packStart(tree, true, true, 5);

add(box);

showAll();
}

bool filterTree(GtkTreeModelFilter gtkModel, GtkTreeIter 
gtkIter)

{
auto model1 = new TreeModelFilter(, false);
auto it1 = new TreeIter(, false);
string artistName = to!string(model1.getValue(it1, 0));

return true;
}
void onFilterEntryTextChanged(EditableIF filterEntry)
{
filter.refilter();
}

// void onFilterEntryTextChanged(ParamSpec param, ObjectG 
object)

// {
// filter.refilter();
// }
}

void main(string[] args)
{
Main.init(args);
new MyWindow();
Main.run();
}


Re: Gtkd how to add double value to liststore

2017-01-14 Thread Erdem via Digitalmars-d-learn

On Sunday, 15 January 2017 at 01:36:44 UTC, Ali Çehreli wrote:

It looks like ListStore is a collection of 'Value's. Does the 
following work?


setValue(iterator, 1, new Value(price));


Yes it works.

Ali bey teşekkürler! :)



Gtkd how to add double value to liststore

2017-01-14 Thread Erdem via Digitalmars-d-learn
I would like to pass some double value to ListStore's constructor 
but it doesn't allows me to do.


import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.ListStore;
import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.TreeIter;
import gtk.CellRendererText;


class MyWindow: MainWindow
{
Box mainBox;

this()
{
super("Tree view exercise");
setBorderWidth(10);
mainBox = new Box(Orientation.HORIZONTAL, 0);
add(mainBox);


showAll();
}
}

class InfoModel: ListStore /* model */
{
this()
{
super([GType.STRING, GType.DOUBLE]);

}

void addGoods(string name, double price)
{
TreeIter iterator = createIter();
setValue(iterator, 0, name);
setValue(iterator, 1, price);
}
}

class DisplayModel: TreeView /* view */
{
TreeViewColumn articleColumn;
TreeViewColumn priceColumn;

this (ListStore model)
{
articleColumn = new TreeViewColumn("Article", new 
CellRendererText(), "text", 0);


}

}

void main(string[] args)
{
Main.init(args);
new MyWindow();
Main.run();
}

When I try to compile this program it gives this error message:

Error: none of the overloads of 'setValue' are callable using 
argument types (TreeIter, int, double), candidates are:


import/gtk/ListStore.d(273):
gtk.ListStore.ListStore.setValue(TreeIter iter, int column, 
string value)
import/gtk/ListStore.d(281):
gtk.ListStore.ListStore.setValue(TreeIter iter, int column, int 
value)
import/gtk/ListStore.d(569):
gtk.ListStore.ListStore.setValue(TreeIter iter, int column, Value 
value)


Also is it possible to round this double to 2 decimal places when 
presenting data with GtkTreeView.




Re: arsd.dom appenChild method gives assertion message

2016-12-12 Thread Erdem via Digitalmars-d-learn

On Sunday, 11 December 2016 at 22:11:51 UTC, Adam D. Ruppe wrote:

On Sunday, 11 December 2016 at 17:52:29 UTC, Erdem wrote:

[...]


Try something like:

content.appendChild(firstElements[0].removeFromTree());


Thanks this method also works.

   foreach (element; firstElements)
   {
   element.removeFromTree();
   content.appendChild(element);
   }




Re: arsd.dom appenChild method gives assertion message

2016-12-11 Thread Erdem via Digitalmars-d-learn

Ok this seems to work as expected.

import arsd.dom;
import std.stdio;

void main()
{
   auto document = new Document();

   document.parseGarbage(`
 
 Test Document1
 
 
 This is the first paragraph of our href="test.html">test document.
 This second paragraph also has a href="test2.html">link.

 Old text
 
 `);

   auto document2 =  new Document();

   document2.parseGarbage(`
 
 Test Document
 
 
 
 
 
 
 Old text
 
 `);

   Element content = 
document2.getElementsBySelector(`div[id="content"]`)[0];


   writeln(content);
   writeln();

   Element[] firstElements = 
document.getElementsBySelector("body")[0].children;


   foreach (element; firstElements)
   {
   element.parentNode = null;
   content.appendChild(element);
   }

   writeln(document2.toString());
}


arsd.dom appenChild method gives assertion message

2016-12-11 Thread Erdem via Digitalmars-d-learn
I would like to add first documents content inside a div element 
like this.


import arsd.dom;
import std.stdio;

void main()
{

   auto document = new Document();

   document.parseGarbage(`
 
 Test Document1
 
 
 This is the first paragraph of our href="test.html">test document.
 This second paragraph also has a href="test2.html">link.

 Old text
 
 `);

   auto document2 =  new Document();

   document2.parseGarbage(`
 
 Test Document
 
 
 
 
 
 
 Old text
 
 `);

   Element content = 
document2.getElementsBySelector(`div[id="content"]`)[0];


   writeln(content);

   Element[] firstElements = 
document.getElementsBySelector("body");

   writeln (firstElements);

   content.appendChild(firstElements[0]);
}

The program compiles fine. But when I try to execute it gives an 
assertion error like this.


??:? _d_assert_msg [0x80cc048]
??:? 
_D4arsd3dom7Element11appendChildMFC4arsd3dom7ElementZ9__requireMFZv [0x80a6f62]
??:? arsd.dom.Element 
arsd.dom.Element.appendChild(arsd.dom.Element) [0x80a6df1]

??:? _Dmain [0x809f73c]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x80cd792]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x80cd6dc]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x80cd74e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x80cd6dc]

??:? _d_run_main [0x80cd66e]
??:? main [0x809fc93]
??:? __libc_start_main [0x129532]

How should one use appendChild or similiar methods of arsd.dom 
library?




std.net.curl application throws an exception

2016-11-27 Thread Erdem via Digitalmars-d-learn

try to compile this program from std.net.curl

import std.net.curl, std.stdio;

void main()
{
auto range1 = byLineAsync("www.google.com");
auto range2 = byLineAsync("www.wikipedia.org");
foreach (line; byLineAsync("dlang.org"))
writeln(line);

foreach (line; range1) writeln(line);
foreach (line; range2) writeln(line);
}
I compile this program like this.

$ dmd internet.d -ofinternet
or

dmd -I/usr/include/dmd/phobos -L-l:libcurl.so.4.2.0 internet.d 
-ofinternet

The program compiles fine but it throws an exception.

std.concurrency.PriorityMessageException@std/concurrency.d(273): 
Priority message


 ??:? 
_D3std11concurrency10MessageBox160__T3getTDFS3std11concurrency3TidS3std3net4curl21__T11CurlMessageTAyaZ11CurlMessageZbTDFS3std11concurrency3TidS3std3net4curl19__T11CurlMessageTbZ11CurlMessageZbZ3getMFDFS3std11concurrency3TidS3std3net4curl21__T11CurlMessageTAyaZ11CurlMessageZbDFS3std11concurrency3TidS3std3net4curl19__T11CurlMessageTbZ11CurlMessageZbZ3ptyMFKS3std11concurrency36__T4ListTS3std11concurrency7MessageZ4ListZb [0x81d03f4]
??:? bool std.concurrency.MessageBox.get!(bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(immutable(char)[]).CurlMessage), bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(bool).CurlMessage)).get(bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(immutable(char)[]).CurlMessage), bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(bool).CurlMessage)) [0x81cfeed]
??:? void std.concurrency.receive!(bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(immutable(char)[]).CurlMessage), bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(bool).CurlMessage)).receive(bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(immutable(char)[]).CurlMessage), bool 
delegate(std.concurrency.Tid, 
std.net.curl.CurlMessage!(bool).CurlMessage)) [0x81cfd08]
??:? void 
std.net.curl.AsyncLineInputRange!(char).AsyncLineInputRange.__mixin5.tryEnsureUnits() [0x81ccb87]
??:? @property bool 
std.net.curl.AsyncLineInputRange!(char).AsyncLineInputRange.__mixin5.empty() [0x81cc7db]

??:? _Dmain [0x81b47b8]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x81d9292]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x81d91dc]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x81d924e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x81d91dc]

??:? _d_run_main [0x81d916e]
??:? main [0x81d3393]
??:? __libc_start_main [0x129532]

I use dmd v2.072.0