« first day (331 days earlier)      last day (3681 days later) » 

7:02 PM
0
Q: Preprocessing Markdown Documents for Keywords

xdumaineI recently added a feature to my application to serve arbitrary markdown documents from a directory. This is designed to allow authors to populate a folder full of help documents, and be able to view them without any code changes. However, because this is an MVC application, I needed a few extra ...

 
7:34 PM
Grrr
5
Q: Feedback on how custom triggers are listened to and triggered

HyposaurusI have some triggers placing and sizing elements for video controls. It works well enough but mostly through trial and error and I am not sure if there is a better pattern: The full source can be found here: http://jsfiddle.net/Xa93a/ and webpage: https://media.themetacity.com/3/ My biggest iss...

This is not a question worth 5 upvotes
I would rather say -2, than +5
 
7:44 PM
no longer has any zombies!
 
congrats!
 
Now I'll have to work on boosting the answers per question ratio.
 
@konijn What exactly makes the question worth -2?
@rolfl I remember you said that you liked that my Sudoku Java 8 code was "a real use case", I can make you happy that I have come up with another real use case for Java 8 !
And I can actually use Java 8 on it because I don't plan on using that code for either Android or GWT ! Because it is quite processor-intense
Oh, I just realized, I can even use parallel streams!
Now I get excited! :D
 
8:33 PM
@SimonAndréForsberg The code does not run because it is a randomish snippet of the whole code
also, it shows a tiny part of the code, the question cannot be properly answered just from that part
I dont like questions that force you to go read some fiddle
I also mentioned that he should put more code, and got completely ignored
 
@SimonAndréForsberg I can tell, can you? what's the use-case?
 
@rolfl It's for my fighting code, the one I got reviewed a while back.
 
Oh. let me take a moment and gather my thoughts ;-)
Right... emergency trip to the dentist with my daughter.... she bit hard on a popcorn kernel, and hurt a tooth .... great... then the dentist pulls it....
I guess she was right to complain.
Good thing it was only a 'baby tooth'.
Still, CR is much more ...... uhmm.... stable.
 
Ouch. Tell her to not have as much popcorn next time ;)
Speaking of which, I gotta buy popcorn...
 
8:56 PM
I have popcorn. :D
 
have teeth?
 
Yes. :-(
 
@rolfl or @skiwi Do you know of any simple way to repeat a String in Java 8 ? For example, achieving the string "---------------" (of variable size, of course)
 
There is a way... StringUtils, i think
Going to other computer.
 
I know Guava provides the Strings.repeat method but I was curious if Java 8 provided another way, without using Guava or Apache Commons/Lang
String.join("", IntStream.range(0, 10).boxed().map(i -> "x").collect(Collectors.toList())); doesn't quite hit the mark :)
Although it works, it's.... not optimal.
 
9:08 PM
Nope, I have drawn a blank.
 
drawn a blank?
 
The fastest way I have done this with regular Java7 is to over-fill a String, and then just substring from it.
 
over-fill?
 
ok :)
	private String repeat(int count) {
		StringBuilder str = new StringBuilder();
		for (int i = 0; i < count; i++)
			str.append("-");
		return str.toString();
	}
that will do for now
 
9:10 PM
For example, with JDOM we need to do indenting of XML docments.... make a string of 1000 spaces.....
 
aha, and then just substring
 
Then, if you need to indent by 4 you indent with SPACES.substring(0,4);
 
but what if you need > 1000 spaces of indentation one day? :)
 
You grow it to be longer whenever it is needed.
 
Automatically, or manually?
Automatically I guess
 
9:11 PM
The 'magic' of pre-Java8 Strings is that they shared the underlying char[] array.
 
if string.length < x then string = string + string
 
In Java8 there are now new Strings on new char[] arrays too
pretty much, and then all the new code reuses the bigger string for their indent needs.
I am not sure how well it will perform now in Java8... you may find it easier to have a char[] array that is filled with the characters you want to use - and new String(DASHES, 0, length);
 
Off-topic...
 
Well, there is Arrays.fill of course... but I'm not sure if that's using iteration or some kind of mem-copy
 
0
Q: Print rows with values greater than 0, 2d array

user3482705Help! So I have a 2d array like: row1 {-4,2,1} row2: {1, 4, 7} row3 {0, 12, 4} I want to loop through and print out only the rows that have ints greater than 0. So row2 would print ,but rows 1 & 3 would not because they have 0 & negative number. I'm trying to break out of my inner loop when I enc...

 
9:14 PM
@SimonAndréForsberg String.format("%30s", "").replace(' ', '-')
 
@200_success Thanks, I think I've seen that one before but forgot about it :)
 
Well, that 'works' but would be horribly inefficient compared to other ways... but it is a 1-liner.
 
And luckily, I don't need to be GWT compatible here so I can actually use String.format for once...
 
Alternatively, new String(new char[30]).replace('\0', '-')
 
0
Q: Print rows with values greater than 0, 2d array

user3482705Help! So I have a 2d array like: row1 {-4,2,1} row2: {1, 4, 7} row3 {0, 12, 4} I want to loop through and print out only the rows that have ints greater than 0. So row2 would print ,but rows 1 & 3 would not because they have 0 & negative number. I'm trying to break out of my inner loop when I enc...

 
9:18 PM
Alternatively, PaddedString.get(30) .... where PaddedString is a utility class that intrnally uses a ThreadLocal to provide the goods.... so is threadsafe, cached, and fast.
 
Yay, a user that implements my suggestions!
Indeed, mAvailableSounds was useless. I get rid of that and used mSoundPoolMap as a SparseIntArray instead. Flexbility wise, I created another class loading all my sounds. — FR073N 22 mins ago
@rolfl Why the need for ThreadLocal? What state would be stored?
@Jamal CVA'd and comment added
 
@SimonAndréForsberg And the OP deleted it. Should've read the Help Center...
 
How did this question get 4 up-votes?
3
Q: Shorter way to write multiple if-then-else-if

Bastienif($row['best']){ $id = $row['best']; } elseif($row['average']){ $id = $row['average']; } elseif($row['bad']){ $id = $row['bad']; } If row['best'] is null, I need $id to equal the 2nd best. If 2nd best is null, $id is equal to the next best.

 
I have no idea. Without context, it could just look like example code.
 
9:34 PM
@SimonAndréForsberg It came from a 1-rep user. As long as it's not spam or blatantly off-topic, I try to bump them up above 15.
 
@200_success Good point, I normally try to do the same thing actually.
 
9:53 PM
How could I have missed this question?
0
A: Basic Calculator in Java with Swing

Simon André ForsbergBug! In your program, it's impossible to use any operator besides addition. As Code Review is not meant to be a code-bug-fixing site, I think you should try to fix this yourself. Hint: The bug is in your addActionButton method Now, about your question. Yes, the template method is a good choice....

@StackExchange Use bigger text next time!!
 
@SimonAndréForsberg :
0
Q: Poke-a-Dot (Provider)

rolflI need to create variable-length strings of dots/periods/full-stops to add to some text content, in a way that is similar to a formatted table-of-contents: Chapter 1 .................................... 1 Section 1.1 ................................ 1 Subsection 1.1.2 ..........................

 
@rolfl Is that part of JDOM, from elsewhere, or did you make that code up on the spot?
 
Made it up on the spot, but it is similar to things I have done before.
I tried it in JDOM, but ended up using a stack.
 
Are you allowed to use Java 8 ? :)
 
Sure.
It is a serious question, I expect there are problems with it, and I have similar patterns I use quite often for other things.
I imagine there are some things I can learn
 
9:59 PM
lol, now you are getting me interested in how the rest of your code works. Sounds quite interesting.
 
Imagine the base string is something like ... say a database connection.
 
Yeah, I understand it is a serious question, which is why I will take my time in possibly coming up with an answer. Not entirely sure you will see an answer from me on that one, depends on the speed of @palacsint and others
Well in that case I see one thing already...
Your question received 3 votes in a short period of time, my recent calculator answer hasn't received any... jealous
 
@rolfl was it you that told me about a photo gallery framework that I could easily add to my site?
 
3
Q: Poke-a-Dot (Provider)

rolflI need to create variable-length strings of dots/periods/full-stops to add to some text content, in a way that is similar to a formatted table-of-contents: Chapter 1 .................................... 1 Section 1.1 ................................ 1 Subsection 1.1.2 ..........................

0
Q: Sieve of Eratosthenes C++

LanyardI'm looking for some feedback on my implementation of the algorithm. How can I improve it? I ran into problems when calculating the larger prime numbers > 46349 due to integer overflow, but fixed that by using sqrt instead of pow. #include<iostream> #include<math.h> using namespace std; int mai...

 
@Malachi - yes, I use Gallery: (menalto IIRC).
Dinner time.
 
10:08 PM
Not an answer:
0
A: Package manager in Clojure

rileyfreemanIn addition to the excellent analysis above, I could have improved my runprog function by following the advice given here: http://codereview.stackexchange.com/a/45823

 
10:19 PM
Simple enough. Perhaps someone can add something else.
0
A: Sieve of Eratosthenes in C++

Jamal <math.h> is a C header. Use the C++ header <cmath>. If you have a dynamically-allocated array with new, you must use delete at some point afterwards, otherwise you'll get a memory leak: delete [] prime; When comparing something with a bool, you don't need to explicitly use true or false. For...

 
10:42 PM
@syb0rg Just a flag will do. The new moderation team is on top of things. =)
 
@200_success I haven't yet adjusted to the new abilities of the mod team ;)
 
I couldn't resist jumping on that sieve question too :)
0
A: Sieve of Eratosthenes in C++

CorbinYou have not implemented a sieve. See Wikipedia's pseudo code for the Sieve of Eratosthenes. You need to check if reading in a number was actually successful: if (!(std::cin >> number)) { std::cerr << "Invalid number provided" << std::endl; return EXIT_FAILURE; } (Note that you woul...

 
You just had to come and show off with this large answer... :-)
And I was thinking about std::vector<bool>, but I was hesitant.
 
Yeah. Unfortunately std::vector<bool> is a bit of an abomination... But... Yeah....
a std::vector<int> will almost certainly take the same amount of space as an equal capacity new bool[] provided an int is the size of a word.
So I would probably go with an int vector rather than bool. std::vector<bool> is of those rare gross corners of C++ where magic happened that shouldn't have happened :/
 
And I was originally going to talk about return 0. Must've slipped my mind.
 
10:56 PM
:)
Luckily CR tends to cover the hell out of simple C++ questions haha
5
 
Today was a weird day today, especially with today's migrated C++ question. That really annoyed me.
 
Migrated C++ question? I didn't see that.
 
3
Q: Check quotient and division by zero

user2941252Please evaluate this code and tell me if it is standard C++ coding: #include <iostream> #include "DivisionByZero.h" using namespace std; double checkQuotient(int numerator, int denominator){ if(denominator == 0) throw DivisionByZero(); return static_cast<double>(numer...

 
ah :/
 
Well, I'm lucky I still got some upvotes.
 
11:02 PM
Voting seems to be weirdly slow on CR today >.<
 
It's a Monday. :-(
 
Ah true. Just got off spring break. My days are all confused lol.
 
If anyone wants to spend some votes, I know a place to spend them:
2
Q: Basic Calculator in Java with Swing

TheWombatGuruI used a standard calculator design from Java. I wanted to expand it so I created a class to create buttons for different operations, like +, -, *, /. The original program didn't do this, they just made them individually without a template method. Do you think I should do it like this? //The j...

I've heard that question and it's answer is quite good to spend votes on
 
:D
It does indeed look very worthy of votes.
Also, every time I see you write something about Java 8, it makes me want to go download it. And I don't even write Java :p.
5
 
And now it's time for class. Be back later.
 
11:08 PM
@Corbin You totally should. I get happy just by think of using Java 8.
Then again, I am a programmer. The idea of programming usually makes me happy.
 
It looks like there are quite a few very useful improvements. Like tons.
 
It seems to have addressed a large part of the "omg java has so much boilerplate!1!1!!" complaint.
 
Lambdas! Default methods! I'm lovin' it!
Oh yes it has.
Java 7:
		btn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("Hello world!");
			}
		});
Java 8:
btn.addActionListener((event) -> System.out.println("Hello world!"));
That's it for today, TTGTB. Night
 
Good night!
 
11:29 PM
Night
 
good news, they days of the ugly black header bar on all SE sites are numbered – they are currently A/B testing a new feature that will help users customize the colour of that bar. Or something like that ;-)
 
0
Q: Make this bounding ball Javascript more efficient?

user3376708I have been using this code for a while for a project at work. Actually I got it from a friends who got it from a book I am certain off. But either way it worked for my demonstration. But the other night I decided to sit down and see if I could make it into all functions and then to see about mov...

0
Q: ZigZag order of a tree traversal

bazangPlease let me know your thoughts on the code below, please be brutal. Here is the question I solved: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binar...

 

« first day (331 days earlier)      last day (3681 days later) »