« first day (433 days earlier)      last day (3584 days later) » 

7:20 PM
Note to self: normalizing data from flat files is not something flat files were designed for.
Trying to break "Orders" into "OrderHeaders" and "OrderDetails"... all kinds of weirdness ensues..
 
What does a row look like @Mat'sMug can you copy/paste the column headers?
 
1
Q: backbone.js boilerplate

Simon HarperI am currently experimenting with a backbone boilerplate application and would really appreciate some feedback or thoughts on its structure. I come from a PHP background so am used to frameworks such as Codeigniter and Zend. I've always been fairly javascript savvy but only have only recently s...

0
Q: Push elements in array if exists and implode them later

Radu MarisPlease evaluate this, it is readable enought ?, can it be improved ?. $array = array() if ( $isA ) { $array[] = $a; } if ( $isB ) { $array[] = $b; } // DO something with the array, but only if at least one element is set if ( $array ) { $like = implode($array, ','); } I think the...

 
Also yes, flat files are not very good at anything except holding a bunch of text
 
ugh, I wasn't selecting the correct field...
f5 instead of f25...
f5 is the order number...
f25 is the order type
 
@Mat'sMug Holy mess!
@SimonAndréForsberg Good point, my first time here. I will try to improve it. — Radu Maris 46 secs ago
He bought it!
Welcome to Code Review! Unfortunately, it's a bit hard to review code like this because the code you are showing is example code rather than code that you're actually using in a real project, which means that a lot of context has been stripped away. Unlike Stack Overflow, we prefer to look at real code instead of example code. — Simon André Forsberg 2 mins ago
 
7:36 PM
^^ Nice!
 
@Phrancis now I need to stick a CASE WHEN on the ...JOIN's ON clause...
 
@Mat'sMug the columns aren't even named to label what kind of data is in them? bleh
That don't sound fun
I've never seen that done, be curious to see how you do @Mat'sMug
 
@Phrancis columns? lol the tables are like YYF041, YYF121, etc.
 
^^ Yikes
 
from
	`Mine`.`YYF391`
	left join `Mine`.`YYF361` ON `Mine`.`YYF361`.`f2` = `Mine`.`YYF391`.`f5`
	left join `Planning`.`OrderTypes` `ot` ON CASE WHEN `Mine`.`YYF391`.`f25` = 'P' THEN '0' ELSE `Mine`.`YYF391`.`f5` END = `ot`.`Code`
	left join `Planning`.`Customers` `pc` ON `Mine`.`YYF391`.`f4` = `pc`.`Code`
	left join `Planning`.`Seasons` `ssn` ON `Mine`.`YYF361`.`f12` = `ssn`.`Code`
seems to work
 
7:40 PM
@Mat'sMug Are you sure you don't miss your old job?
 
dammit, doesn't
@SimonAndréForsberg lol 100%
 
Alright, just checking :)
 
@Mat'sMug why all the back ticks? Those are not needed
 
those are just flat file extracts, once I make sense out of it all I'll have a whole normalized db for me
@Phrancis another MySQL annoyance
 
from Mine.YYF391 left join Mine.YYF361 ON Mine.YYF361.f2 = Mine.YYF391.f5
 
7:43 PM
@Mat'sMug You don't need to always apply backticks AFAIK. Only when it's colliding with a keyword and perhaps in some other occasions.
 
I really don't understand what you are trying to do, can you word it in human language?
 
@SimonAndréForsberg or when you have a space or operator in your column name (which is obviously bad practice)
 
I have a table called "OrderTypes" that I want to relate to YYF391.f25 (to get an OrderTypeId value instead of a code), but that field has errors in it and I need to substitute a value before I do the join.
I think I'm better off making the YYF391 selection a subquery, and make the substitution there
 
^^ that
And for the love of gods do yourself a favor and write the code by hand instead of using the GUI :)
You could also just find the erroneous values and just do one big UPDATE YYF391 SET f25 = 'Foo' WHERE f25 = 'Bar';
 
7:49 PM
I am writing it by hand, it's just I started off with an existing view (which has aliases for the fXX columns!)
 
Wow.
Who designed that process? WTF.
 
there's basically nothing in place, I'm designing it!
there's this rusty flatfile-based system, and an overnight process that sends the flat files' contents into a MySQL database; they built views on top of that, that's all!
 
@Mat'sMug That must feel good!
 
ah, works!
from
	(select `Mine`.`YYF391`.*, case when f25 = 'P' then '0' else f25 end OrderTypeCode from `Mine`.`YYF391`) as orders
	left join `Mine`.`YYF361` ON `Mine`.`YYF361`.`f2` = orders.f5
	left join `Planning`.`OrderTypes` `ot` ON orders.OrderTypeCode = `ot`.`Code`
	left join `Planning`.`Customers` `pc` ON orders.f4 = `pc`.`Code`
	left join `Planning`.`Seasons` `ssn` ON `Mine`.`YYF361`.`f12` = `ssn`.`Code`
@SimonAndréForsberg indeed :)
ugh. insert failed. column 'CustomerId cannot be null... dammit.
 
^^ Forgot AUTO_INCREMENT on your column?
 
7:55 PM
@Phrancis Noooooooo.
Identity bad. Natural Keys good.
=)
IMO
 
@ckuhn203 lol, you would hate my company.
 
@jliv902 It's ok. I hate my company most days.
Idenities have their place, but if you have a good key available, I don't see a reason not to use it.
 
@Phrancis no, it's because of the left join, the customer number doesn't exist in my Customers table for some reason
 
Does MySQL have a NVL() function like oracle?
 
0
Q: Simple password dictionary attack script

Dai Nguyen-VanThis is my simple Perl script implement password dictionary attacking, encryption algorithm SHA1 with different length. It takes 2 arguments as input: first argument is password dictionary file path, the second one is a text file contains line-by-line encrypted text. I used 2 common dictionaries ...

 
7:58 PM
or TSQL's ISNULL()?
 
and all my tables have an Id PK (auto-increment), a DateInserted and a nullable DateUpdated
@ckuhn203 ifnull
 
=)
 
We don't have a DateInserted for every table. We typically throw it into at least one table per database though.
 
I'm a fan of willy nilly database nondesign. It makes life soooooooooo easy. lol
Does anyone know if javascript has enums?
 
Seems like it. link
or maybe not. The comments seem to suggest there isn't a standard enum
 
8:05 PM
yay, found an order for a customer that doesn't exist anywhere!
...from 1995
 
@jliv902 Close enough for government work. Thanks.
@Mat'sMug lol
Good stuff.
 
@jliv902 That is technically not an enum, but it can be used like one.
I think that this:
my.namespace.ColorEnum = {
RED : 0,
GREEN : 1,
BLUE : 2
}
becomes an object with three properties: RED, GREEN and BLUE.
 
Yeah I realized that after reading the comments in that link. I've never used HTML, Javascript, or any of that fancy scripting mumbo-jumbo.
 
Although it seems like by using Object.freeze, you can:
56
A: Enums in JavaScript?

RandolphoBottom line: You can't. You can fake it, but you won't get type safety. Typically this is done by creating a simple dictionary of string values mapped to integer values. For example: var DaysEnum = {"monday":1, "tuesday":2, "wednesday":3, ...} Document.Write("Enumerant: " + DaysEnum.tuesday);...

@jliv902 mumbo-jumbo certainly is the word, but I'm not sure if "fancy" is the word :)
 
I prefer my languages to compile into executable machine code. =)
 
8:18 PM
@jliv902 I prefer my languages to compile into executable byte code :)
 
I just prefer my code simply compile.
 
If it compiles, ship it.
2
 
@ckuhn203 I also put a unique index on the natural key
 
Ship it even if it doesn't compile @jliv902. We have money to make here.
 
let the users test it
 
8:26 PM
@Mat'sMug If your natural key's unique, why add an Identity? Doesn't make sense to me.
 
Prayer Driven Programming: Ship the program and pray that it works.
6
 
Unless you think it could change.
 
@ckuhn203 because the natural key has a meaning outside the DB, the PK doesn't.
all FK's are referring to PK's, not natural keys
faster joins
especially when your natural key isn't an int
 
hey
 
ehhhhh ok. I'll bite. But only because I've seen you code.
 
8:28 PM
Hello
 
I'd question the shit out of most people doing it.
 
lol
hey @jliv902
 
After having a business meeting, I feel like I'm in a good position now already while still studying. I just need to make some damn things to prove my capabilities.
 
I'm going to end up reviewing my own question. I screwed some thing sup.
 
@SimonAndréForsberg compiles into executable byte code, and you could even find people crazy enough to make it run on the
 
8:32 PM
@skiwi You gotta be kidding me?
 
@SimonAndréForsberg Not even kidding. Though I do not know of anyone who has done that.
 
TTQW - later @all!
 
Why does PHP have such a bad rap? I've only heard terrible things about it.
 
because it's PHP
2
 
See you @Mat'sMug
 
8:35 PM
and if you go OOP with it you get
 
I once tried PHP OOP, I got an out of memory error.
 
I think PHP gets most of its bad rap from the lack of skill/care with which PHP programmer code
3
 
@Phrancis And that it runs on very poor servers
I for a matter of fact may start with PHP using professional frameworks in the future, I don't think bad of that with people who know what they are doing on servers which know what they are executing
Though my love will always be with Java.
2
@SimonAndréForsberg Did you hear about the new planned experimental Java stuff yet? (Not scheduled for Java 9)
 
@skiwi Nope, what stuff?
 
They're aiming to have lots of stuff possible, but I can give you one excerpt
List<boolean> = new ArrayList<boolean>, having the performance of a BitSet.
I think it's awesome
It means that you'll be able to use generics together with primitives (and value types)
And you can specialize the generics to have a different implementation in specified cases
 
8:46 PM
I haven't used Java in so long. I vaguely remember using Swing and Awt. There was also the funky ? extends stuff.
 
@skiwi What the...
 
@SimonAndréForsberg It looks like magic?
@jliv902 Stuff in future will get a whole lot funkier!
 
@skiwi Well, I understand List<boolean>, nothing magic about that. But... the performance of a BitSet? What... Who... When... How...?
 
@SimonAndréForsberg Optimization magic.
 
0
Q: Manipulating the clocks per tick with an in-game timer

user47947I've created a timer in a game that I'm making and if you run it you can see that it counts 28 times per second and I'm trying to make it so that it only counts up once every second. I tried using the on-tick function at the end of my code by that doesn't give me the desired result. Let me know w...

 
9:00 PM
By this... (All very tentative code)
hmm, no code to copy paste, erm let me find a similar example
class Generator<any T> {
    T generate() {
        // generic implementation
    }
}

class Generator<int> {
    int generate() {
        // int-specific implementation
    }
}
Similarly you could write ArrayList<boolean> using a BitSet in its specification
 
@skiwi Oh, so you would have to duplicate some code for the various implementations?
 
@SimonAndréForsberg Yeah, it's the pain the library makers and the gain for the users.
 
Well, then I can understand how it is done.
Seems like quite a pain.
 
These days are all currently possible, but are much much more verbose
I think that with class BitSetBooleanPrimitiveArrayList extends ArrayList<Boolean> { ... } you can still get decent code in these days, but it's verbose
If you don't specialize it'll just fall back to an ArrayList<boolean> backed by a boolean[]
2,800 rep on CR, I can hit 3K tomorrow!
 
@Phrancis I don't like the idea of pimping my answers. Feels like pleading for upvotes. Other ObjC questions have ended up being hot network questions and not netted as many upvotes as this one too...
 
9:13 PM
@nhgrif I can see why you hold that viewpoint. Think of the big picture though, as in CR in general. Obviously we get much less traffic than SO for example, even though what we do is sort of similar (as in, programming Q&A) in the SE grand schema.
If we all upvote each other it shows we care to have good answers and good questions stand out
 
@nhgrif it's the hot network question thing combined with the fact that it's a really simple question and answer IMO
people are more likely to upvote something they understand
 
As for the idea of posting self-answered questions, I've done this some.
 
people are more likely to understand something that's really short and simple
 
@nhgrif I did notice that, kudos
 
But I'm not sure what would be a good topic to someone who knows nothing about Objective-C.
I thought I had @syb0rg talked into learning Objective-C on the promise that I'd provide plenty of good reviews, and that should serve as a good way to get some relatively simple, yet high quality posts... but I think he got busy with other stuff.
 
9:19 PM
This SQL is very ugly I doubt his PHP is much better but I wouldn't know since I don't code PHP.
 
codereview.stackexchange.com/questions/56632/… <-- I presume this guy will never return. Notice that the question has an edit basically saying "I fixed it"
 
INNER JOIN book b ON bg.book_id = b.id guess that qualifies as Hungarian notation huh.
If you're going to make an alias for a 4 letter table name... ugh, lazy
 
Today was the first day I rep-capped on CR.
 
@nhgrif That can probably be rolled back. It may be a self-answer with more detail, but that itself is not part of the original code.
 
It was edited before any answers were posted.
So I thought it was fine.
And my answer refers to the code from the edit--not the original code.
 
9:24 PM
It looks to me that someone just provided that code, rather than the OP just simplifying it from advice.
 
I just don't think the asker will be returning to mark an accepted answer.
 
Probably not. If you have reviewed that, then I'll keep it.
 
If anyone has an idea for something simple they might want to try accomplishing in Objective-C, I can certainly try doing self-answered questions on these topics.
 
@nhgrif Unfortunately, I think pimping answers is a necessity to get attention to a post. Technically, you don't even have to pimp your answer. You can pimp the question and/or a competing answer as well.
@Phrancis That's "Scottish" notation, not Hungarian.
 
Arguably, I could probably turn this into a CodeReview question:
13
A: When a subclass overrides a method, how can we ensure at compile time that the superclass's method implementation is called?

nhgrifIf we're talking about custom classes, you can add the following to your superclass's method declaration: __attribute__((objc_requires_super)); And if you want to ensure that all of your UIViewController subclasses call a method like [super viewDidLoad];, you could subclass UIViewController...

 
9:31 PM
@nhgrif A Minesweeper game. With possibility to choose the size and number of mines.
 
@SimonAndréForsberg oh right
 
Simon, I was thinking of something significantly simpler than that. Phrancis suggested that I should post some simple self-answered questions so that those of the regulars that know nothing about ObjC could digest some of these smaller/simpler problems in a bite-sized manner if they were interested in learning.
 
@nhgrif Tic Tac Toe? (Non-ultimate)
 
If I were to do a Minesweeper game, I'd want to do it in Swift, since the game itself would be a learning project for me, and I need a project to learn Swift with, as I'll be starting on fully learning that soon.
I think the idea is super simple, with extremely limited scope. Like where the total amount of code would be this or less:
8
Q: Unhandled Exception handler that captures a screenshot

nhgrifSo, whether you're still in the development stages or your app is already on the app store, you always hope your app isn't crashing. But if it is, you want to be sure you've got good crash reports, right? Moreover, if your app is on the appstore, it may not be sufficient to wait around for Appl...

But the concept would be more basic.
 
@nhgrif I would like to make an iOS version of my Minesweeper Flags game. Currently I only have Flash and Android versions of it. That's why I suggested that :)
 
9:35 PM
lol
Well, do you have a Mac and Xcode?
I'd 100% review everything you post.
If you were going to do Minesweeper in iOS, UICollectionView is a really good starting point.
 
@nhgrif I do. I did start making another game for iOS some years ago but never finished it. And if I would do it today, I would consider using a cross-platform solution (such as RoboVM, XMLVM, or PhoneGap)
@nhgrif I'll try to remember that one. Sounds like a neat class.
Speaking of pimping, as we talked about before, I feel that this question has received very little attention today:
3
Q: Custom grid view with different columns

Dedaniya hirenkumarI am developing a custom grid view with different columns. EDIT: Here View Possibilities Mockup Here is the full demo. You can directly use it, with Internet uses permission. This works perfectly but I want to optimize it. MainActivity.java package com.example.rtrt; import java.util.Arra...

 
so, Android has ListViews.
and the iOS equivalent is a TableView.
A collection view is the same thing, except it's rows and columns.
I don't know if Android has something like that.
 
@nhgrif GridView
 
Ah yeah.
Yeah, so the way the code looks here: developer.android.com/guide/topics/ui/layout/gridview.html is part of the reason I don't really care for Android. Heh.
Specifically when you're doing stuff such as creating listeners.
I just really like the way Objective-C deals with it.
I mean, somewhere, deep within the framework, there's a listener.
But seeing stuff like this: }); bothers me. You see it occasionally in Objective-C too... but I try to avoid it. And in Objective-C, it mostly can be avoided.
 
@nhgrif I do wish Android would support Java 8 completely, creating listeners becomes so much easier then.
 
9:45 PM
In Objective-C, your UICollectionView object has two properties.
 
@nhgrif With the release of Swift and XCode 6, that also caused me to stumble. Now I'm not sure what language to pursue.
 
Either, syb0rg. Objective-C is unlikely to die any time soon. XCode6 and Swift is not yet stable. And either way, the biggest difference between the two is syntax. You're still using the same Cocoa Touch framework in both languages.
 
One of the properties is the datasource. It can be an object of any type that conforms to a protocol (protocol is similar to Java interface). When the collection view needs to know how many rows/columns, what to put in each row, etc., it calls a corresponding method on the data source.
 
@nhgrif True. I'm downloading XCode 6 right now, which should really get me going with Objective-C and Swift.
 
9:48 PM
The other property is the delegate, again, an object of any type that conforms to a different protocol. And when the user interacts with the collection view in some way (tapping a cell), the collection view calls a method on the delegate to let it respond to the event.
So it's not some anonymous function you've created inside a method call inside a method inside your activity. It's an actual method of whatever class you're using as the datasource/delegate. It seems much cleaner that way to me. And you can call it outside of the collection view calling it if you want (which avoids repeating code).
 
Call me "PROCEDURE" Phrancis ;)
0
A: Optimizing Laravel Eloquent Multiple Joins

PhrancisSQL formatting Your SQL script in my opinion could use some indentation and a few more line breaks. How does this look in comparison? Variable names Table & column aliases are useful. But it is a good practice to use a variable name that at least says something about what the table contains. ...

 
You know what always bothers me about SQL?
Select statements.
 
^^ why?
 
@nhgrif UICollectionView sounds like a reasonable design.
 
SELECT (these columns before you say what tables you're selecting from so you get red squiggles and no autocomplete help)
FROM table
2
 
9:53 PM
@nhgrif In Java 8, you can have an actual method as the delegate/implementation of an interface. this::someMethod is a valid lambda expression.
@nhgrif I guess that's why the LINQ syntax is "FROM table SELECT columns"
 
So it's more like this: NSSetUncaughtExceptionHandler(&unhandledExceptionHandler); where the part in the parenthesis is a pointer to a function?
 
@nhgrif I usually write my FROM statement first personally
 
Yea, I do to, but that's clunky. SELECT * FROM table now go back and replace * with my columns.
 
@nhgrif I do the same.
 
I think the intention is to make it has much like human speech as possible
 
9:55 PM
@nhgrif In Java that would be setUncaughtExceptionHandler(ExceptionHandlerInterface handler) and ExceptionHandlerInterface is an interface (duh!) with only one abstract method, which matches the method reference you give when calling the method.
 
You don't say to someone "From this bad grab this apple"
 
@SimonAndréForsberg The example I showed was an actual usage of the function, not a declaration of it
&unhandledExceptionHanlder() is a function already created in the project.
 
@nhgrif setUncaughtExceptionHandler(this::handleException); then, where handleException matches the interface method.
 
Right.
So there's some of that in Objective-C. Objective-C also has blocks, which is like the anonymous functions.
But the big advantage to the protocol/delegate pattern
 
Or you can write a lambda expression directly. setUncaught(ex -> System.out.println(ex));
 
9:58 PM
If you're using a tableview in iOS, I know how to find the method that handles the user tapping a row. I just search for "didSelectRowAtIndexPath:" because that is the most relevant part of the method name that ALWAYS responds to that event.
 
I meant,"You don't say to someone "From this bag grab this apple"
 
Or, of course, the verbose new ExceptionHandlerInterface() { @Override public void handleException(Exception ex) { System.out.println(ex); } }
 
I don't have to find line A where they set the function so I can then search for the function name.
 
@Phrancis Never talked like Yoda, you have?
 

« first day (433 days earlier)      last day (3584 days later) »