« first day (414 days earlier)      last day (3901 days later) » 

00:20
TTGTB
560 mugs on the wall
00:36
Night
01:03
0
Q: Code Hunter 2.06

Frutal1tyI'm playing Code Hunt on level 2.06 (loops) this level is about counting the number of "a" in a String, there's my code: public class Program { public static int Puzzle(String s) { int ret = 0; for(int x = 0; x < s.length(); x++){ if(s.charAt(x).equals('a')) ret++; } return ret...

01:44
0
Q: whats wrong with my size method of Tree List in java

user3701204Im trying to implement a Tree that holds the list of the children of a given node. When I try to output the size in my main method it returns 1. How do I return the size/height of the tree in my createNode method? For the Tree in my main method, I believe the size/height should be 3 (0,1,2,3). An...

1
Q: Login System Security Part 2

user3586322old thread/old code: Login system security This is an update on the code and suggestions I received from generous users on the old thread. So same rules apply, just check it out, tell me what you think. Is it better or worse? is the security getting better and if so what else can I do to make...

02:34
I finally gave my JSON parsing library a name and a home: codereview.stackexchange.com/q/43872/27623
0
Q: Implementing `randoms`

Kevin MeredithLearn You a Haskell presents the randoms function. I implemented it as follows: -- randoms that takes a generator and returns an infinite sequence -- of values based on that generator import System.Random randoms' :: StdGen -> [Int] randoms' g = num : randoms' gen where (num, gen) = rando...

 
1 hour later…
03:41
Hey, thanks santa ... you found one-vote short?
hi
Hi.
Two Enlightened coming up. And I believe I just have one question and one answer one-away.
No you don't
:-)
03:46
I just spent a lot of time figuring out a JDQ alternative answer.
One of the nicest pieces of code I have played with in a bit
I doubt he'll appreciate its beauty
Yeah. :-/
04:00
Wow, I think that was my longest (time-wise) review yet
04:12
Last 9-score answer just now improved.
Speaking of badges, how did I end up with the Generalist badge? How much more specialized can you get than I am?
A wizard did it.
04:27
0
Q: How to speed up the code for finding the 'Minimum' AND of the possible subsets of a set(subset size should be greater than or equal to 2)

007#include<stdio.h> #include<stdlib.h> #include<math.h> #include<malloc.h> #include <iostream> #include <vector> long long int set[100000]; long long int counter, j; long long int ans,min,count; bool ha; long long int pow_set_size; long long int power[100000]; void printPowerSet(long long int set_...

@CaptainObvious Beyond two libraries, this is pretty much C.
@rolfl: Incoming... you know.
0
Q: Implement stack using a queue

JavaDeveloperI am trying to implement Stack using linkedlist. Looking for code-review, best practices and optimizations. public class StackUsingLinkedList<T> { private Node<T> top; int size; public StackUsingLinkedList() { } private static class Node<T> { Node<T> next; ...

04:55
@Jamal How was that for helping reduce the time from question to (at least the first) answer?
You're pretty fast. :-) I have to go to bed soon anyway.
morning @all
@Jamal All that time on SO had to be good for something...
@chillworld Good morning!
I don't know how you manage each day. :-P
Morning!
@Jamal Poorly (at least according to my wife).
04:59
no idea what to do with this :
In mine eyes a bad answer
suggesting to go for a one liner is against all our principals for readable code
@JerryCoffin Maybe Lounge<C++> keeps you sane? :-) I'd learn more C++ and go in there, but I have a feeling that they don't just talk about C++...
I'll skip it
@Jamal Actually, we rarely discuss C++ there. Right now, you'd be a lot more likely to see something about World Cup than C++. For example, a couple days ago there was the first time I saw:
Roy Hodgson and the England team visited an orphanage in Brazil today.

"It is heartbreaking to see their sad little faces with no hope."  said Jose, age 6."
Phew. Well, I should be good as long as I don't come in with a question.
LOL
...or I can just wave my diamond and get by with fear or something.
OTOH, the Lounge isn't a play to help you stay sane. It's a place to fit in by being insane.
@Jamal Even Shog doesn't instill a whole lot of fear there.
05:06
I wasn't seriously going to go in there. Just speculating. :-P
@JerryCoffin ...then there's no hope for me. D:
@Jamal It's simply not the sort of place where fear is of much use. Personally, I think you'd get along all right, but probably wouldn't find it particularly enjoyable. It does have a couple of regulars who are pretty negative about pretty much everything, and I'm not sure how well you'd get along with that.
Even after just reading the transcript, it does send a bad vibe.
@Jamal It is...different. I like it, but as noted above, I'm probably not entirely sane, which helps... :-)
I've noticed. :P
05:22
@Jamal: Does the comment I just added to this answer seem helpful/useful?
I think so. It's sort of a review, but is missing out on some additional info.
@Jamal It wasn't easy, but I tried to suppress my natural tendency toward snark...
SO does that to ya. ;-)
I sometimes feel tempted to snark on SO, and I'm not quite sure why I resist.
@Jamal I wish I could honestly blame SO, but in my case it predates SO by quite a while, I'm afraid.
Storytime!
05:31
@Jamal I beg your pardon?
Nothing. Just a tad curious.
@Jamal About my being snarky, you mean?
Yeah
Goes back to my childhood. I had an older sister who was almost constantly sarcastic and fairly frequently downright vicious. I suspect I developed it as a defense mechanism.
Ah
I've never been like that before, but seeing so much trash on SO has just... enraged me or something. Sure, it's just a website, but it's one of the best, and I don't like it filling with trash.
05:37
OTOH, it's hard to guess how I'd have turned out if she wasn't around. I could be blaming her for how I'd have been in any case.
As far as I know, I have no defense mechanisms. I can be "vicious" at times, but by nature, I'm not.
@Jamal I have the mixed blessing of having been on Usenet for years, and Fidonet for years before that (that's where Edward and I first "met"). Fidonet was a lot of fun, but it probably helped a lot that the technical hurdles to participation were quite high. I doubt that atmosphere could be maintained on a modern web site.
Before the "Eternal September", Usenet was pretty friendly as well. It also provided an extremely level playing field, where you could carry on a conversation with Dennis Ritchie or Bjarne Stroustrup quite regularly. After a billion AOLers joined, however, things changed, and there's no real going back.
Many online communities do tend to decline in quality over time. I see it in so many places.
@Jamal I'm not sure their right, but I suspect a psychologist would say we all have defense mechanisms. At the same time, it's certainly true that in some cases they're a lot more developed than others.
That's probably it. Not too many people have truly threatened me, not even online. But I'm also stronger online than I am in person.
05:45
@Jamal I saw an explanation a while back that seems to make sense. A bigger community means you're less likely to interact with a particular user in the future, which reduces your concern for treating them well.
Some of us try to treat people well anyway, but others...don't.
I fear that that can happen to CR if we get too big. Through my editing and moderation, I'm trying to combat that as much as I can.
@Jamal And believe me, I (for one) am thankful that you do! I do think CR is probably at least somewhat less prone to go that direction than SO, but it's still awesome that you three work so hard at maintaining its quality too.
On that note, I think I'm going to go get some sleep. Good night.
:-)
Goodnight!
06:45
0
Q: Laravel - Repository and Entity patterns

doitmywayI've spent quite a bit of time studying the repository and entity patterns and this is what I came up with. I would appreciate it if you could post suggestions and critique. User entity: <?php namespace Huntitapp\Entities\Entities\User; use Huntitapp\Entities\Abstracts\AbstractEnti...

07:34
0
Q: PHP Simple Class

Hassan Althaf<?php namespace Users; use mysqli; class Users { protected $db; public function __construct() { $this->db = new mysqli('localhost', 'root', 'php123', 'sms'); } public function login($username, $password) { $query = $this->db->prepare("SELECT username, password FR...

 
2 hours later…
09:42
0
Q: Code hunt : Perfect score means not so perfect coding

chillworldWith a recent question I went to code hunt and play there a little bit. At one moment I get this result as question : n Expected Result 1 0 2 1 3 5 4 14 5 30 6 55 7 91 8 140 9 204 First solution : public class Program { public static int Puzzle(int n) { ...

0
Q: Satelite orbit simulation in Matlab using Runge Kutta 4

tanphamI have a satelite orbit simulatoin in Matlab (Using Runge Kutta 4). After complete, it look like seem ugly and i don't khow how to fix it. This is my fx.m file: function v = fx(t,x,vx) v = vx; This is my fy.m file: function v = fy(t,y,vy) v = vy; My gx.m file: function v = gx(t,x,y,vx,vy)...

0
Q: Code hunt : Perfect score means not so perfect coding

chillworldWith a recent question I went to code hunt and play there a little bit. At one moment I get this result as question : n Expected Result 1 0 2 1 3 5 4 14 5 30 6 55 7 91 8 140 9 204 First solution : public class Program { public static int Puzzle(int n) { ...

0
Q: My HTML and CSS is disgusting. I need some help getting topyellow,topred, slider, and navbar divs stacked

user3756283So here is my code. I basically have a left, middle, and right section of the page. There is a left and right margin which is about 19.5% wide on each side with a white area in the middle which will contain the main content of the site. I will use the left and right areas to post certain thing...

10:17
1
Q: Bank card validation module

NRKirbyI am relatively new to Java (& code review) and hope that someone could review a module I wrote for bank card validation. I included a class that tests some of the methods, this is purely to show the methods work, rather than unit testing. I would be very grateful for any input as to how to impro...

For dependency injection, I recommend we discuss it in chat The subject is too long for comments. As for hashing algorithms, then shouldn't you be practicing best practices? password_hash() is the best there is. Maximum length does not harm performence, it harms security. It limits the number of characters your users' password might have! Static methods have no meaning in PHP. You might as well use normal functions without a class. getAndSet: In that case I'd call it fetchUserInfoFromDB(). — Madara Uchiha 2 mins ago
Please ping me if he gets here
Madara
I'm here.
Thank you for your post I really appreciate it man.
monking
@HassanAlthaf Sure thing :)
Monking @all
10:27
Ok, now how would I use all your ideas?
I've removed LIMIT 1 from my query.
No, actually LIMIT 1 is a good thing
Ok, I'll add it back then.
There we go.
You should get rid of the while loop
*loop. And okay.
You know for sure that there will only be either 1 row or 0 rows. In which case, you don't need a loop
Only an if to check if there's a row or not.
10:28
Ok, and i've added the 'return true' to my if statement as well.
OK
What have you tried with DI and failed?
I've made another class.
Let me get pastebin for what I tried to do.
0
Q: Is it possible to remove variable repetition here?

MEM/** * Class stringHelperK * Helper Class to deal with small string manipulations. */ class stringHelperK { public function normalizeStringK($string) { return $this->removeAccents( $this->replaceSpacesWithSlashes($string) ); } /** * @param $st...

@MadaraUchiha pastebin.com/QD9SMdAY
Anyone else who can criticize more of my code? I actually like it when people criticize my code. Instead of feeling shy, I feel happy that I know my mistake.
10:33
@HassanAlthaf You should pass the $db object to the User
Like so:
new User($db);
Or
Oh, DB $db or just $db
Just $db
Let me create a class quick then.
By the way, which IDE do you use?
When you define the function, you write DB $db to say "I only accept DB objects!", but when you pass it in, you don't specify the type.
@HassanAlthaf For web development I use PhpStorm
But I'm moving towards NodeJS so I'm looking at a few others too
Well, try Sublime Text 2.
10:35
@HassanAlthaf I already own a license for ST3 :)
'own' a license?
Nice man.
Madara, I guess I know you from somewhere, do you play this game, "Habbo"
Oh okay. I used to no someone called Madara.
10:36
But Madara Uchiha is not an uncommon nickname, given its role in Naruto
*know
Oh!!! I was wondering why do I see Madara Uchiha all the time.
Sublime Text ftw.
I spent my childhood in programming instead of cartoon.. I wish I had my childhood back.
@kleinfreund I need to force myself one day to sit through and only use ST for two months, until I can use it as effectively I'm using PhpStorm.
10:38
Heard good things about PhpStorm as well.
PhpStorm is amazing.
Btw Madara.
Using ST and try to remember more shortcuts from time to time.
Can you explain me in your own words, what is an Abstract Class? And when and why it is used?
Please don't link me to an article because I don't understand in them.
@Hassan What if Madara wrote such an article?
10:39
@HassanAlthaf An Abstract class is a class that cannot be concrete, but it can be derived into more specific classes that inherit its behavior.
You cannot new an abstract class.
For example
Madara can you simplify your language? My english sucks.
Man, Chrome has an experimental flag for DirectWrite. Finally good font rendering.
Madara, I get this error, "Notice: Undefined variable: db in C:\xampp\htdocs\Projects\SMS\classes\class.users.php on line 109"
"$Users = new Users($db);" should I make an instant inside the DB class or something?
No, but you need to have a $db variable before you pass it in
I do Madara.
Let me get a pastebin again
10:44
An abstract class is like a basic tree. You know the parts a usual tree consists of. But you don't know whether it has needles, etc.
@HassanAlthaf When you call $db it does not exist yet.
You only set it in the next row
So, @MadaraUchiha what should I do?
(Also, should be $db not $DB)
@HassanAlthaf Instantiate $db before you try to pass it in :)
@Hassan A more specific class would provide more detailed information about this tree.
10:46
@MadaraUchiha it is still not working.
I switched the positions of the classes.
I mean the instants
$DB = new DB();
$Users = new Users($db);
$UserData = new UserData();
$UserUtil = new UserUtil();
@HassanAlthaf $db not $DB.
OMG LOVE YOU MAN
IT works
And your last suggestion
UserMapper and stuff, I don't understand them. @MadaraUchiha
@HassanAlthaf Think about it this way. The less any one component knows about any of the other components, the better.
Oh.
So, I am about to almost rewrite the class the way you suggested.
The less your User object knows about the rest of your system, the easier it is to move it to a different system, without altering the code.
10:53
But can you explain the idea of Mapper?
Sure
The Mapper's job is to be the... mapper... between the object and storage.
The mapper is aware of only two things, your object (that is the User) and the storage (in your case, the database).
Can you please put it into some simple code and explain it to me?
I dunno why but my brain doesn't process English.
My brain only processes PHP.
@HassanAlthaf Hehe, where are you from?
@MadaraUchiha Sri Lanka.
@HassanAlthaf Hmmmmm, trying to think of someone I know from Sri Lanka....
10:56
Why?
To translate or something?
Nope, can't remember XD
No, just for fun
LMAO
Can we keep in touch via skype or something?
Don't really have skype, and I'm at work now, so not really no :D
Ok, can you do me a simple code demonstration of
The mapper 'idea'
In any case, think of the object as a black box. Your mapper will have two main methods: save and fetch. Save saves a single object to the database, and fetch gets one object from the database. Doesn't matter how for now.
With OOP, it's best to not try to understand how and object works first, but what it does.
After you understand what it does, the idea behind it, then you can dive into code and see how it does it.
11:00
Ok?
I am gonna work hard and try to squeeze that idea into code.
@HassanAlthaf So what a mapper basically does, is to map your objects to your storage.
It can save and fetch objects from database.
In non technical terms?
@HassanAlthaf At its most basic form, it will be the only one with SQL queries in it.
It would be the only thing that is responsible for storage.
That way, the User object is not aware to anyone. "Someone will fill me with details, I don't know and don't care who".
11:03
0
Q: Sorted array to a Binary Search Tree

user3748727I have pasted the following code from VS: What wonders me is that I'm not getting elements in root.left and root.right. class Node { private int data; public Node left; public Node right; public Node(int dat) { ...

The UserMapper is aware of the User and the database "someone asked me to go to the database and return this User object from it:
Oh well well. I will just try this out first.
And the UserService is the higher level "admin" for both of the other classes. It is aware of the User and the UserMapper. "someone asked me to register a user, so let's make a User object with the details, and then have the UserMapper place him in the database!"
Oh, you are good in explaining man.
I'll rewrite the class now according to your ideas.
Give it a shot ;)
If you have problems with developing, Stack Overflow is the correct place to ask (they have chat too)
11:08
So.
You are saying only the UserMapper is the class that has access to database?
@HassanAlthaf Correct
Ok, cool.
This way, if tomorrow you want to move from mysql to PostgreSQL, or to files, or to Rest API, you only need to change one part of your app
The mappers.
Yeah. Nice idea.
@MadaraUchiha can you make an instance of a class inside a function?
@HassanAlthaf What do you mean?
11:17
Like
$user = new User(); inside a function
?
@HassanAlthaf You can, yes.
Ok, cool.
Well, would it be good
On most cases, it's better the pass it in the parameters though, depends on the situation.
if I make an instance of that object in the getAndSet function?
Well, to pass the data from getAndSet, how would you do it?
@HassanAlthaf What's the point of getAndSet?
11:21
Funny... I revisted a very old PHP script I made years ago, and now it complains because myw ebserver upgraded I suppose
To get the username, and fetch the data of the user, and assign the variables the value of the information
like get the password and set the $password variable with that
@HassanAlthaf That's the fetch method in the Mapper.
I know.
Well, I did like this for login:
In the user service
What I usually do is to pass a User object in, with the $id field already filled in.
What do you mean?
Example code?
11:22
$user = new User;
$user->setID(42);
$this->mapper->fetch($user);
I dont get it.
@HassanAlthaf What aren't you getting?
So, i make that user instance in the last lines.
The last "$this->mapper->fetch($user)"
So once the user logs in successfully, we only know their username and password.
@HassanAlthaf Right
So you have a method in your UserService called handleUserLogin($username, $password) {
Which will do something like
$user = new User;
$user->setUsername($username);
$user->setPassword($password);
$user->hashPassword(); //Forgot to hash the password!
$this->mapper->fetch($user);
if ($user->isAuthenticated()) { /* successful login! */ }
else { /* error! */ }
i dont understand what is happening in the mapper->fuetch etc
11:28
@HassanAlthaf mapper->fetch takes the object, reads all the properties, and constructs a query to get the user based on those parameters
so what is mapper?
@HassanAlthaf mapper is the UserMapper object
oh.
and the fetch method fetches all the data.
@HassanAlthaf Correct
And how to assign it in User class?
11:29
You give it a partial User object, and it fills the rest of the details in.
User::Rank = $rank?
In the fetch() methof
public function fetch($username) {
$query shit here..
User::Rank = $rank;
User::ID = $id;
Or you create an instance of the User class?
@HassanAlthaf I usually pass in an instance to begin with.
ok cool. :)
11:31
public function fetch(User $userObj) {
   ...
I understood everything. Once I'm done, I'll put it back on CodeReview.
I don't have much time today, I'll do so on Saturday.
@HassanAlthaf Cheers. In a new question please, it's better that way. And link to your old one :)
(Only permitted on laptop on weekends).
yeah ofc @MadaraUchiha
Expect that on Friday or Saturday.
Awesome :)
0
Q: Platform independant thread pool v2

Tom MylesThis is a continuation of this question. Taking into account the advise given by Loki, an implementation of the threadpool using a std::continuation_variable to control when threads wakeup is presented below. Using this, the test program eventually deadlocks, the time before deadlock occurs is d...

11:39
Monking!
Monking @SimonAndréForsberg
Monking @Vogel612
@MadaraUchiha $query->num_rows == 1 ? true : false; would that work?
@HassanAlthaf $query->num_rows == 1 is a boolean, no need for ? true : false;
wht do you mean
$query->num_rows == 1 true: false?
11:41
@HassanAlthaf 3v4l.org/lNq64
I am using ternary ops. instead of if ()
nonoon..
$query->num_rows == 1;
@Vogel612 much better :D
@MadaraUchiha well I am a java-guy, soo...
@Vogel612 So you do Object . method();?
11:46
noooo...
but. it's a friggin arrow and not a .
0
Q: multithreaded file downloader using threading and signals

sanThis is my first attempt to write a multithreaded application that downloads files from internet , looking for improvement in code, logic and better strategy for implementation Please ignore the pylint messages which is not the focus at the moment. to manually test you can use the urls from the...

also i doubt that would work...
@Vogel612 By itself it won't do anything
but you can do return $query->num_rows == 1 like in any other language.
btw: () = x -> x.stuff is (maybe) a lambda, so in Java the arrow is an operator and not a [...]
thingy..
12:16
@Vogel612 In Java that would be either () -> x.stuff (no lambda params) or x -> x.stuff (one lambda param)
12:33
Hey @Simon ... hmmm.... s.charAt(x).equals('a')
Hey @rolfl
Yes. That. I don't see how that can compile
@SimonAndréForsberg didn't get lambdas so good either way...
480 mugs on the wall btw
I <3 Lambdas
I've almost forgotten what coding Java was like without them
I am getting used to them, but don't like the performance implications
I can see a future where the Java performance experts will spend their days unwinding lambdas and replacing them with pre-lamda features.
can anyone here give me a helping hand with some Java XML parsing problem?
12:46
Are they that bad for performance really?
but beware, I am very bad in Java
What's the problem?
I have an external program that I call with some inputs and it returns an xml output that I have to parse
@Nobody - I happen to know a little about Java and XML parsing
so I looked for XML parsing in java and settled for SAX implementing a ContentHandler
12:48
But, you may want to take my advice with some ..... caution
@Nobody XML parsing? Sounds like a job for DOM
Does Java not provide libraries for DOM handling?
DOM, XPath, etc?
@Nobody When I do XML parsing in Java, I normally use the Jackson library. Then I get the results as POJOs
@MadaraUchiha you do know that @rolfl is the maintainer of JDOM?
@MadaraUchiha: I followed the advice here: stackoverflow.com/a/373935
I want to avoid as much dependencies as possible
@Nobody How complicated is the resulting XML
And what do you need to do with it exactly?
12:50
very easy
OK, leaving aside the dependencies, there's two basic models you should consider, and one you should avoid.
<elements><element></element>...</elements>
I don't know of SAX, but DOM is a widely known and widely implemented solution.
Do you want to process the data as it comes off the stream using a state machine? use SAX.
I simply need to read some attributes of the <element> and the text data it contains
12:51
if you want to get the whole document in memory, which will be slower (latency wise), and limited by your memory size, then use DOM, or a variant.
Don't use StAX
for each element
SAX is complicated to write.
so far I found it easy but now I hit a wall and wanted to check if my assumptions are correct
DOM is easier to navigate than SAX.
I don't need any navigation
12:52
OK, SAX is a good lesson to learn
it is simply: hit an "element"? -> read 2 attributes and the contents and store them in a list
OK, that should be easy enough
so I derived from org.xml.sax.helpers.DefaultHandler
Good start.
and override startElement, endElement and characters
12:54
to get the attributes you should not need to override characters
I scrape the attributes from startElement
@rolfl: Is it an attribute as well or where does it come from?
just to make sure I am using the right names: <element>This is the content</element>
<element attribute1="val1" attribute2="val2">characters</element>
okay, so I want the characters (which is what I meant by "content")
Ah, I see that now... misread it.
I read 'contents' to be the contents of the attributes....
so I need the characters function?
12:57
yes
okay, then let me go on:
in the startElement function I set the boolean currentNodeIsElement to true or false depending on the qname of the element
and store the two attribute values in integers

« first day (414 days earlier)      last day (3901 days later) »