« first day (506 days earlier)      last day (3510 days later) » 

8:00 PM
but if a user has 50 types of foods, you are saying I should add columns for each food?
 
and grab the last row of the user for updating the session?
 
This is unacceptable
 
I agree, unacceptable.
A new kind of food should not require a schema change.
 
I'd go for a transaction log too
 
@200_success I see what you mean. But I am concerned that older transactions that wouldn't matter anymore, simply because they have been used up, will still be taken into account and calculated every time. And to remove them I have to build a cleaner that just doesn't seem like the right thing
another thing is that if I decide to add other sources of, for the example, foods in future, like presents or rewards, I would also have to treat them as transactions
That wouldn't be right, I guess
 
8:05 PM
CREATE TABLE FruitPerUser {
	TableID INT Primary Key,
	FruitID INT Foreign Key,
	UserID INT Foreign Key,
	DateStamp DATE, -- assume Time is included
	Inventory INT
}
then you grab the most recent records from the UserId
 
Malachi's solution works, but you have to be careful about race conditions when calculating the inventory.
 
if there is only one user per UserID it should be ok
the Fruit table could get locked up though as well as the FruitPerUser table
you should have a history to go back to. but if you are only keeping a session state, you should save the session in a table and allow the site to pull that session object from the database
 
I don't need to keep history
Well I don't know if that's technically right
 
then it would be a simple table holding UserID and Session Object
 
if a user buys, for examp,e 5 apples, then feeds 2 to his pet I need to have 3 for him available
 
8:09 PM
sounds like all you want is Session Variables to be able to repopulate when they log out and back in again
 
yep and that's what I've built
Let me get back to the example with banks though
how do banks store different currencies in an account?
do they store them as columns ?
 
different accounts
 
What do you mean different accounts
I have both EUR and my local currency in 1 account
 
they are technically in two accounts.
linked to your single account
say 0123 is your master account
 
Oh yeah I understand
 
8:12 PM
0123-001 is your American and 0123-002 is your EUR
 
but that would be a huge overkill in my case
 
@Malachi It would be interesting to consume the same apple twice in two different sessions.
 
same user should only have one session and not be allowed to open a second session
 
That's not true
 
not meaning only one page
 
8:13 PM
what if I'm on my desktop and mobile at the same time
for some reason
 
I can be logged into this chat room from 3 places at the same time....
my alerts on stackexchange don't pile up on another machine that I am logged into if I see them here at work.
 
I'm quite happy with my db structure right now, it's pretty clean and easy to use, the only issue I appear to be having is adding large quantities of items
 
So, I still recommend the transaction log method that I proposed. You don't have to worry about race conditions. You probably won't ever need to worry about database size. (And if you do, you can fix that later.) You just do the simplest thing possible, and let the database do its job.
 
Alright, I'll give this some thought.
Thank you so much for your advice and time
2
 
You're welcome.
 
8:19 PM
have a good one
hope I was more productive than counter productive, I kind of jumped into the middle there....
 
That's OK. The alternative suggestion was helpful to the discussion.
 
glad to hear that....lol
back to the issue of figuring out why my installer isn't working the way I need it to.
 
22
Q: Why don't developers make installation automatic on windows?

Volker SiegelThis is the inverse to "Why don't developers make installation wizards on linux?", which is interesting, but made me think "Automatic instalation is the natural way. Why do they use wizards?". So here is the inverse question: I'm sure it's not about laziness or anything like that but I fail to ...

 
I had something broken and then tried to create a new one, hopefully I fixed the old one... I am not sure that link helps me...
 
@200_success I love apt-get install in Linux after 1 day already
2
 
8:25 PM
@skiwi it is wonderful...lol
 
@skiwi You've only used Linux for one day? Oh you poor poor soul...
2
 
<?php
$var = 4;
if ($var == 3){
	echo 'This variable equals three.';
} else {
	echo 'This variable does not equal three';
}
?>
 
@SimonAndréForsberg Well... since friday actually
 
@SimonAndréForsberg wish I could use it everywhere!
I would know it a lot better.
 
^^ is this proper formatting for if-else statements the "PHP way"?
 
8:26 PM
I like Windows in a way, but I like Ubuntu/Linux in another way
 
Sorry, that was Schadenfreude. I wasn't trying to be helpful.
 
(mostly the indentation of the else... should it have a line break?)
 
@Phrancis I'm not sure if there are any specific PHP conventions. I think there might be, but people tend to write so crappish PHP so it seems like noone is really aware of them...
 
Isn't that the truth lol.
 
@Phrancis I'd recommend looking at how php.net does it in their examples and do it the same way
 
8:27 PM
<?php
if ($a > $b) {
    echo "a is bigger than b";
} elseif ($a == $b) {
    echo "a is equal to b";
} else {
    echo "a is smaller than b";
}
?>
From php.net
Good to go I guess!
 
Yeah
I personally like it this way:
}
else {
I don't know why Java and other languages do it } else {
two braces and one keyword on the same line, that's too much for me!
 
I don't like that much either TBH
 
@SimonAndréForsberg Well, if you want more free space, then use C!
 
@skiwi Well, if you forgot to write a, then edit your message!
 
The else on new line seems funky to me, but, in the bigger picture, I don't care about where it is as much as whether it is applied consistently
 
8:30 PM
"if you more free space"?
 
@SimonAndréForsberg I no see error
 
I like that @rolfl consistency
 
@SimonAndréForsberg I'm sorry but I as soon as you said PHP.net I though at this blog and I cannot help linking it to you phpmanualmasterpieces.tumblr.com
 
@SimonAndréForsberg Yeah yeah :)
 
8:34 PM
> If the thought of confusing people who read your code makes you feel
warm and tingly, you’re going to love the ternary operator, represented
by a question mark (?). This operator, which lets you make your
conditional statements almost unintelligible, provides shortcut syntax for creating
a single-statement if-else block.
 
figured it out! now to test the exception thingy and E-mailer....LOL
 
<?php
$msg = $numTries > 10 ? 'Blocking your account...' : 'Welcome!';
?>
^^^ Eww?
 
forgot the subject line
 
So @Malachi and @Phrancis here are kind of trying ot learn to professional program? ;)
I haven't opened up Netbeans in last two days :( And yet I also have opened Netbeans the last two days.
 
<?php
$var = 4;
// This feels dirty...
$result = $var == 5 ? 'This variable is five.' : 'This variable is not five.';
echo $result;
?>
 
8:40 PM
@mariosangiorgio Why am I not surprised? :)
 
I'd like my PHP to make you guys proud... that's why I ask so many questions? ;)
 
@Phrancis It is immensely useful though, that ternary conditional operator. (the 'real' name is the conditional operator, but 'ternary' just got stuck to it)
 
@SimonAndréForsberg Until people start chaining 10 of them together...
Then they get ugly
 
@Phrancis Keep on asking! As long as it will end up in you answering more and better PHP Zombies (better answers, not better zombies)
@skiwi That is true. Heck, it's even enough chaining two of them together
 
About time I learn to review something other than SQL :)
5
 
8:44 PM
Talking about PHP, back in the days I wrote a website to manage a fantasy football league. I still have the code but I am afraid I'll cry if I read it. PHP, zero experience in programming, and code written in a couple of weeks. I'm still surprised it worked reasonably well for the whole season...
 
I'm surprised by how good I seem to be able to write C... Though tomorrow I'll put it up on CR once the code has been officially accepted for this assignment!
 
@mariosangiorgio Been there :)
@skiwi Let me remind you:
7 hours ago, by skiwi
I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, I hate C, ...
 
@SimonAndréForsberg ;)
Well, I still need to do at least two assignments in C
Excellent question.
-2
Q: Get input of integers with space between

BrianHow do I get input of 3 integers with white space inbetween from 1 line? For example, I would prompt ... a,b,c? 1 2 3 How do I get the values 1,2,3 and store them separately?

 
@skiwi Nice homework!
 
TTGTB
 
8:58 PM
@skiwi I am writing code for work
 
@SimonAndréForsberg I prefer F (Fahrenheit). ;-)
 
-3
Q: Get input of integers with space between

BrianHow do I get input of 3 integers with white space inbetween from 1 line? For example, I would prompt ... a,b,c? 1 2 3 cout << "(Integers) a,b,c?"; cin >> ???? ; How do I get the values 1,2,3 and store them separately?

 
@Jamal I hate F, I hate F, I hate F, I hate F, I hate F, I hate F, I hate F...
 
I have 5 badges where I have 20+ answers but not enough votes for a bronze badge
 
First answer, anyone knows this language?
0
A: Is this IRC bot utility library Racket-y enough?

Jonathan SchusterHere are my comments after a brief reading: First, if you intend to make this library fit for general use, add documentation in comments for the provided functions. See the Racket style guide for examples Also, if you intend to make this a more general library, don't include default arguments (...

 
9:08 PM
The English portions seem like sensible review points
Would be neat to see him get awarded the bounty on his first answer!
I have this little script:
<?php
$day = 'Thursday';
$time = '0800';
$country = 'UK';
if ($day == 'Thursday') {
    if ($time == '0800') {
        if ($country == 'UK') {
            $meal = 'bacon and eggs';
        }
    }
} else {
	$meal = 'pork chops';
}
echo $meal;
?>
If I change $country to say, 'USA' I get this:
> E_NOTICE : type 8 -- Undefined variable: meal -- at line 14
 
define meal at the top with an initial variable? seems like meal is only defined at the bottom of the 3 if statements
 
either that, or AND the if-conditions together so that there is no remaining control flow path that leaves $meal undefined.
 
@Phrancis $meal isn't set when that happens
 
AND is && right?
 
I would have to look it up.
 
9:17 PM
@Phrancis correct
 
but if you did and's all the way and then an else, $meal would get set no matter what
 
0
Q: Performance enhancement for collection manipulation

RanPaulI have below snippet of code which gets all the available menu items for a zone(top or left)and adds the widgets for which user has access to an ArrayList collection. For now the getWidgetsByZone(zone) returns 64 items and iterates over them. Am seeing some performance lag in this method(in a too...

 
This look a little better? Not getting any error and returning the correct result.
<?php
$meal = 'Undefined';
$day = 'Monday';
$time = '0800';
$country = 'USA';
if ($day == 'Thursday' && $time == '0800' && $country == 'UK') {
	$meal = 'bacon and eggs';
} elseif ($day == 'Monday' && $time == '0800' && $country == 'USA') {
	$meal = 'pork chops';
} else {
	$meal = 'steak and fries';
}
echo $meal;
?>
Mostly curious also if it's good practice in general to do something like $meal = 'Undefined' right at the top
In other words, give variables a default value so you know if something's not right, you'll get that value...
 
9:40 PM
@Phrancis Sentinel values are a stupid idea, in general. Rather try to make sure that no matter what path is executed, a valid value gets assigned. In this case, a default value is unnecessary. If you do need a value for an “unassigned” variable, use NULL. Also, remember to actually check for that value!
 
@Phrancis personally, i'd say no. in your example, if you don't set $meal, the code echoes "Undefined" and carries on like you didn't just output invalid data. If you hadn't set a default value, PHP would at least have thrown a notice at you.
assuming you develop with notices on, which most people should :P
 
@amon for a string type $variable would I check for... NULL || 'NULL' or '' (empty string)
 
@Phrancis $variable = NULL; assign_values(); if ($variable == NULL) { oops(); }
 
@cHao I saw your rant on your SO profile, I bet that comes in handy
 
9:57 PM
I gotta say, this was a very interesting question:
 
0
Q: Determine if a string has all unique characters

KingPolygonI'm practicing algorithms (for future interviews) while learning about Big O notation and was wondering if there's a faster or more optimal way of writing an algorithm to see if a string has all unique characters (assuming you can't use additional data structures). - (BOOL)containsUniqueCharacte...

 
2
Q: Count number of ways to paint a fence with N posts using K colors

thomasA friend sent me this question, and I'd love somebody to review this and give his opinion. The question: Write an algorithm that counts the number of ways you can paint a fence with N posts using K colors such that no more than 2 adjacent fence posts are painted with the same color" Is...

 
@CaptainObvious Nice interruption! :P
 
arrrgh @CaptainObvious
 
@Phrancis it does, occasionally. i'm getting to the point where i downvote SO questions (and answers) that still use mysql_query. i just point them at my profile now rather than going over the details each and every time :)
2
 
10:04 PM
Any pros/cons in using a switch function as opposed to if {} elseif {} else {}?
 
Switch in theory is faster, what language?
 
PHP - example:
<?php
$day = 2;
switch($day) {
	case 1: $special = 'green eggs and ham';
	break;
	case 2: $special = 'macaroni and cheese';
	break;
	case 3: $special = 'roast beef sandwich';
	break;
	default: $special = 'French onion soup';
	break;
}
echo $special;
?>
I find the syntax is simpler, but I'm sure there are limitations
 
Definitely use the switch.
 
OK, I have now placed the code inline as well. Hope the hold can be removed now. Thanks. — figmentum 1 min ago
The OP has sort of waited for a while, and now I might have to say that the code appears to be hypothetical.
 
BBL - Thanks for all the advice :)
 
10:38 PM
Nice, got a "Wow" comment ;-)
(for an objective-C answer ..... hehehehe).
 
-1
Q: How can i fix my code?

Junior Bettencourtstatic void Main(string[] args) { Random rnd = new Random(); int num = rnd.Next(); int tries = 0; int guess = 0; Console.WriteLine("Guess My number"); do { Console.WriteLine("Enter a number between 0 and 5"); ...

 
Night!
No more birthday for me, next!
 
10:55 PM
0
Q: C++: How to make a error trap for letters in number guessing game

Shico75I need help making a error trap for my number guessing game. The problem is When the player puts in a letter or word instead of a number the whole program crashes. +Any tips on how to improve my code is also appreciated! #include <iostream> #include <stdlib.h> #include <time.h> #include <cstdlib>...

 
11:07 PM
Good first answer:
3
A: Optimize query containing too many inner join and rows

user139734I can see what you are doing, unlike some others and I would suggest you approach performance problems in this way : 1) Lift out the SELECT statement and build it table by table. 2) Dress the SQL to make it readable for those that come after you. SELECT ... FROM dbo.WTEFAC ...

 
11:30 PM
Ok. So I practically just napalm'd this with downvotes...
66
Q: Remove-Last-Comma-Problem

Jonasis there a more elegant way to solve this problem? List<String> paramList = new ArrayList<String>( ); paramList.add( "param1" ); paramList.add( "param2" ); StringBuilder result = new StringBuilder(); for ( String p : paramList ) { result.append( p ).append( ", " ); } String withoutLastComma ...

 
How in the world did that question get so many views??
StringBuilder result = new StringBuilder();
for ( String p : paramList )
{
  result.append( p ).append( ", " );
}
And... WHY?
Create your own problem, and then hack a fix for it...?
insert into Palm values 'Face';
7
 
@Phrancis, this is gold cuz.
> Your aliases make no sense. Your table names are cryptic enough (you probably can't change that) but to alias WTFAC as F certainly doesn't help. WTFACINFO as BS to me only suggests this: WTF BS.
And I know I missed ya @Simon, but happy birthday man.
 
11:47 PM
Glad someone noticed the sarcasm :)
 
It was a funny review. I'm a fan of funny reviews.
I've noticed that the more frustrated the reviewer is. The funnier they tend to be.
2
 

« first day (506 days earlier)      last day (3510 days later) »