« first day (712 days earlier)      last day (3602 days later) » 

17:01
@JeroenVannevel I believe @rolfl needed to wait longer on his optimized queries at some point ;)
@JeroenVannevel If your program has been tested on small examples and works there, then you might well be prepared to wait a while for a larger example to complete
Apparently this is not valid SQL: MIN(p.CreationDate WHERE (p.PostTypeId = 2 AND p.ParentId = q.PostId))
@Hosch250 You want a HAVING statement.
OK, thanks.
min(p.CreationDate) having (rest)
No?
17:06
@GarethRees That explanation is pretty poor, indeed
WaIT.... No. @Hosch250 is that all of the code?
@sᴉɔuɐɹɥԀ The example makes things no clearer!
Of course not.
SELECT q.UserId
,MIN(q.CreationDate)
,MIN(p.CreationDate) HAVING (p.PostTypeId = 2 AND p.ParentId = q.PostId)
,q.PostId[Post Link]
FROM
  (
  SELECT
  MIN(p.CreationDate) [CreationDate]
  ,MIN(p.Id) [PostId]
  ,MIN(u.Id) [UserId]
  FROM Users u JOIN Posts p ON u.Id = p.OwnerUserId
  WHERE (p.PostTypeId = 1 AND u.Id = 34073)
  GROUP BY u.Id
  ) q
  ,Posts p
GROUP BY q.UserId, q.PostId
ORDER BY q.UserId
That doesn't work either.
Omg no.
Everything works but that line.
17:08
I will help you... But not until you CTE.
CTE?
You need a subquery or a CTE to do that.
Put your HAVING at the very end, between GROUP BY and ORDER BY
Common Table Exrpession
Oh, OK.
OK.
Sure, whatever you say.
17:08
Don't help him until he CTEs that hot mess...
Subqueries are fine too, some DBMS you can't do CTEs so it's good to know both ways
cough cough MySQL cough
Does the SEDE support CTE?
@Hosch250 you need two different datasets to do what you're trying to do.
17:09
I know, but sub query is just as easy. It's just way messier, so if he wants help, let's unmess it a bit.
Yeah, I knew that much.
That is where I started going wrong.
@nhgrif That's what Code Review questions are for :)
I've found a MSDN page on CTE's.
hmm, I would have thought the p.ParentId = q.PostId would be a condition on the join with Posts, and the p.PostTypeId = 2 could either be part of the join condition or a where clause
@Hosch250 what?
17:11
but I would use ANSI joins for that
@Hosch250 This is the logical order SQL SELECTs should be written, good to memorize:
It seems to be a common problem that people are unable to explain clearly what their program is supposed to do. I guess that's why problems are good to review — at least you can find and read the original problem description
- SELECT
- FROM
- JOIN
- WHERE
- GROUP BY
- HAVING
- ORDER BY
I don't know what the 2 people who upvoted the question were thinking.
@GarethRees I'm one of the two; I usually do on first posts if it's on-topic, out of habit
Didn't notice until you pointed out that the explanation was not good; I thought maybe it was a Python thing
17:14
@sᴉɔuɐɹɥԀ I read the question to see if it is even vaguely comprehensible — surprisingly often it's not
@GarethRees Surprisingly?
Autocorrect failed him.
I still feel like I deserve a medal for figuring out what this program was supposed to do
I sense much sarcasm in the force
WITH FirstQs(CreationDate, PostId, UserId)
AS
(
  SELECT
  MIN(p.CreationDate) [CreationDate]
  ,MIN(p.Id) [PostId]
  ,MIN(u.Id) [UserId]
  FROM Users u JOIN Posts p ON u.Id = p.OwnerUserId
  WHERE (p.PostTypeId = 1)
  GROUP BY u.Id
)

SELECT UserId
,MIN(CreationDate)
--,MIN(p.CreationDate) HAVING (p.PostTypeId = 2 AND p.ParentId = q.PostId)
,PostId[Post Link]
FROM
  FirstQs
GROUP BY UserId, PostId
ORDER BY UserId
OK, I have this now.
I think I can finish now that I know about this.
17:17
Come on... people have been using Hibernate for years, and then this
Adding this to favorites (I would like to see the anwser) — gtgaxiola 44 secs ago
@GarethRees well, you kind of got one. Got a badge at least =;)-
Nobody is going to tell me that nobody has asked the question I have asked yet... I hope
@Hosch250 Nice work, that looks much cleaner
@Hosch250 that having makes no sense.
Probably not.
17:19
@Hosch250 Great, now create another that returns this information
(p.PostTypeId = 2 AND p.ParentId = q.PostId)
@Hosch250 Here is a hint. You can join tables to other tables, but you can also join a table to itself to make 2 data sets ;)
How do I connect two of them?
It says something about a semicolon.
With glue.
2
);

WITH FirstQsA(ACreationDate, APostId, AUserId)
NVM, Bing will tell me.
17:22
in this case, though, the CTE filters to PostTypeId = 1, and he's wanting to match to a row with PostTypeId = 2
Are you trying to make multiple CTEs?
Yes.
WITH A(stuff), B(stuff), C(stuff) SELECT stuff...
I will be home in 2ish hrs.
Your filters go in the WHERE
17:28
It appears to be working!
That's good
To join a table to itself, you just need to give them different aliases!
SELECT foo.Name, bar.Name
FROM Mytable AS foo
JOIN MyTable AS bar ON foo.Id = bar.Id
Making some progress, but very slowly
It's like pulling teeth here. — Gareth Rees 1 min ago
^^ Seems like it
"I want you to solve my problem, but I'm not going to tell you what it is"
I really don't like simply using JOIN without specifying join type
17:35
@nhgrif I don't either, really. But some people pick on me when I user INNER JOIN because "it's the default anyways"
private class is also the default, doesn't mean you shouldn't declare it, in case the default changes at some point
or in case anyone doesn't know
OK, it returns first questions that have answers within 24 hours.
Now for a code review.
@GarethRees I Googled for "globalized discretization" and it seems to be quite an advanced data mining/data science concept. Perhaps that's why it's difficult to understand, he might be taking a data theory type of course.
Practically everything that came up was a scientific paper. There's not even a Wikipedia page for it.
> The process of converting data sets with continuous attributes into input data sets with
discrete attributes, called discretization, was studied in many papers, see, e.g., [1–3, 5, 7, 10, 11,
13, 15]. We will assume that input data sets contain examples, characterized by attribute and
decision values. A concept is defined as a set of all examples that have the same value w for
decision d.
@sᴉɔuɐɹɥԀ It doesn't seem like an advanced concept to me. It's just putting the data into buckets
Could be, I dunno at this point lol.
17:40
Anyway, if it were an advanced concept, there would still be no hope of reviewing the code unless we know what it's supposed to do
And so no excuse for not mentioning it in the first place
0
Q: Find first questions with answers posted within 24 hours

Hosch250So, sᴉɔuɐɹɥԀ suggested I write a SEDE query to find first questions with answers posted within 24 hours, and here it is: WITH FirstQs(QCreationDate, PostId, UserId) AS ( SELECT MIN(p.CreationDate) [CreationDate] ,MIN(p.Id) [PostId] ,MIN(u.Id) [UserId] FROM Users u JOIN Posts p ON u.Id ...

"Discretization" seems to be similar to "data binning" which does have a Wikipedia article
Hmm, it broke.
I found a nasty 68% cost nested loop in your execution plan, that's probably what is making it slow
And, I think I found the boo boo
Deleted? :\
17:51
It is broken.
Weird. - Or is the data wrong?
For some reason, the data is wrong.
I know what the problem is.
I need to use a JOIN, I think.
How do I get the creation date of the Q when I only have the ID?
@Hosch250 You already did, perhaps without knowing:
FROM
  FirstQs
  ,FirstQsA
  ,Posts p
The trouble is here:
FirstQsA(ACreationDate, APostId)
AS
(
  SELECT
  MIN(p.CreationDate) [ACreationDate]
  ,MIN(p.Id) [APostId]
  FROM Posts p JOIN FirstQs ON CreationDate = p.CreationDate
  WHERE (p.PostTypeId = 2 AND p.ParentId = PostId)
)
It only returns the value for the top item in FirstQs.
This is my newer version, but it won't work.
I would suggest to move your join logic outside of the CTE
17:57
NVM, I have it.
Testing...
Darn it!
It is only returning one answer!
Welcome to SQL :)
It is returning the answer to the first question.
0
Q: Is it possible to further optimize this bitstream reader code?

Brendan LongI have a program which reads and analyses MPEG-TS files. I've been using gperftools to identify hotspots and optimize them, and 45% of all samples at this point are in my main bitstream reader function. I've already: Reduced the number of overflow checks to one per call (not shown here, since ...

17:59
And that answer is the only one returned for all rows.
13 hours ago, by sᴉɔuɐɹɥԀ
Just write a SELECT and try to join tables correctly, and apply aggregates & filters. SELECTs are the most difficult, other operations are pretty easy for the most part
wouldn't FirstQsA need a group by clause so it returns more than one row?
Oh, so that is it.
OK, thanks.
18:16
Now it is timing out.
Anyway, I'm gong to have lunch, then do school
@Hosch250 you should probably explain, in plain English, exactly what your query is attempting to do.
Still at it
I think we've managed to explain about half the problem
1
Q: Discretization of continuous attributes for automatic classification

BrassboundBatmanBackground In machine learning, it's common to encounter the problem of making a decision as to which discrete category an object belongs to based on a set of continuous attributes. For example, we may have this collection of observations on three attributes A, B and C, where the decision has be...

@nhgrif Later.
18:28
@GarethRees You, sir, are a very patient man.
0
Q: My first MVC project - finishing the Router

inkdDone a lot of reading today. Here is the completed router portion of the MVC-inspired project I am currently working on while trying to become a better programmer. I'm looking at how other frameworks are doing things and just kind of piecing together what like most. Folder structure: [project] ...

18:56
in TCG Creation, 31 mins ago, by skiwi
I could make a gamlbing game on what error I'll get first
@DanPantry: are you still doing that UI?
Oh damn I'm so stupid!
I'm using a method $.getJSON of jQuery and was expecting an HTML instead of JSON response
I think I'll use query syntax more often
public async Task<IEnumerable<Highscore>> GetHighscoresAsync(int page, int pageSize)
{
	var results = (from user in _context.Users
					let score = (from answer in user.Answers
							where answer.IsCorrect
							select answer).Count()
					orderby score descending
					select new Highscore
					{
						Score = score,
						Username = user.UserName
					}).Skip((page - 1)*pageSize).Take(pageSize);

	return await results.ToArrayAsync();
}
Look at how pretty it is
Too bad only a few methods are available in it though..
@JeroenVannevel That doesn't just work, right?
With "random () in your code"
There's nothing random about my parentheses, buddy!
This is trialled and tested and works perfectly
What brackets are suspicious to you?
19:07
LINQ query syntax is elegant
@JeroenVannevel Everything looks suspicious!
@skiwi That's just because you Java people have inferior syntax
2
No judgement
@skiwi Just read it from the end to the beginning and imagine it's a SQL query
@JeroenVannevel I still don't believe it works, how?
@JeroenVannevel hmm... let me check how it'd be written in jooq...
19:13
it's really like SQL with a few differences. See that let score? That lets (lol) you define an intermediate variable in your query to store a result of a subquery. It's basically a nested select statement
@JeroenVannevel But how can var results = (from user ... compile?
a from-select query returns an IQueryable so you can perform Queryable extension methods on it: just put parentheses around it and you have your collection to call things on
that's compiler stuff. It creates an expression tree
okay I'm too inexperienced with jooq...
This is the very reason why LINQ is so extremely powerful
Expression trees are abstract trees that.. well.. represent an expression
You can then create providers that translate that to different instructions
You've got providers for Linq-to-xml, linq-to-objects and linq-to-sql
(and more)
you can use this same syntax to query an XML document or a collection of in-memory objects
LINQ is much more than just a few extension methods
0
Q: Identifying a development and production server by http_host

Ronak PatelI am using below code to recognize which set up I need to use in Codeigniter: $dev_urls = array('dev.com'); $prod_urls = array('prod.com'); if(in_array($_SERVER['HTTP_HOST'], $dev_urls)){ define('ENVIRONMENT', 'development'); } else if(in_array($_SERVER['HTTP_HOST'], $prod_urls)){ defin...

0
Q: Utility that decodes and logs UDP packets

Mike Hamer I have written the following utility, as my first non-tutorial program in Go. The purpose of the utility is to connect to a torque/force sensor (aka load-cell) via UDP; to send an initialization command; and to record the resulting stream of measurements. Since I am planning further functio...

19:18
This sounds like C# is superior to Java with respect to that, I cannot allow that
@sᴉɔuɐɹɥԀ From the makers of SNAP... here we present
GTA V for PC is out..
Please be less than 30€ for a change
Ah of course. 60€.
I have a week off (well, it's almost over), but I decided to not buy GTA V for PC even though lots of friends are playing it...
How else would I have time to code and actually have a life?
And 48 euro cheapest is still too expensive, I want 35 euro :/
It really is a lot..
I inquired what exactly is contained in a tutoring session for Acces I saw an ad for
If they just need to write some queries and create a few tables, I can totally do that
19:37
i was interested in GTA V until i saw a bunch of people talking about needing to grind out money in the multiplayer version
@bazola The campaign is still a lot of fun!
not 60 bucks worth, not when it will be on sale soon enough
well GTA is still so fun just to do crazy things around the town! But I can understand why people don't want to pay 60 bucks for the single player!
@bazola What about money in MP?
@Hosch250 Let me know once you got your query working. I made one for the same query but in a different way, execs in 400ms or so.
19:45
@JeroenVannevel people were saying they had to run some mission with some random people online and got 23000 cash or something for beating it, and they were pretty excited about it.. doesn't sound like the GTA that I am interested in playing
sounds like an MMO grind is what i mean
@Marc-Andre i like the ones like saints row, just cause, and crackdown where you have godlike powers
Well, luckily I'm only interested in hitting people with cars
2
@skiwi is learning to do that too ^^^
@rolfl Hey... That wasn't what I am supposed to be doing!
You're taking driving lessons, right?
Yes
19:47
Q.E.D.
0
Q: Split string by substring without using String.Split()

UnderscoreThe Aim Since I very rarely write code to do things other than business logic any more I've set myself a challenge: Split a string into a list of substrings by splitting on a matching string, without using string.Split() or similar methods of string (substring, indexof, etc). The method must a...

@bazola You can safely ignore the multiplayer modes and get way more than your money's worth out of the game
Got the Pop Question badge for my latest question.
@skiwi Does it really matter which is better between these two?
20:02
@nhgrif It matters as much as we want it to matter
Yes, but neither are Swift... so really, how much does it matter?
@nhgrif All of them can give you Brainfuck if you're not careful
> ReferenceError: skiwi2 is not defined
Nooo!
20:32
0
A: Save File Manager

nhgrifYour organization is a bit confusing. TCFileData is a hacked attempt to force abstract classes into a language without abstract classes, and TCFile is a hacked attempted at creating a namespace for a language that doesn't have namespaces, and your use of generics here seems unnecessary. I think...

@Hosch250 How is the query coming?
@JeroenVannevel What does the async keyword do?
It will execute that method on a new thread. You just await the method and it will be executed asynchronously
no hassle with multithreading at all
Show me how it'd be called?
Just like normal?
var result = await MyAsyncMethod();
Can you call it without await?
async methods return Task or Task<T> depending if they're void or non-void
You can, but then it's like fire-and-forget
you execute it and it just does its thing in the background
if the program exits before the thread is finished.. it's a little messy
20:42
So... hmm...
You say no hassle...
0
Q: Creating an array length n * n, separating it into n groups, and adding numbers to it n times

alanbuchananI am completing the CodingBat exercises for Java. Here is the one I have completed just now: Given n > = 0, create an array length n * n with the following pattern, shown here for n = 3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups). Here is my code: pub...

All you have to do is return Task<MyObject> instead of MyObject, mark the method as async and use await when you call it
That's nothing
Right... except now you need a synchronous and asynchronous version of your methods...
You can execute asynchronous method synchronously if you want
Just use var result = MyAsyncMethod().Result or var result = MyAsyncMethod().Wait()
Well then that isn't too terrible.
Of course, that approach only works when you just need some non-blocking stuff.
20:47
TPL (Task Parallel Library) is really strong and the major change in C# 5
I think I'd still prefer the Objective-C/Swift approach, of course.
of course
let queue = NSOperationQueue()
queue.addOperationWithBlock() {
    // do stuff on this background queue
}

let mainQueue = NSOperationQueue.mainQueue()
mainQueue.addOperationWithBlock() {
    // do stuff on the main thread
}
Of course, there's an NSOperation object, so you can just create an NSOperation object, and call queue.addOperation(op), or you can create an array of operations, and add them all at once.
queue.cancelAllOperations()
You can set (or get) the maximum concurrent count.
Get the count of remaining operations on the stack (or just get a reference to the operation array)
But the real power comes when you start diving into the NSOperation class itself.
21:03
I'm not versed enough in multithreading to say many meaningful things about it
All I can say is that I love what the TPL provides for me
No UI blocking stuff by using 3 keywords
Is there an easy way to add stuff on the main queue from the background?
What do you mean?
Hmm, maybe it's sort of unnecessary the way it works.
But you know you can't update the UI from the background.
Oh, that's no problem. Just pass in an IProgress<T> to your method and you can report through that
Yeah... ...
21:06
In WinRT this is combined together with Task
This seems fine for relatively simple stuff for just the sake of not blocking the UI.
and in things like WPF you can just use Dispatcher.Invoke(() => { /* ui thread */ })
everyone must be out of votes, I haven't gotten any votes in a couple of hours....and we all know how awesome my answers are, right?
Hello. I'm interested to see how codereview develops. Just dropping in to say Hi
I long ago abandoned SO
Hello, @AidenBell!
21:14
Hello @SirPython
Im hoping this replaces SO, which I long ago sort of gave up on
@AidenBell Hey @AidenBell welcome to The 2nd Monitor :)
Well... this doesn't replace SO.
They serve different needs.
as an answerer
finding interesting things to answer
or review
"replaces SO as something to do in the evening"
That, it does ;)
21:16
In case anyone, as a voter, is looking for a replacement to SO, I present you:
2
A: Save File Manager

nhgrifYour organization is a bit confusing. TCFileData is a hacked attempt to force abstract classes into a language without abstract classes, and TCFile is a hacked attempted at creating a namespace for a language that doesn't have namespaces, and your use of generics here seems unnecessary. I think...

I see you have a really good PHP score on SO, there are tons of unanswered PHP questions here!
Meh I dislike PHP
no PHP is clean PHP :P
Welcome to the club lol.
Php designers Hate Programmers
My only concern here will be keeping quality up as good code review is harder than answering SO questions I think
@nhgrif too true
21:19
Does anyone want to move my stuff from one city to another?
@nhgrif Depends how many cases of beer are in the balance
For your enjoyment
If a function is 1 line and it's well-named (here it's just "silly_case"), and there's test coverage for that function, do you still find that 1 line unreadable? If anything I might change (len(input_string) + 1)/ 2 to pivot_index and perhaps move "".join(string_as_list) to its own line but otherwise this seems like a straightforward list comprehension to me. — Scott Lobdell 2 hours ago
the thread is funny
I agree, that's bad style
Looks like the answer is sacrificing readability for the sake of brevity. Not sure how I feel about that.
See the comments /facepalm
21:24
I don't see any redeeming qualities for "brevity"
"Yeah I made it harder to read, but now you have 20 less pixels used!"
I dunno how he can put an argument forth for that
Definitely deserving of my DV
@nhgrif Not so great, I haven't done any more work on it.
Maybe it's like go faster stripes on a car ... must be better because it's on one line!
Just came back from an accounting test, and just going to read a chapter or two in different textbooks.
21:26
Probably at least two, right?
How can you read one chapter in two books?
also, any feedback on this answer?
http://codereview.stackexchange.com/questions/86961/app-for-displaying-pictures-to-like/87005#87005
I don't think Sqlite is so simply and automatically multithread safe.
I think it's pretty good. Perhaps Point 2 (sanitization) would be deserving of a short example
@nhgrif it locks the entire db iirc when writing
The entire DB?
21:29
so while not performant it should be safe
yes
@rolfl Post IDs and Post Creation Dates can be in different orders? Right?
I would expect a page lock, maybe a table log, during a transaction and whatnot, but whole DB... wow.
@sᴉɔuɐɹɥԀ SQLite is not intended for multiple access at the same time. In reality, your application should probably have a dedicated SQLite thread...
@nhgrif Yes. It is odd, but can happen
21:30
Okay, thought so.
Can you open a single file twice with write access? I'd expect that to just throw an exception from the get-go
@nhgrif Ah OK, makes sense. Like a DB that's shipped with an app that is only for the user's data eh?
@nhgrif Mostly related to migrations and mergers.
Right.
@sᴉɔuɐɹɥԀ Yes.
Anyway sqlite was recommended as some cheap atomicity with an intro to SQL
21:32
It's just an efficient way of saving stuff locally.
Beats his JSON files I think
anything else would seem overkill
You shouldn't even have multiple applications on the same machine accessing a SQLite database, nevermind multiple machines over a network.
Ah ok. I should read a bit about SQLite, seems like an interesting product.
True, but you can have multiple requests served off an sqlite db
And, if I were using a SQLite database, I'd probably just have a dedicated SQLite thread.
21:33
for example, Django offers sqlite as a backend
all valid points, but for the scope of what it is replacing, recommending any other RDBMS would be way too much I feel
I don't think I'd even bother with SQLite.
Oh wait, nevermind.
"Yes, SQLite handles concurrency well, but it isn't the best from a performance angle. From what I can tell, there are no exceptions to that. " from stackoverflow.com/questions/4060772/sqlite3-concurrent-access
concurrency isn't too much of an issue and I think it serves his purpose well
Of course, his query can always be likes = likes + 1 so he doesn't even ever have to read the current likes (when updating them)
I would wager the performance would only be an issue if there frequent Sql connections opened and closed
I'm not sure his script will be handling anything approaching the performance/IO limits of the db
even sqlite
;)
21:37
SQLite is kind of a pain in the ass.
@sᴉɔuɐɹɥԀ an issue with any writing as it locks the entire DB
@nhgrif it backs Firefox's local storage, it is pretty robust
SQLite is used in a lot of places. That doesn't make it any less of a pain in the ass to develop with.
I'd never use SQLite in any Objective-C or Swift application.
True, I might be biased as it is the workhorse of my day-job
I'd use CoreData (which is backed by SQLite).
Because CoreData is easier to work with.
Dunno, slap any ORM on it and I don't care
21:39
But my apps just talk directly to Microsoft SQL Server.
Really cool Q & A here
3
A: Generating Unique Colors

Ben AaronsonThere's not much code here, but I think it can be pretty cleanly divided into two parts: Generate three bytes for a color from an integer Have a way of getting multiple integers which are guaranteed to be unique Simple as your algorithm is, you're already running into limitations by coupling ...

Ahah, I was wondering why I suddenly got several votes in a row!
@RubberDuck and his sockpuppet accounts
I like the : IEnumerable
@BenAaronson Hahaha, the pimp effect eh!
Yep, any excuse to type ": IEnumerable" makes me feel warm and fuzzy
21:50
That ^
Deadline for the Riot API challenge is tomorrow at noon. There's no UI yet. I suppose I can try to get something to work tonight
0
Q: Generating Calendar month information using JavaScript

Prathap ReddyI am using below function to set month information on context passed. It is working fine, but please review it and let me know if any potential flaws or any improvements in this code // Expects month to be 1-12 index based. prototype.monthInformation = function(year, month){ var date = ne...

How hard can it be to make an Android app after all
Okay, so if I've done my query correctly, there are 8,670 questions, which were the first question asked by that asker, and received an answer within 24 hours.

« first day (712 days earlier)      last day (3602 days later) »