Re: Why Does Dscanner Warn About a Missing toHash if opEquals is Defined?

2016-08-02 Thread BLM768 via Digitalmars-d-learn

On Sunday, 31 July 2016 at 18:57:50 UTC, Jack Stouffer wrote:
Next question: what's the fastest hashing implementation that 
will provide the least collisions? Is there a hash 
implementation that's perfered for AAs?


I've heard that FNV-1a is a decent general-purpose option, and 
it's fairly straightforward.


https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function




Re: Why Does Dscanner Warn About a Missing toHash if opEquals is Defined?

2016-07-31 Thread BLM768 via Digitalmars-d-learn

On Sunday, 31 July 2016 at 16:39:59 UTC, Jack Stouffer wrote:
But D provides a default toHash for every type if it's not 
defined. I was wondering why not just rely on that version.


If two objects are equal, their hashes must also be equal. 
Consider this example:


struct Nullable(T) {
  bool isNull;
  T value;

  bool opEquals(Nullable!T other) {
if(this.isNull != other.isNull) return false;
// Any two nulls are equal.
if(isNull) return true;
return this.value == other.value;
  }
}

auto n1 = Nullable!int(true, 3);
auto n2 = Nullable!int(true, 4);

writeln(n1 == n2); // true
writeln(n1.hashOf == n2.hashOf); // false = BAD!

Now that I think about it, maybe this should be in the language 
docs; I don't think they mention it. 
(https://dlang.org/spec/operatoroverloading.html#equals)


Re: Iterate all visible symbols, even from imported modules

2016-07-18 Thread BLM768 via Digitalmars-d-learn

On Monday, 18 July 2016 at 13:00:16 UTC, Lodovico Giaretta wrote:

// how do I discover that "std" is a package?


I've got a DMD pull request that adds __traits(isPackage, 
someSymbol), but it's stuck waiting for approval. If and when it 
gets merged, it could be useful for that.


https://github.com/dlang/dmd/pull/5290


Keeping a reference to a linked list element

2016-05-11 Thread BLM768 via Digitalmars-d-learn
I just started working on a project in which it would be 
convenient to hold a reference to a specific entry in a DList. 
The interface doesn't seem to provide a way to get a pointer to a 
raw node struct, so about the best solution I can find is to get 
a range out of the list, pop elements until I get to the one I 
want to store, and save a reference to the front of the range 
with theRange.takeOne. I could then remove that node with 
theList.remove(theSavedNode), insert before/after it, etc., but I 
can't see a good way to just _get_ the node before or after it. 
Is there a good way to do this with the current interface, or 
would it need to be extended?


Re: C header file: tagged enumerations

2016-04-27 Thread BLM768 via Digitalmars-d-learn

On Tuesday, 26 April 2016 at 23:40:24 UTC, Adam D. Ruppe wrote:
D doesn't handle this C pattern well... you basically have to 
rewrite the whole thing for each version.


Or you can use the technique that's used in llvm-d: build the 
enumeration from a string mixin which is generated from a table. 
It's not necessarily the most elegant solution, but it can 
eliminate some code duplication.


Re: Functions that return type

2016-01-20 Thread BLM768 via Digitalmars-d-learn

On Wednesday, 20 January 2016 at 10:04:03 UTC, burjui wrote:
That's alright. Parsing and AST construction are trivial with 
S-expressions (Lisp-like syntax), so if you use them for the 
early stages of development, you can focus on the type system. 
When you're done with types, you can switch to making a better 
grammar for your language.


True. I'd been playing with the idea of having multiple syntactic 
"front-ends" anyway (mainly for the purpose of making DSLs), so 
it wouldn't be too much of a stretch to use an S-expression 
syntax. One problem, though, is that I'd either have to extend 
that syntax to support some of the constructs I want (i.e array 
literals) or create a bunch of variadic constructor functions 
(which could be evaluated at compile time). Of course, 
S-expression syntax is kind of designed to be extensible...


That's all off-topic, though. ;)



Re: Functions that return type

2016-01-19 Thread blm768 via Digitalmars-d-learn

On Sunday, 17 January 2016 at 02:08:06 UTC, Timon Gehr wrote:

On 01/16/2016 11:50 PM, data pulverizer wrote:

I guess the constraints are that of a static language.


(This is not true.)


I'm playing with the design of such a language myself. Basically, 
anything can create/use/return type objects, but a variable of a 
particular type can only be instantiated using an immutable type 
object whose value is known at compile time.


It's not very far along, though. Right now, I have a "compiler" 
that parses integers and parentheses. ;)


Re: How do you create an opengl window with DerelictOrg?

2015-12-07 Thread BLM768 via Digitalmars-d-learn

On Monday, 7 December 2015 at 21:33:57 UTC, Enjoys Math wrote:

I've seen these:
https://github.com/DerelictOrg?page=1

BUt not sure how to use them, examples?


OpenGL itself can't create a window/context, so you'll need to 
use DerelictGLFW or DerelictSDL. GLFW is lighter-weight.


Combine the setup code from here:
https://github.com/DerelictOrg/DerelictGLFW3

...with the example code from here:
http://www.glfw.org/documentation.html

Don't forget to load DerelictGL when you load DerelictGLFW. In 
addition, after you have the OpenGL context, you'll need to call 
DerelictGL3.reload() if you want anything more advanced than 
OpenGL 1.1.

https://github.com/DerelictOrg/DerelictGL3





Re: Password Storage

2015-11-27 Thread BLM768 via Digitalmars-d-learn

On Friday, 27 November 2015 at 16:14:06 UTC, H. S. Teoh wrote:
True, so you'd store hash(password01) in the database, and 
compute

hash(X + hash(password)) during authentication.


T


Another option is SCRAM: 
https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism


Re: Password Storage

2015-11-26 Thread BLM768 via Digitalmars-d-learn

On Friday, 27 November 2015 at 02:05:49 UTC, H. S. Teoh wrote:
For authentication, the password shouldn't even be sent over 
the wire. Instead, the server (which knows the correct 
password) should send a challenge to the client (i.e., a large 
random number produced by a good RNG -- which is different each 
time the user authenticates). The client should then prepend 
this challenge to the password typed in by the user, and 
compute the hash of the result. This hash is sent back to the 
server, which does the same computation on its own, and checks 
whether the two hash values match. Provided you're using a good 
cryptographic hash, the only way the client will be able to 
provide the right answer is if the user actually knows the 
password. At no time is the password ever sent over the 
network, encrypted or not.



--T


The issue I see with this is that the server has to _know_ the 
password in order to hash it with the challenge. If the server is 
compromised, guess who else knows the password now?


Some kind of public-key encryption/signing might work, though.


Re: Something about Chinese Disorder Code

2015-11-24 Thread BLM768 via Digitalmars-d-learn

On Tuesday, 24 November 2015 at 09:48:45 UTC, magicdmer wrote:

I display chinese string like:

auto str = "你好,世界"
writeln(str)

and The display is garbled。

some windows api like MessageBoxA ,if string is chinese, it 
displays disorder code too


i think i must use WideCharToMultiByte to convert it , is there 
any other answer to solve this question simplely


You can also try using a wide string literal, i.e. "你好,世界"w. The 
suffix forces the string to use 16-bit characters.


The garbled display from writeln might be related to your console 
settings. If you aren't using the UTF-8 codepage in cmd.exe, that 
would explain why the text appears garbled. Unfortunately, 
Windows has some significant bugs with UTF-8 in the console.


Finding packages recursively

2015-11-23 Thread BLM768 via Digitalmars-d-learn
I'm trying to recursively visit a package and all 
packages/modules within it using metaprogramming. I should be 
able to use __traits(allMembers, somePackage) recursively to get 
all symbols within the package, but is there an easy way to 
determine whether a symbol represents a package, a module, or 
something else?