Re: Named parameter builder pattern for template parameters

2014-11-26 Thread Robik via Digitalmars-d

On Friday, 21 November 2014 at 13:39:43 UTC, monarch_dodra wrote:

I trust everyone here knows about the builder pattern
(http://en.wikipedia.org/wiki/Builder_pattern)? It can be very
useful when the number of (optional) arguments in a function
start to run rampant, and you know the user only wants to start
setting a subset of these.

D has phenomenal meta programming possibilities, and I see more
and more templates taking more and more parameters. So I thought
to myself, why not have a template builder pattern?

I was able to throw this together:
http://dpaste.dzfl.pl/366d1fc22c9c

Which allows things like:
alias MyContainerType = ContainerBuilder!int
//.setUseGC!??? //Don't care about GCm use default.
.setScan!false
.setUSomeOtherThing!true
.Type;

I think this is hugely neat. I'm posting here both to share, and
for peer review feedback.

I'm also wondering if there is prior literature about this, 
and

if it's something we'd want more of in Phobos?


If D would support getting parameter names(currently does not 
work for lambdas) of lambdas we could have:


   someConnect(host = test, port = 7999);

Just a random thought :)


D Mode for ACE editor

2014-01-23 Thread Robik

Hello everyone.

I am happy to announce that updated D Language mode for Ace 
editor has been merged and included in latest build.


For those who don't know, Ace is an open source code editor 
written in JavaScript and used by c9.io, koding.com and hopefully 
will be used on DPaste soon as well.


Both of above services cannot be yet used for full D development, 
C9 does not provide any D compiler[1] and Koding does not support 
D syntax highlighting, but I think we are on good way.


Live demo can be found at: http://ace.c9.io/kitchen-sink.html

Major improvements are:
 * Updated keyword list
 * Support for UDAs
 * Minimal ASM support
 * Delimited Strings

Cheers, Robik.


 [1] If I'm not mistaken, it should be possible to compile GCC 
there.


Re: Begining with D

2013-10-13 Thread Robik

On Saturday, 12 October 2013 at 21:27:18 UTC, 1100110 wrote:

On 10/10/2013 02:36 PM, Adam D. Ruppe wrote:
On Thursday, 10 October 2013 at 19:19:53 UTC, Ali Çehreli 
wrote:

import std.c.linux.termios;


worth noting that this is Linux only. doing it on Windows is a 
little

different.

Working with console/terminal input and output can get 
surprisingly

complex, and doing it cross-platform is easiest with a library.

Robik's consoleD is one:
https://github.com/robik/ConsoleD/blob/master/consoled.d

it focuses on enabling color and drawing mainly, and also has 
functions

to turn off the line buffering and getch().

If you use his library, you can do this:

import consoled;

void main() {
int a = getch(); // gets just one character
writecln(a); // prints back out what you got
}

and other nice things.


I had issues with getch() on ConsoleD...

If you too have issue, you can try 
github.com/D-Programming-Deimos/ncurses which has similar 
functions, but is also way more complex...


I guess its was on linux right? Probably because some last 
quickfixes i added wasn't propely (read never) tested on linux :P
Soon I'll try to finally start working on merging terminald and 
consoled somehow.


Re: Code from a Rosetta Code Task

2013-08-29 Thread Robik

On Thursday, 29 August 2013 at 18:57:58 UTC, Meta wrote:

uint fib(in uint n) pure nothrow {
immutable self = __traits(parent, {});
return (n  2) ? n : self(n - 1) + self(n - 2);
}

I came across this while browsing Rosetta Code. It's really 
cool how you can do recursion without anonymous functions (and 
this will actually not work if you make fib a delegate). 
However, I'm confused about the __traits(parent, {}) part, 
specifically , the {} passed to parent. Does {} just mean the 
outer scope?


{} in this case is just empty delegate function.


Re: String representation of enum value

2013-08-04 Thread Robik

On Sunday, 4 August 2013 at 13:57:20 UTC, Marek Janukowicz wrote:

Given following code:

enum ErrorCode {
  BAD_REQUEST,
  UNKNOWN
}

ErrorCode code;

is there any way to get string representation of code with 
regard to values

defined in enum? I mean - if code == 0, I'd like to get a string
BAD_REQUEST, if it's == 1, I'd like to get string a 
UNKNOWN. Of course
I'd like to use something more consise and elegant than a 
switch :)


I think std.conv.to!string is what are you looking for :)

http://dpaste.dzfl.pl/e1c38f8f


Re: Does D have a Queue and Stack container?

2013-01-13 Thread Robik

On Sunday, 13 January 2013 at 19:55:28 UTC, Damian wrote:
As per title, it would be awesome if someone could link me to 
these. I'm quite suprised that D does not already contain 
these.. are there any plans for them joining Phobos?


Here's one I am using: https://gist.github.com/4525926

You can use LinkedList as DeQueue.


Re: SQLite library on Windows

2012-12-27 Thread Robik

On Thursday, 27 December 2012 at 01:45:26 UTC, BLM768 wrote:
I've been trying various methods to get SQLite working in 
Windows using the etc.c.sqlite3 bindings, but I can't figure 
out how to get everything in a form that DMD likes. GCC doesn't 
seem to output anything that OPTLINK can use, and I can't use 
the standard DLL build without creating a .LIB file from it, 
which apparently isn't an easy task. I can't remember if I've 
tried compiling SQLite with DMC, but I'd rather avoid that 
option because it would require a custom Makefile. Maybe 
objcopy has an option that would help...


Has anyone managed to get the library working on Windows?



Download their windows binaries and use Digital Mars implib tool 
with /system switch.


Re: Mono-D v0.4.4 Template mixins, completion improvements

2012-12-01 Thread Robik

On Friday, 30 November 2012 at 17:33:27 UTC, alex wrote:

Hi everyone,

I've implemented one of the last missing things regarding code 
completion (except those huge remaining fields in the 
expression evaluation, so correct traitCTFE handling etc.) now.
Though I doubt that everything is interpreted correctly I wrote 
a bunch of unit tests that passed successfully - imho another 
step in the right direction.


Great news, thanks.

Now trying to begin with the code formatter.. but unlike 
installing new completion features this will take longer, I 
guess :)


http://mono-d.alexanderbothe.com
http://d-ide.sourceforge.net

https://github.com/aBothe/Mono-D/issues




Re: UDA + Pegged AST Hack

2012-11-28 Thread Robik

On Wednesday, 28 November 2012 at 21:40:35 UTC, Daniel N wrote:
Thanks to the wonderful UDA implementation in 2.061, I thought 
of a little hack, which may interest at least someone.


I'm using it for prototyping ctfe ast transformations together 
with: https://github.com/PhilippeSigaud/Pegged


Yes, it was possible to do similar stuff before and 
examples/dgrammar.d from Pegged is quite impressive, but not 
bug free.


This UDA-line-hack-way is actually significantly cleaner, 
because when using __LINE__ you are certain that there will be 
at least one [__LINE__] which is not inside a string or comment 
on the attributed line... this allows one to make a very 
limited grammar/parser which doesn't have to 
know/parse/understand the entire file.


I know my proof-of-concept doesn't handle multi-line, but it 
can be added, and doesn't matter for the sake of prototyping 
AST manipulations.


If anyone else have fun UDA hacks, considering that it's a new 
feature, please share.


import std.string;
import std.range;

struct magic
{
  [__LINE__] int var1;
  [__LINE__] int var2;
  [__LINE__] int var3;
}

enum dsrc = import(__FILE__).splitLines(KeepTerminator.yes);

string parse()
{
  string result = ;

  foreach(m; __traits(allMembers, magic))
result ~= dsrc.drop(__traits(getAttributes, mixin(magic. 
~ m))[0]-1).takeOne().front;


  // insert pegged parsing / transformations here.

  return result;
}

mixin(struct magic2\n{\n ~ parse() ~});


I made two, but not as cool as yours: 
http://dpaste.dzfl.pl/32536704 http://dpaste.dzfl.pl/15e4591b


Re: Abstract Database Interface

2012-10-28 Thread Robik

On Sunday, 28 October 2012 at 00:31:49 UTC, BLM768 wrote:
I've recently been working with Ruby's ActiveRecord as part of 
my job, and I realized that D was powerful enough to make a 
similar abstraction layer. I've been playing with the idea for 
a little while, and I've put up some code at 
https://github.com/blm768/adbi. It isn't nearly as 
comprehensive as ActiveRecord, but it captures the basic idea 
of representing database structures as objects/structs.


Using it is something like this:

module main;

import std.stdio;

import adbi.model;
import adbi.sqlite3.database;

struct Test {
mixin Model!test;

const(char)[] name;
double num;
mixin reference!(test2, test2, Test2);
}

struct Test2 {
mixin Model!test2;
int value;
}

int main(string[] args) {
auto db = new Sqlite3Database(test.db);
auto q = db.query(SELECT * FROM test;);

Test.updateSchema(db);
Test2.updateSchema(db);

auto range = ModelRange!Test(q);

foreach(value; range) {
writeln(value);
}

	auto q2 = db.query(SELECT * FROM test, test2 WHERE test2_id = 
test2.id);


auto r2 = ModelRange!(Join!(Test, Test2))(q2);

foreach(j; r2) {
writeln(j);
}

return 0;
}

This code prints out every entry in the test table, then 
prints the results of a join on the test and test2 tables. 
The calls to updateSchema() set up some static members of Test 
and Test2; after these calls, the library does not perform any 
operations with the column names, which should make retrieving 
a record noticeably faster than in a system like ActiveRecord. 
The downside is that these functions must be called every time 
the database schema changes in a way that affects column order, 
but that should happen very rarely, if ever, in a typical 
application.


The code is far from complete, but it's an interesting toy and 
might actually be useful for simple applications once some of 
the issues are ironed out.


I am working on similar project, named SQLd[1]. If you are 
interested, we can join forces and work togheder :)


IRC Nick: Robik
[1]: http://github.com/robik/SQLd



Re: [GtkD] Error 1: Previous Definition Different : __Dmain

2012-10-28 Thread Robik

On Sunday, 28 October 2012 at 18:15:14 UTC, Adrien Tétar wrote:

On Sunday, 28 October 2012 at 16:10:25 UTC, Mike Wey wrote:
Did you run the dgen executable from the src directory, 
otherwise it might be possible that some of the demos got 
compiled into the library.


Yea I did.

[IMG]http://www.abload.de/img/dgenrnk9j.png[/IMG]

I even tried to remove the 'demos' folder but the compiled lib 
is of the same size...


Maybe that happens because I use Eclipse + DDT?

Here is my sc.ini :

[Version]
version=7.51 Build 020

[Environment]
LIB=%@P%\..\lib;\dm\lib
DFLAGS=-I%@P%\..\..\src\phobos 
-I%@P%\..\..\src\druntime\import -I%@P%\..\..\src\gtkd -L 
C:\D\dmd2\windows\lib\GtkD.lib

LINKCMD=%@P%\link.exe



Try removing dgen.d from there :)


Re: [RFC] ColorD

2012-10-26 Thread Robik

On Friday, 26 October 2012 at 01:35:43 UTC, Adam D. Ruppe wrote:
On Thursday, 25 October 2012 at 22:27:52 UTC, Jens Mueller 
wrote:

5. setting the contents of the title bar

The title bar of what?


Here's how you do it on xterm:

writefln(\033]0;%s\007, title);



Yeah, the problem is it does not work in all terminals.



Re: [RFC] ColorD

2012-10-24 Thread Robik

On Tuesday, 23 October 2012 at 22:47:40 UTC, Walter Bright wrote:
On 10/22/2012 3:55 AM, Andrei Alexandrescu wrote: On 10/22/12 
9:47 AM, Jens Mueller wrote:

 This is probably interesting for Phobos. But I'm not the one
to make a
 decision. The core Phobos developers should decide.
 Hopefully somebody is reading this.

 Off the top of my head something that is specific for only
certain systems
 (Unixen in this case) is decidedly of less Phobos interest.
We could,
 nevertheless, put such functionality in system-specific
modules.

A module that only sets the console color is a little too light 
to be a phobos entry.


A more comprehensive module that included:

1. getting mouse input
2. getting size of the console
3. moving the cursor around
4. drawing boxes in the console window
5. setting the contents of the title bar
6. supporting cut/paste
7. getting no-echo raw input
8. setting the size of the cursor

would be a definite candidate. I.e. a module that can support 
building a text mode screen app (like a text editor).



Thanks for your suggestions. I will try to do what I can, but I 
think there may be some problems because of differences in 
terminals. Although some of them should not be the problem :)


Re: [RFC] ColorD

2012-10-22 Thread Robik

On Sunday, 21 October 2012 at 22:32:35 UTC, Walter Bright wrote:

On 10/21/2012 12:28 PM, Robik wrote:
 Simple example:

 import std.stdio, colord;
 void main()
 {
  setConsoleColors(Fg.red, Bg.blue);
  writeln(Red text on blue background.);
  resetConsoleColors(); // Bring back initial state
 }

Need a method to get the current state, and reset the current 
state. Otherwise, nested calls to the console functions will 
screw up the state.


I.e.:

auto save = getConsoleState();
setConsoleColors(Fg.red, Bg.blue);
writeln(Red text on blue background.);
setConsoleState(save); // Bring back initial state

Or better:

auto save = getConsoleState();
scope (exit) setConsoleState(save);
setConsoleColors(Fg.red, Bg.blue);
writeln(Red text on blue background.);


On Windows, setting color to initial sets console colors to ones 
that were set before launch of the program. On Posix it sets 
default (ANSI remove formatting).
I will try to check if it is possible to get current colors on 
Posix.


[RFC] ColorD

2012-10-21 Thread Robik

Hello,

I would like to introduce ColorD, small library that allows to 
simply manipulate console output colors, both on Windows and 
Posix operating systems. It also supports font styles such as 
underline and strikethrough(Posix feature only).



Simple example:

import std.stdio, colord;
void main()
{
setConsoleColors(Fg.red, Bg.blue);
writeln(Red text on blue background.);
resetConsoleColors(); // Bring back initial state
}


Feedback welcome.

GitHub: https://github.com/robik/ColorD

Regards.


Re: [RFC] ColorD

2012-10-21 Thread Robik
On Sunday, 21 October 2012 at 20:19:54 UTC, Peter Sommerfeld 
wrote:

Robik wrote:

I would like to introduce ColorD, small library that allows to 
simply manipulate console output colors, both on Windows and 
Posix operating systems.



GitHub: https://github.com/robik/ColorD


On windows I got an error:
Not a property EnumTypedef!color,fg.opDispatch
Same for bg.

void resetConsoleColors()
{
setConsoleColors(Fg.initial, Bg.initial); // here
}

Peter


What version are you using?


Re: [RFC] ColorD

2012-10-21 Thread Robik

On Sunday, 21 October 2012 at 20:39:31 UTC, bearophile wrote:

Robik:


GitHub: https://github.com/robik/ColorD


Maybe it'ìs better to call it ConsoleColorsD, or something. 
ColorD seems more fit for a (handy) library about color theory, 
color space conversions, etc.


Bye,
bearophile


Moved to https://github.com/robik/ConsoleD


Re: [RFC] ColorD

2012-10-21 Thread Robik

On Sunday, 21 October 2012 at 21:01:21 UTC, Jens Mueller wrote:

Interesting looks solid to me.
Some nit-picks:
* Coloring on Posix depends a ANSI terminal. Can you check that 
a terminal is ANSI compatible?


Sure, why not.

* There are some magic numbers in the code. These may be 
difficult to

  figure out for maintaining.


I will fix this.


* enum Color should maybe be same on all systems.
  This is a rather small issue. But I may transfer the Color to 
another
  system. So if it is possible there should only be one enum 
Color for

  all systems.


I think that this will only complicate the code.

* Call it terminal or similar. Because other terminal related 
stuff can

  be added and IMHO it's a better name.


It got renamed to ConsoleD.

I have written a similar library. Not finished. Let's join 
forces.

https://github.com/jkm/terminal

Johannes Pfau has written a progress bar. I will add this.

Jens


Sure, I'm interested in joining forces. Do you have IRC?




Re: [RFC] ColorD

2012-10-21 Thread Robik

On Sunday, 21 October 2012 at 21:25:14 UTC, Era Scarecrow wrote:

On Sunday, 21 October 2012 at 19:28:21 UTC, Robik wrote:
I would like to introduce ColorD, small library that allows to 
simply manipulate console output colors, both on Windows and 
Posix operating systems. It also supports font styles such as 
underline and strikethrough(Posix feature only).


 Does this rely on nCurses? (or similar)


No, everything is written from scratch. On Windows side it used 
WinAPI functions, on Posix, ANSI codes.


Re: Mono-D v0.4.1.5 Fixes

2012-10-14 Thread Robik

On Saturday, 13 October 2012 at 13:17:52 UTC, alex wrote:

Hi everyone,

Just released a new Mono-D version that features couple of 
bigger sort of fixes..


The download:
http://mono-d.alexanderbothe.com/repo/MonoDevelop.D_0.4.1.5_MD3.0.4.7.mpack

The changelog:
http://mono-d.alexanderbothe.com/?p=634

The blog:
http://mono-d.alexanderbothe.com

The issues:
https://github.com/aBothe/Mono-D/issues


Cheers,
Alex



Great work, thanks.



Re: Failed unittest

2012-08-20 Thread Robik

On Monday, 20 August 2012 at 09:51:10 UTC, monarch_dodra wrote:


I'm wondering if:
1) Would it be possible to compile as many unittests as 
possible, and simply omit the tests that static assert? This 
would create a unit test compilation failure, but not prevent 
the tests that *did* compile from moving on to the run-time 
testing.
2) Would it be possible to execute ALL unit tests, even after 
one fails?


Yes.

You can set assertHandler to your own function.

Something like:

import core.exception, std.stdio;

void handler(string file, ulong line, string msg)
{
if(msg == null) {
writefln(-- %s(%d), file, line);
} else {
writefln(-- %s(%d): %s, file, line, msg);
}
}

void main(){}

unittest
{
setAssertHandler(handler);
assert(1==2);
assert(1==3, 1 is not equal to 3);
}

More info can be found here: 
http://dlang.org/phobos/core_exception.html




Re: Just where has this language gone wrong?

2012-07-19 Thread Robik

On Thursday, 19 July 2012 at 14:21:47 UTC, Petr Janda wrote:

Hi,


Hi

I'm an occasional lurker on the D forums just to see where the 
language is going,but I'm a little puzzled. In another thread I 
found this code


auto r = [5, 3, 5, 6, 8].sort.uniq.map!(x = x.to!string);


Here's list what happens:

 1) Array gets sorted
 2) Duplicate elements gets removed (only unique stay)
 3) Then it get's maped by delegate. It converts numbers into 
strings.

`r` variable will be [3, 5, 6, 8]


What type is x?

Type of x is inferred.


What kind of operator is =

Syntatic sugar for delegates.


On another note, (copied from wikipedia)

foreach(item; set) {
  // do something to item
}


Item type is inferred from `set`, it's just syntactic sugar. Of 
course you can use `auto` but you don't have to.


Re: dlang.org live examples

2012-06-25 Thread Robik

On Monday, 25 June 2012 at 14:43:34 UTC, nazriel wrote:

Hi!

I am polishing up this stuff:
http://dlang.dzfl.pl/

It would allow to run examples from http://dlang.org directly 
in web-browser.
Something like http://dpaste.dzfl.pl, but integrated with dlang 
website itself.


I would like to ask you about your opinions and advises.

There are couple things I can't make my mind on.

First, should standard input and command line arguments be 
constant defined in hidden html fields, or should we allow user 
to pick their own?
It would allow for more freedom and experience but on 
other-hand it would bloat too much website. Whats your opinion?


I think, that we should allow user to specify arguments whenever 
it is possible and reasonable.



Another thing are examples itself. As you may noticed I 
modified some of em too give some experience in browser, for 
example, I've added writeln blocks in Power section.
What should we do with 'em? Examples to run properly requires 
main functions, and loads of examples doesn't have them. Should 
we adjust those examples or leave them alone? Another thing are 
examples that doesn't return or display anything.
Like assert(foo !is null); examples. Should we make them throw, 
add some writelns or leave them alone?


I would love to hear your opinion on those.


I would go with adjusting them, to make output cleaner. Idea to 
replace assert(...) with writeln() sounds good.



Best regards,
Damian 'nazriel' Ziemba



Overall, stuff you made is quite impressive, keep it going!

Regards, Robik.


Re: dpj for Windows

2012-06-17 Thread Robik

On Saturday, 16 June 2012 at 19:36:50 UTC, dnewbie wrote:

On Tuesday, 22 May 2012 at 07:28:04 UTC, Ary Manzana wrote:

On 5/22/12 8:55 AM, dnewbie wrote:

On Monday, 21 May 2012 at 12:08:33 UTC, Ary Manzana wrote:

On 5/20/12 10:37 PM, dnewbie wrote:


It started as a D project, then I've moved it to C.


o_O

Why?


Because the d version of the program has a lot of weird bugs 
and

I wasn't able to kill them.


Then why did you still write a D IDE if you couldn't even 
write it in D?


Did you report the bugs? Are they known? Did you try to fix 
them or to ask the community?


Hi. The dpj mini-ide is now written in D and the source code is 
available:

https://github.com/dnewbie/dpj
Sorry, there's no new feature.
Screenshot: http://postimage.org/image/6mtk293s7/


Looks promising


Re: ColorD

2012-05-28 Thread Robik

On Monday, 28 May 2012 at 13:08:27 UTC, Marco Leise wrote:

Am Sat, 26 May 2012 16:30:58 +0200
schrieb Robik szad...@gmail.com:

I would like to share with my new library written in D. As 
name may suggest (or not) it adds color to your console 
output, it works on both Linux and Windows platforms. I 
haven't seen any similar library for D language, so I decided 
to create this one.


Source and examples(included in Readme file) can be found on 
GitHub repo: https://github.com/robik/ColorD


Regards,
Robik.


Ah, this can be used to pimp the console output.
Give it the following additions to make it complete and useful:

* fg/bg colors are just two attributes, add e.g. bold, 
underline, italic

  (http://en.wikipedia.org/wiki/ANSI_escape_code)

* detect type of stdout; terminal or pipe/file
  (Posix: http://linux.die.net/man/3/isatty)

The latter is important to not accidentally write escape codes 
into a file if output is redirected. Some tools let you chose 
to output with or without colors, so it would be nice if you 
library could offer a isAnsiTerminal function, so the 
programmer can chose to output with or without colors. :)

This is a good idea!


Okay, I think I will have to set up VM and start working on it. 
Thanks for your suggestion by the way!


Re: ColorD

2012-05-28 Thread Robik

On Monday, 28 May 2012 at 17:21:25 UTC, 1100110 wrote:
On Mon, 28 May 2012 11:55:24 -0500, Damian Ziemba 
s...@dzfl.pl wrote:



On Monday, 28 May 2012 at 13:30:44 UTC, Robik wrote:

On Monday, 28 May 2012 at 13:08:27 UTC, Marco Leise wrote:

Am Sat, 26 May 2012 16:30:58 +0200
schrieb Robik szad...@gmail.com:

I would like to share with my new library written in D. As 
name may suggest (or not) it adds color to your console 
output, it works on both Linux and Windows platforms. I 
haven't seen any similar library for D language, so I 
decided to create this one.
Source and examples(included in Readme file) can be found 
on GitHub repo: https://github.com/robik/ColorD

Regards,
Robik.



+1


Nice!

Does it support checking if the terminal supports color?


Not yet. But I guess I will have to add it soon.

Regards,
Robik.



ColorD

2012-05-26 Thread Robik
I would like to share with my new library written in D. As name 
may suggest (or not) it adds color to your console output, it 
works on both Linux and Windows platforms. I haven't seen any 
similar library for D language, so I decided to create this one.


Source and examples(included in Readme file) can be found on 
GitHub repo: https://github.com/robik/ColorD


Regards,
Robik.


Re: StackOverflow Chat Room

2012-03-21 Thread Robik

On Sunday, 18 March 2012 at 23:13:47 UTC, James Miller wrote:

Hey guys,

I made a StackOverflow chat room. You don't have to use it or
anything, but at least it exists now.

Its called Dlang, http://chat.stackoverflow.com/rooms/9025/dlang

--
James Miller


Awesome. But it needs to be configured. What's your IRC name(need
to talk about it)?


Re: StackOverflow Chat Room

2012-03-21 Thread Robik

On Wednesday, 21 March 2012 at 14:49:18 UTC, Kapps wrote:
In my opinion, people should favour the IRC channel (#D on 
Freenode) over this. Plus, the IRC channel is fairly active 
already and doesn't force you to use StackOverflow / have 
reputation.


It is not much, only 2 up votes and protects from bots.


std.zlib uncompress issue

2012-03-04 Thread Robik

Hello.

Recently I was working with std.zlib and experienced error. After 
few hours I realized it was uncompress issue. I've made simple 
example that shows the issue:


import std.stdio,
   std.zlib,
   std.array,
   std.file,
   std.conv;

void main()
{
createFile();
loadFile();
}


void createFile()
{
auto file = new File(test.txt, wb);
scope(exit) file.close;
auto cpr = new Compress(9);
string str = abcdef;

for(int i = 0; i  500; i++)
{
file.write(cast(string)cpr.compress(str~to!string(i)));
}
file.write(cast(string)cpr.flush);
}

void loadFile()
{
auto file = new File(test.txt, rb);
scope(exit) file.close;

auto target = new File(test2.txt, wb);
scope(exit) target.close;

auto ucpr = new UnCompress();

// Making chunk size bigger than file size will (dirty)fix it.
foreach(chunk; file.byChunk(64))
{
target.write(cast(string)ucpr.uncompress(chunk));
}
target.write(cast(string)ucpr.flush);
}

The code creates file with compressed data, then tries to 
uncompress it. That's where the issue is. 
UnCompress.uncompress(src) works only if the src is complete. If 
I pass half of it, I get exception (data error). I don't know how 
to fix it except increasing buffer size to incredible high 
values(some files may be pretty big).


Re: [RFC] Ini parser

2012-02-17 Thread Robik

On Thursday, 16 February 2012 at 22:29:30 UTC, Manu wrote:
I wonder if there is a problem with a 'standard' ini parser, in 
that ini

files are not really very standard.
I have seen a lot of ini files with scope (also also use this 
in some of my

own apps), will I be able to parse these with your parser?

[section]
{
  key = value
  key2 = value

  [subsection]
  {
subkey = value
  }
}

?

I notice your interesting delimiters too, I've never seen 
anything like
that in an ini file before, where did you see that? What makes 
it standard?
I might like to use something like that if I had thought it was 
a normal

thing to use in an ini file...


Also, you can make it simplest/standard-est as possible by 
disabling those features. To do that you have to set for example 
'sectionInheritChar' to 0 to disable it. But to nest sections you 
have to use something like that:


[section]
key = value
key2 = value

[section.subsection]
subkey = value

Where dot in second section name is delimeter you've set up.


Re: [RFC] Ini parser

2012-02-17 Thread Robik

On Thursday, 16 February 2012 at 22:29:30 UTC, Manu wrote:
I wonder if there is a problem with a 'standard' ini parser, in 
that ini

files are not really very standard.
I have seen a lot of ini files with scope (also also use this 
in some of my

own apps), will I be able to parse these with your parser?

[section]
{
  key = value
  key2 = value

  [subsection]
  {
subkey = value
  }
}

?



I parser won't parse it. To have nested sections, it uses 
delimeter in section names to keep it compatible with standards. 
If some parser does not supports nesting it still will, but 
sections would look like [a.b] etc. This curly braces thing can 
break some parsers.


Re: [RFC] Ini parser

2012-02-17 Thread Robik

On Friday, 17 February 2012 at 07:27:52 UTC, Jacob Carlborg wrote:

On 2012-02-16 21:50, Robik wrote:

Greetings.

Recently, I've been working on INI parser in D. The main goals 
were to
keep code easy and well documented. Suggestions are really 
welcome(main

reason of this thread) because it needs polishing and stuff.

It provides simple interface for operating on parsed file, 
including
useful features like section inheriting and variable lookups. 
Here is

simple example taken from README with little modifications:
import std.stdio;
void main()
{
// Hard code the contents
string c = 
# defaults
[def]
name1:value1
name2:value2

; override defaults


Thanks, it's awesome idea. Added.

[foo : def]
name1=Name1 from foo. Lookup for def.name2: %name2%;

// create parser instance
auto iniParser = new IniParser();

// Set ini structure details; can be ommited
iniParser.commentChars = [';', '#'];
iniParser.delimChars = ['=', ':'];


// parse
auto ini = iniParser.parse(c);

// write foo.name1 value
writeln(ini.getSection(foo)[name1].value);
}


Why the need for .value? It would guess because opIndex 
returns IniKey which both contains the key and the value. I 
would sugest you add a alias this pointing to value. 
Something like this.


struct IniKey
{
string name;
string value;

alias value this;
}





[RFC] Ini parser

2012-02-16 Thread Robik

Greetings.

Recently, I've been working on INI parser in D. The main goals 
were to keep code easy and well documented. Suggestions are 
really welcome(main reason of this thread) because it needs 
polishing and stuff.


It provides simple interface for operating on parsed file, 
including useful features like section inheriting and variable 
lookups. Here is simple example taken from README with little 
modifications:

import std.stdio;
   void main()
   {
// Hard code the contents
string c = 
   # defaults
   [def]
   name1:value1
   name2:value2

   ; override defaults
   [foo : def]
   name1=Name1 from foo. Lookup for def.name2: %name2%;

   // create parser instance
   auto iniParser = new IniParser();

   // Set ini structure details; can be ommited
   iniParser.commentChars = [';', '#'];
   iniParser.delimChars = ['=', ':'];


   // parse
   auto ini = iniParser.parse(c);

   // write foo.name1 value
   writeln(ini.getSection(foo)[name1].value);
   }

You can also define parsing details, like commentCharacters* and 
others. As for the keys, structure is used rather than 
associative arrays. There's also bug** that does not allow 
chaining with opCall which I hope will be fixed :).


IniStructure (result of parsing) overloads some basic operators 
allowing you to looping through it and accessing data with 
opIndex and opCall.


Feel free to share suggestions, changes, help me make it better 
:).


Repo: https://github.com/robik/DIni
* https://github.com/robik/DIni/blob/master/src/dini.d#L400
** http://d.puremagic.com/issues/show_bug.cgi?id=7210


New unofficial phobosDoc location

2011-11-27 Thread Robik
After downtime of dav1d.de (where demo was hosted), I've moved it to GitHub 
pages, new location is at:

 http://robik.github.com/phobos/ (floating version)
 http://robik.github.com/static/ (static version)


New unofficial phobosDoc location

2011-11-27 Thread Robik
After downtime of dav1d.de (where demo was hosted), I've moved it to GitHub 
pages, new location is at:

 http://robik.github.com/phobos/ (floating version)
 http://robik.github.com/static/ (static version)


Re: cuteDoc -New DDOC theme

2011-11-03 Thread Robik
Gide Nwawudu Wrote:

 On Fri, 28 Oct 2011 19:51:56 + (UTC), Robik szad...@gmail.com
 wrote:
 
 Hi.
 
 I'd like to share with new theme for DDOC named CuteDoc. It can be
 found here: https://github.com/robik/cuteDoc .
 
 Live demo can be foudn here: http://cutedoc.dav1d.de/ . (Thanks to
 dav1d (from #d) for hosting it).
 
 -- Robik
 
 
 Very nice.
 
 One issue I found was that the struct and class links in the 'jump to'
 frame have the word 'null' instead of a name.
 
 Gide

Thanks! I didn't notice that, I'm working on it now.




Re: cuteDoc -New DDOC theme

2011-10-29 Thread Robik
Nick Sabalausky Wrote:

 Robik szad...@gmail.com wrote in message 
 news:j8f14s$1o78$1...@digitalmars.com...
  Hi.
 
  I'd like to share with new theme for DDOC named CuteDoc. It can be
  found here: https://github.com/robik/cuteDoc .
 
  Live demo can be foudn here: http://cutedoc.dav1d.de/ . (Thanks to
  dav1d (from #d) for hosting it).
 
 
 Cute theme! (A ha! A pun!)
 
 Little suggestion: If you leave the modules and jump to already-expanded 
 in the HTML, and then use JS to flatten them upon page load, then it'll work 
 for everyone, not just those who have JS enabled. It's never good to assume 
 JS.
 
 One other issue: When both modules and jump to are expanded, the bottom 
 half of the jump to is hidden under the bottom frame of the browser window 
 and completely inaccessible, and scrolling dosn't help (And that's even when 
 I have the browser maximized). Frames have never really been considered good 
 style on the web, and floating boxes are not far off from frames. You may 
 want to consider making them non-floaty: it'll take a *lot* less work to 
 make it work right for everyone.
 
 

Thanks for cool suggestions.

About second issue, which web browser do you use?


cuteDoc -New DDOC theme

2011-10-28 Thread Robik
Hi.

I'd like to share with new theme for DDOC named CuteDoc. It can be
found here: https://github.com/robik/cuteDoc .

Live demo can be foudn here: http://cutedoc.dav1d.de/ . (Thanks to
dav1d (from #d) for hosting it).

-- Robik


D programming language Chat

2011-07-05 Thread Robik
Hello everyone!

I would like to announce new IRC-like chat on StackOverflow about
D-programming (language).

To talk there you need at least 20 reputation on your StackExchange account.

You can find the chat here:
 http://chat.stackoverflow.com/rooms/780/d