theory

How to merge user data after login?

我的梦境 提交于 2019-11-30 13:24:49
问题 It doesn't matter if you're building an eshop or any other application which uses session to store some data between requests. If you don't want to annoy the user by requiring him to register, you need to allow him to do certain tasks anonymously when possible (user really have to have a reason for registering). There comes a problem - if user decides to login with his existing profile, he may already have some data in his "anonymous" session. What are the best practices of merging these data

The consequences and pros/cons of flushing the stream in c++

回眸只為那壹抹淺笑 提交于 2019-11-30 11:09:04
I have recently read an article which stated that using \n is preferable to using std::endl because endl also flushes the stream. But when I looked for a bit more information on the topic I found a site which stated: If you are in a situation where you have to avoid buffering, you can use std::endl instead of ‘\n’ Now here comes my question: In which situation is it preferable not to write to the buffer? Because I only saw advantages of that technique. Isn't it also safer to write to the buffer? Because it is smaller than a hard drive it will get overwritten faster than data that is stored on

Is multiplication allowed in relational algebra?

戏子无情 提交于 2019-11-30 10:01:33
问题 I have a relation R ------- cid sid gradepoint credits CS425 001 4.0 3 I need to calculate the GPA. There are more rows, but I believe if I just get this answered I should be ok with the rest. I need to do gradepoint * credits . How do I express this with a relational algebra expression? My best guess is: , but I'm not sure if I can multiply attributes with anything other than a constant. 回答1: Relational algebra doesn't address domain-specific operations. It neither includes nor excludes it,

Are NSStrings stored on the heap or on the stack and what is a good way to initialize one

百般思念 提交于 2019-11-30 09:18:05
I have 2 new questions: 1) Consider this line: NSString *myString = [[NSString alloc] initWithString: @"Value"]; There were two things I learned, but I would like confirmation: As I learned, the "alloc" message indicates that the instance of NSString will be stored in the "heap" memory. I understood also that primitive variables such as "chars" are stored in the "stack" memory. Does this mean that: the instance of NSString is stored in the heap memory; AND that this object has an iVar pointer (when the initWithString method was called) to the "Value" string of primitive "chars", which reside

Comparing two Calendar objects

天大地大妈咪最大 提交于 2019-11-30 07:59:04
问题 I want to compare two Calendar objects to see if they both contain the same date. I don't care about any value below days. I've implemented this and I can't think about any case where it should fail: private static boolean areEqualDays(Calendar c1, Calendar c2) { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); return (sdf.format(c1.getTime()).equals(sdf.format(c2.getTime()))); } Is this approach correct or should I compare c1 and c2 field by field? 回答1: I've implemented this and I

How to merge user data after login?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 07:18:33
It doesn't matter if you're building an eshop or any other application which uses session to store some data between requests. If you don't want to annoy the user by requiring him to register, you need to allow him to do certain tasks anonymously when possible (user really have to have a reason for registering). There comes a problem - if user decides to login with his existing profile, he may already have some data in his "anonymous" session. What are the best practices of merging these data? I'm guessing the application should merge it automatically where possible or let the user decide

How to write a simple database engine [closed]

走远了吗. 提交于 2019-11-30 06:07:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am interested in learning how a database engine works (i.e. the internals of it). I know most of the basic data structures taught in CS (trees, hash tables, lists, etc.) as well as a pretty good understanding of compiler theory (and have implemented a very simple interpreter) but I don't understand how to go

Understanding word alignment

让人想犯罪 __ 提交于 2019-11-30 05:02:36
I understand what it means to access memory such that it is aligned but I don’t understand why this is necessary. For instance, why can I access a single byte from an address 0x…1 but I cannot access a half word (two bytes) from the same address. Again, I understand that if you have an address A and an object of size s that the access is aligned if A mod s = 0 . But I just don’t understand why this is important at the hardware level. Hardware is complex; this is a simplified explanation. A typical modern computer might have a 32-bit data bus. This means that any fetch that the CPU needs to do

Combinatory method like tap, but able to return a different value?

风流意气都作罢 提交于 2019-11-29 23:55:42
I'm going through a phase of trying to avoid temporary variables and over-use of conditional where I can use a more fluid style of coding. I've taken a great liking to using #tap in places where I want to get the value I need to return, but do something with it before I return it. def fluid_method something_complicated(a, b, c).tap do |obj| obj.update(:x => y) end end Vs. the procedural: def non_fluid_method obj = something_complicated(a, b, c) obj.update(:x => y) obj # <= I don't like this, if it's avoidable end Obviously the above examples are simple, but this is a pretty common coding style

When does Big-O notation fail?

人走茶凉 提交于 2019-11-29 21:37:41
What are some examples where Big-O notation[1] fails in practice? That is to say: when will the Big-O running time of algorithms predict algorithm A to be faster than algorithm B, yet in practice algorithm B is faster when you run it? Slightly broader: when do theoretical predictions about algorithm performance mismatch observed running times? A non-Big-O prediction might be based on the average/expected number of rotations in a search tree, or the number of comparisons in a sorting algorithm, expressed as a factor times the number of elements. Clarification : Despite what some of the answers