« first day (584 days earlier)      last day (3435 days later) » 

12:08 AM
Woah, reload already!
 
re written
0
A: Triangles area question

MalachiThe Area that is shaded is the x's and the area unshaded is the o's The Entire Shaded area is equal to the entire unshaded area, meaning that both sides of $\overline {AD}$ are equal to each other, so $\overline {AD}$ divides the original triangle in 2 equal halves which means that ΔBAD $\cong...

now back to work. so my wife will let me eat...
2
 
@200_success ya. clarity on how the transformation process works would be greatly appreciated. int passthrough(int c), display(char * string, int (*transformation)(int)), and then the calls to them in main(). i didn't realize the int (*transformation)(int) was actually a function and that they could be created within a parameter of a function.
@200_success you also said that when transformation is called, that the char's are "written in place". where int (*transform)(int) = passthrough; , transform = passthrough; , and transform = toupper; are being called is when i really get lost though. how come you don't have to set formal arguments?
 
Question:7 ups, accepted answer only 1 ; codereview.stackexchange.com/a/71696/14625
 
12:37 AM
Hi jargonjunkie. Let's break this down a bit.
Suppose we want to always uppercase the text. How could you write display()?
void display(char *string)
{
    for (char *s = string; *s; s++)
    {
        *s = toupper(*s);
    }
    puts(string);
}
Would that work? Any questions about that?
Alternatively…
void display(char *string)
{
    for (int i = 0; string[i]; i++)
    {
        string[i] = toupper(string[i]);
    }
    puts(string);
}
Would you be more comfortable with that?
 
1:27 AM
Just chimed in with a friend on Skype... Found out he's an SE junky, on the Unix site. Small world!
 
2:19 AM
0
Q: Should I define this member function or not?

prestokeysConsider the following: #include <iostream> struct State { virtual ~State() = default; }; struct Drunk : State { void singWhileDrunk() {std::cout << "Singing while drunk.\n";} }; struct Person { State* state; void singWhileDrunk() {dynamic_cast<Drunk*>(state)->singWhileDrunk();} ...

0
Q: How do I import an Art class?

ChandlerI found this site when I searched for a Java RPG to use as an outline since I'm a total beginner in my Computer Science class. I copied and pasted some code that was posted here around two years ago, but I couldn't compile it on BlueJ. Google helped me a lot since I found out how to import stuff...

0
Q: Class CatalogWalker can walk thru a list of catalogs, calculate and report some statistics

GurmanJust for review and may be useful for somebody from os import walk from time import time from abc import ABCMeta, abstractmethod class Reporter(object): __metaclass__=ABCMeta @abstractmethod def report(self, catalogs_cntr, files_ctnr, speed): """ output catalogs_cntr, file...

 
2:41 AM
@CaptainObvious Is it just me or that question is pretty mediocre?
 
its not so much the pointer notation over array notation thats the hiccup for me. its more the mystery behind the magic. i know that, for instance...

void display(char *string, int (*transform)(int))
{
for (char *s = string; *s; s++)
{
*s = transform(*s);
}
puts(string);
}
 
Do you follow the hard-coded toupper() samples above?
 
so i could easily translate that too

void display(char * string, int (* transform)(int value))

so i know that transform is a function that is a pointer-to-int and it takes an argument of int value., but what is transform doing? it hasn't been declared until that point and is private to the functions parameter scope. i'm not one for the "black box theory". i like to know what's in the box.
@200_success ya. lol i feel stupid right now. i can see that toupper, but it somehow fulfills what toupper and tolower is doing all at once.
 
Before I discuss function pointers, could you confirm whether you are completely comfortable with this use of toupper() first?
void display(char *string)
{
    for (int i = 0; string[i]; i++)
    {
        string[i] = toupper(string[i]);
    }
    puts(string);
}
 
yes, i am more comfortable with array notation, but i don't mind the pointer notation. that way i can get better at interpreting it. i know that
string[i] == *(string + i) == string == &string[i]
are all supposed to be synonymous. which is why you can say that
string[i] = toupper(string[i]); == *s = transform(*s) || *s = toupper(*s++)
assuming were using a while() loop for instance
while (*string)
 
2:52 AM
So you are convinced that my last sample prints an uppercase version of whatever string you pass in?
 
0
Q: How can I make my drawing "talk" to the user?

ChandlerI may seem like an idiot for asking, but here's something I made on BlueJ that I need help with: /** * class Kirby will draw a Kirby character * I'm disclaiming now if that's an issue * * @version WhenChandlerThoughtItWouldBeMoreEfficientToUseMicrosoftPaintForThis */ //At the bottom of t...

 
@200_success i feel like a horse being led to water and i just don't realize that im staring at the water im supposed to drink already lol. but im going to answer i don't know because i really don't. im not sure what you're trying to ask. but if youre asking if im convinced, the answer would have to be no. but then, i haven't applied your theory to the application yet...hence the reason for my doubt. to be honest, this is dubious evidence IMO at best.
 
That's fine. I want to make sure we're on the same page before progressing.
How about string[0] = toupper(string[0]) — can you tell me what that does?
 
ok, ill play along.

string is the address of where the data is stored.
[0] is the dereferenced value, or where the first element is stored at the given address.

string[0] is assigned the value that toupper returns which is an assumed char, or int value that represents a char value. string[0] is the char that is processed by toupper and toupper returns an "uppercase" value, which is really...i see now lol.
 
So it just overwrites the first character of the string with the uppercase version of itself. Right?
 
3:05 AM
@200_success yea, but how does transform know whether to do either or if we just declared it?
 
Let's defer that discussion a bit, if you don't mind.
 
@200_success ok. let's keep going. im curious.
 
string[1] = toupper(string[1]) does what?
 
string[0] = toupper(string[0]) //first char
string[1] = toupper(string[1]) //second char
string[2] = toupper(string[2]) //third char
and so on...
 
Good. How can we uppercase the whole string?
 
3:08 AM
@200_success all replacing themselves with their respective "modified" chars
 
for (int i = 0; string[i]; i++)
{
    string[i] = toupper(string[i]);
}
OK with that?
 
0
Q: Can someone check my AES Encryption class for security flaws?

hedfun2I am new to encryption and recently wanted to learn more about it. I researched how to do AES Encryption in java and assembled my own java AES encrpytion class. I don't know if there are any major security holes though. Can someone experienced in java encryption look at my code and tell me if the...

 
@200_success yea, for(;;) or while() would work.
 
As long as you somehow stop when you encounter the NUL terminator.
So, how would you write a loop that lowercases the entire string?
 
'\0' NULL and 0 all different representations all amounting to the "same value".
 
3:10 AM
Yes, that's right.
 
@200_success just replace toupper with tolower
@200_success that's why you used the switch...
 
I should be a bit more careful in saying that they are all the same. '\0' is used to represent ASCII value 0, also known as the NUL character.
NULL is generally used to mean a pointer with a zero value.
… which points to "nowhere".
 
@200_success i know what you meant. it's okay. and zero is a literal value or representation.
 
0 is just a generic zero.
If you mix them up, the code will "work", but programmers reading your code will get confused.
 
or literal constant to be exact.
 
3:13 AM
Anyway, strings are terminated by a '\0' marker.
 
ok. that makes sense
 
And what does this code do…?
for (int i = 0; string[i]; i++)
{
    string[i] = passthrough(string[i]);
}
 
each char representing one byte, the difference between an array and an string literal is that the string literal holds the null character.
so if we had the string "hello, world"
and broke it down, it would be an array of chars with a terminating null char '\0'
i is in the scope of the for loop and only exists until the end of the block.

for i is initialized to 0 while string char is not null increment i postfix
assign string[i] the value of passthrough(string[i]);

which basically checks to see if the passed value is an int and if it is it returns an int which is passed to string[i].
or am i wrong?
 
That's all true… but what actually happens, in plain English?
I'm referring to this passthrough() function, by the way…
int passthrough(int c) {
    return c;
}
 
the loop scans the string char by char until it reaches the null character. while it traverses the string character by character it passes the value back and forth from passthrough to string.

while each value is passed over to pass through, it needs to be of type int. the data object being passed to the function. im assuming, or inferring, that since only an int value can be passed (thats part of the test, or condition) and if it does so, it can return the integer based value to the calling function or object.
 
3:23 AM
OK, except that there is no real testing going on. It just does it.
Basically, it goes through the string, overwriting each character with itself.
Or more simply, it does "nothing".
 
and thats all it does.
so what's the point?
 
So, let's consider the three loops…
First version:
for (int i = 0; string[i]; i++)
{
    string[i] = toupper(string[i]);
}
Second version:
for (int i = 0; string[i]; i++)
{
    string[i] = tolower(string[i]);
}
Third version:
for (int i = 0; string[i]; i++)
{
    string[i] = passthrough(string[i]);
}
They are all the same, except for the toupper vs. tolower vs. passthrough.
So the challenge is, can we write one loop that covers all three cases?
 
@200_success i would assume so.
 
The only purpose of the passthrough function is to make all three cases look similar, so that we don't need to write a special case for your -p flag.
So, what we want is
for (int i = 0; string[i]; i++)
{
    string[i] = do_the_right_thing(string[i]);
}
Or, with more elegant naming,
for (int i = 0; string[i]; i++)
{
    string[i] = transform(string[i]);
}
The next challenge is, how can the caller specify what the "right thing" is?
 
@200_success finally, lol.
 
3:30 AM
Sometimes, the "right thing" is toupper. Sometimes it's tolower. Sometimes it's passthrough.
If you read the documentation for toupper() and tolower(), you'll see that they both accept an int and return an int.
 
ya, int toupper(int c)
not a single pointer in sight
not even a char
 
Therefore, we have to design passthrough to also accept an int and return an int.
So, we have to tell the compiler that transform is some kind of function that accepts an int and that returns an int.
 
and hopefully it will complain if not so.
 
That's what int (*transform)(int) says. The variable transform represents a function that accepts an int and that returns an int when called.
With that knowledge, let's look again at
void display(char *string, int (*transform)(int))
{
    for (char *s = string; *s; s++)
    {
        *s = transform(*s);
    }
    puts(string);
}
The loop I wrote is exactly equivalent to the ones I have been showing you just now.
 
0
Q: Replace spaces in string

CodeYogiimport re def replace_token_regex(s, token=" "): return re.sub(token, '20%', s.strip()) def replace_token_inplace(s, token=" "): for index, char in enumerate(s): if ord(char) == ord(token): s[index] = '20%' return s print replace_spaces_regex("Foo Bar ") s = l...

 
3:36 AM
It just happens to use *s instead of string[i]. Don't let that bother you. I assure you that they are the same.
So, display is a function that accepts a string and some transformation, where the transformation is one that maps an int to an int. It performs the transformation, then prints it.
Take a minute to convince yourself or raise any objections.
 
@200_success i believe you. it doesnt bother me at all. the part that gets me is that transform is dereferencing itself. why not declare it as int * transform(int)?
is there a major differnce between (*transform) and * transform?
 
The parentheses around (*transform) are necessary to get the precedence right.
 
because parentheses is higher than the asterick.
so the function really isn't a pointer to a int, its a dereferenced value because you're supplying a referenced value?
 
int *transform(int) would be interpreted as int *(transform(int)), which doesn't make sense.
transform is not a pointer to an int. It is a pointer to a function. The function accepts an int and returns an int.
 
@200_success ok. i am following. i just wanted to clarify before asking my next question to make sure i am following what you're saying.
switch (option(argv[i]))
        {
          case '-':
            help(stderr, argv[0]);
            return 1;
          case 'h':
            help(stdout, argv[0]);
            return 0;
          case 'p':
            transform = passthrough;
            break;
          case 'u':
            transform = toupper;
            break;
          case 'l':
            transform = tolower;
            break;
          default:
            string = argv[i];
here you state that transform = passthrough;
and transform = toupper;
i had expected some arguments such as var = transform(value);
but it seems like youre somehow assigning values to these functions...maybe this is somehow out of the scope of what i've covered, i am missing a few key chapters from my book.
 
3:45 AM
That would be calling the function and actually performing the transformation. We don't want to call it in main. We want that loop we were talking about to call it.
In main, we just want to specify what kind of transformation we want.
So that we can tell display() to use the right transformation.
 
so what does transform = toupper; actually do?
it just tells transform what to do and how?
in this case, set char to uppercase.
 
Technically, it sets transform to point to the chunk of code that represents the toupper function.
 
because transform just takes these values and replaces its "old values" with its "new values" per se. so thats a how a pointer based function works, eh?
 
Logically, you can think of it as saying "I think we will want to use toupper as the transformation later."
 
ok
thats the part that i was having a hard time with.
i was like wait, wth is going on here?
im starting to get it now though.
 
3:51 AM
0
A: A query to get all posts that count for Archaeologist and Excavator

rolflI have coded up in SEDE what I believe to be a mostly accurate representation of the post edits that count toward Archaeologist. It identifies all your edits, and then discards those that were active within 6 months prior to the edit. It uses the following strategy to determine the last activity...

 
Maybe it would be easier to understand if we didn't assign the function pointer first. Try playing with a very simple main, like…
int main(int argc, char *argv[]) {
    char *string = argv[1];
    display(string, toupper);
}
 
well, let me ask a question real quick.

could

int * function(int value) be considered the same as
int function(char * string, int (*function)(int value))
 
In the latter part, you used function twice — do you mean two different functions?
 
yes,

to better state

int outside(char * string, int (*inside)(int))
is int(*inside)(int) == int * function(int)?
 
And in the former part, do you mean int (*function)(int value)?
 
3:55 AM
yes
 
Remember, you need the parentheses to get the right precedence.
 
alright, lets go back for a sec then, so i can better understand
lets say these are both functions
function one and function two respectively
int * function_one(int)
int (*function_two)(int)
both are functions, but the important part here is the precedence
one says im returning a pointer to an int
and the other says what again?
 
I'm not sure that the function_one example even makes sense.
 
well let's say its an actual function
because thats how we can get a return null value or pass an address of a character in a string. it usually represents a return value, right? generally speaking of course.
int * function_one (int * string)
{
if (*string == '\0')
return null
else
return *string
}
 
I just tried compiling int *function_one(int) = NULL; and got an error.
On the other hand, int (*function_two)(int) = NULL; works.
Oh, I see.
function_one is a function that accepts a pointer to an integer, and that returns a pointer to an integer.
It is, however, not a pointer to a function.
 
4:04 AM
exactly
#include <stdio.h>
#include <stdlib.h>
char * function_one(char * string)
{
if (*string == '\0')
return NULL;
else
return string;
}
int main(void)
{

return 0;
}
this does compile
 
Yes, I think that compiles.
 
i just checked lol
needed to make sure i wasnt crazy
sanity check and all
now back to my question
 
Go ahead.
 
as i just stated, function_one represents a return value a pointer-to-int or in this case a pointer-to-char for example.

function_two
this is what you said.
That's what int (*transform)(int) says. The variable transform represents a function that accepts an int and that returns an int when called.
With that knowledge, let's look again at
void display(char *string, int (*transform)(int))
{
for (char *s = string; *s; s++)
{
*s = transform(*s);
}
puts(string);
}
lets say that function_two's equivalent was this function pointer
int (*transform)(int)
what does that mean exactly?
 
So function_two and transform have the same type, and are "compatible" with each other.
 
4:09 AM
0
Q: Generate Random String and Writing to File

ajkumar25my task is to generate random strings and store in a file till the size of file is less than 10MB. My approach towards this problem is as follows. import java.io.File; import java.io.FileWriter; public class Application { public static void main(String[] args) throws Exception { lon...

 
yes. and to reiterate, this is what my question really is, and i really am just copy and pasting what i said before.
--------------------------------
alright, lets go back for a sec then, so i can better understand
lets say these are both functions
function one and function two respectively
int * function_one(int)
int (*function_two)(int)
both are functions, but the important part here is the precedence
one says im returning a pointer to an int
and the other says what again?
what is function_two? what is it doing? and how is it differnt from function one aside from the obvious.
 
function_one is actually a function (a function that accepts an int and that returns a pointer to an int). function_two is not actually a function, but rather a pointer to a function — one that accepts an int and returns an int.
 
ok.
finally.
i understand lol
 
Yeah, sometimes it's tricky to read a C declaration. Anyway…
as I was saying…
int main(int argc, char *argv[]) {
    char *string = argv[1];
    display(string, passthrough);
    display(string, toupper);
    display(string, tolower);
}
Do you feel OK about that?
 
4:15 AM
int main(int argc, char *argv[]) {
    char *string = argv[1];
    int (*function_ptr)(int);
    function_ptr = toupper;
    display(string, function_ptr);
}
How about that?
 
0
Q: Angular Todo Lists - Factories? Controllers? App architecture advice needed

gabrielfreibergI have an angular app using a restful api which works, but I know is structured poorly. I'm using a projectService (factory) to do all interfacing with the REST back-end, for both of the backend Project and Task models. The ProjectController and TaskController both get the projectService (fact...

 
what you're saying when you declare something as
transform = toupper
since transform is not a function and it is a pointer to a function, you can point to an already existing function such as toupper, or tolower, or to transform...

were really saying, transform is pointing to an existing function that can do this behavior for us already, so let toupper do all the work. toupper is passed the value by using transform which is also a pointer. so we can arbitrarily use one function or task over the other depending on the needs of the current action.
 
Exactly!
 
i told you i understood haha
all thanks to you man?
yes!!! all thanks to you!!!
i didnt realize how clever the code really was.
its cleaner, easier to maintain, less to read, and to write.
 
Yes. It is more elegant than passing special characters to display(), then having display() interpret them with some kind of switch or if-elseif-elseif.
The tricky part is understanding that you can pass a pointer to a function, and figuring out how to actually write the pointer declaration.
 
4:22 AM
ya, i can see that.
i just want to say thank you for your time, help, and dedication. its refreshing to work with someone like you, esp since i do most of this on my own. most people just brush me off, mock me, or refuse to help. lately, i've been using stack exchange and i've had much better results.
 
I suggest that you experiment with some of the stripped-down versions of main() to get the hang of the concept.
 
i definitely will.
 
Well, I already took the time to write an answer. It would be a shame if it just flew over your head. =)
 
haha
gonna have to mark that one as an answer ;)
 
There are some languages, like Python or LISP, where passing code around is common and natural. In C, it's a bit unusual. But it's a tool in your toolkit that comes in handy for situations like this.
 
4:25 AM
yes indeed. i was looking at both those languages, but im really edging over towards Python so i can focus more on my Maths again and move towards my Intro to Algorithms book.
i just wanna solidify my knowledge with C first which is why im taking my time with it. its my real first language.
 
Python is a nice language. I recommend it. C is also good to learn so that you get to understand what goes on at a low level.
Anyway, good night, and I look forward to your next question on CR.
 
that's why i chose C. my natural need to know led me to C. ive had experience with JavaScript and PHP in the past, but C is a totally different tool. and good night to you as well. look forward to some answers in the future.
later, it was a pleasure.
 
@Mat'sMug i've gone "full circle" myself with reactive extensions. spent ages trying to write Simon Says using them only to realise, once i got it working, that i didn't need them in the first place -_-
4
 
♪ a-la-la-la-la-long ♪
;)
 
lol
 
4:31 AM
I want to understand how to interpret the MSDN help in this case
I wanted to bind to `ListCollectionView`'s `Count` so I have been advised to cast it to `INotifyCollectionChanged` and then use it's `CollectionChanged`event.
how would you get to that conclution from ListVollectionView MSDN page?
In the methods it's mentioned
OnCollectionChanged(NotifyCollectionChangedEventArgs)
 
INotifyCollectionChanged will notify when an item is added/removed from the collection
 
now I understand it. but curious to know how could I find it out myself using the information on the MSDN page
 
I'd just google INotifyCollectionChanged..
 
or better way to put it "based on which part of info in that page I could come to the same conclusion"
INotifyCollectionChanged hasn't been mentioned in that page even once
 
the remarks section does
> If the source collection implements the INotifyCollectionChanged interface, the changes raised by the CollectionChanged event are propagated to the views.
 
4:38 AM
emm that's true. It seems I just simply failed to search for a word in the page
Thanks @Mat'sMug.
 
np
 
5:27 AM
TTGTB
 
5:42 AM
0
Q: improving my R code

SiklosI wrote a code and wanted to ask how to improve it. It is a simulation of animal skins, like a cellular automat. #Create Matrix with random numbers 0/1 with a 50% chance createMatrix <- function(br,gen) { mat <- matrix(rbinom(br*gen,1,0.5),br,gen) return(mat) } nextMatrix <- function(mat,w) {...

 
Monking @all
 
monking @Heslacher
 
6:03 AM
0
Q: Comment on improving or different approach

OzeraI want to sort a string which contains words and integers with the restriction that if the nth element in the list is an integer it must remain an integer and if it is a word, it must remain a word. I am trying to find comments on improve the code or looking for a different approach to the pr...

 
6:52 AM
-1
Q: Adding Pictures in C++

NishantI am 15 and my journey has just begun. I am trying to add jpeg pictures in my program via Turbo C++. Can anyone help me in that?? I need Simple way.

0
Q: Uniform distribution of elements

CodeYogiGiven the following inputs: The input distribution or frequency. Eg: [(a, 10), (b, 9), (c, 4), (d, 3)] (a, 10) means I have 10 words starting with a The number of buckets. Eg 2 Output: The mapping of bucket # and the corresponding alphabets. Eg: {0: [a, d], 1: [b, c]} order is not importa...

0
Q: Swift Performance

HowardI'm new in Swift Language. I have a C# version simple AStar route which is very fast. But I rewrote with Swift, the performance is very bad (3,4 seconds for a very simple road). Could someone take 10 minutes to give me some suggestion. Because I have no experience on this. What I thought is that,...

 
7:29 AM
0
Q: How to set link into menu in Codeignitor?

Adarsh Bhatt ABI am developing an fees managment application in codeignitor. i am new in CI so I want to know that How to create simple menu and how to set link to that menu item? Here is my Code of Menu: application/controllers/studentmaster" class="btngrn btn-xlarge mar-right...

 
7:43 AM
hey
 
hey
 
how are you?
 
Good as usual, and yourself ?
 
Also doing fine
Getting a bus to university soonish...
If there's any space left, it's ridiculously crowded
 
8:00 AM
0
Q: Collection and property binding in the same class

Lamloumi AfifI have a winform which contains three controls (TextBox, GridView and a binding Source) . I Have this class VerificateurViewModel Public Class VerificateurViewModel Inherits ObservableCollection(Of Verificateur) Implements INotifyPropertyChanged #Region "Fields" Privat...

 
 
1 hour later…
9:11 AM
0
Q: Most efficient way to get columns where one is minimum

user3284707I have a table with 3 columns in the format below: WebcastChannelId, WebcastEventId, SortSequence 1 , 2 , 1 1 , 5 , 2 1 , 3 , 3 2 , 7 , 2 2 , 8 , 1 I would like to get the values for the webcastChannelId and WebcastEventId with the minimum sort sequence. In the above example this would be:...

 
9:46 AM
Heya folks.
 
hey @kleinfreund
 
Hi skiwi
 
0
Q: Test a number for primality and return smallest divisor different from 1 if it’s is composite

kleinfreundIn this exercise we were asked to test a number for primality and print the results. Additionally – in the case the number is composite – the smallest divisor different from 1 should be printed out. Negative input values shall not pre processed and result in a message. The second part of that ta...

 
how are you @kleinfreund?
 
Phew. I'm fine. From now on we have the Tuesday morning off for the rest of the semester. Catching up on some stuff I didn't find the time recently. Like posting reviews. :D
How are you, @skiwi?
 
9:53 AM
Also fine
Priorities shifted a bit.. less programming for fun
 
What for now? Money?
 
On one hand, other hand less programming and you know... social things
The things the stereotype programmer fears!
 
Aaaaaah!
 
Why wording around it like that then? :)
Also there is no such thing as stereotype programmer fears.
 
@kleinfreund Ah, my friend, punctuation, I messed up
I didn't mean stereotype programmer fears, but stereotype programmer there :)
If that makes any sense.
 
10:02 AM
0
Q: Cleaning up my jquery code

Jesse UilenreefI a bit of noob to jquery so i got this jquery code what i think can be way faster. Does someone want to help me cleaning it up? Explaining why you did what would be real nice but not needed. thanks, Jesse. The working site is online here: http://jesseu.nl/madein030/ The jQuery code: onResize ...

 
I don't know, it makes sense to me or does it? So you're not talking about things a stereotype programmer fears?
 
@skiwi no the punctuation is fine..
 
@kleinfreund I am
btw @Vogel612 I figured a nice way
 
Alright, I got it then. :P
 
public static String readEntry(final Path path, final String entryKey) {
    try {
        Objects.requireNonNull(path);
        Objects.requireNonNull(entryKey);
        String entryKeyCopy = entryKey + "=";
        try (BufferedReader bufferedReader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
            List<String> entries = bufferedReader.lines()
                .filter(s -> s.startsWith(entryKeyCopy))
                .filter(s -> !s.isEmpty())
                .filter(s -> !s.startsWith("#"))
Which is clean and clean
It closes the reader and is not ugly
 
10:06 AM
but these filters....
the second startswith is not helpful I think...
 
It's to ignore comments... in an ugly way
Hmm
Good point there though
It ignores comments by default
 
Can someone have a look over this answer and tell me what he means? codereview.stackexchange.com/a/72116/35408
Is he suggesting the seperation of primality test and calculating the smallest divisors or am I getting it wrong (again)?
 
what part exactly??
 
@kleinfreund At second look he is correct... your way looks weird to me, though it's not per se weird
He pretty much says you could only use if's, and not use else if's
 
Yeah, I get that. That's sane.
However the second part confuses me.
 
10:09 AM
Though I don't directly see another way to do it
It wouldn't be much fun to maintain that code though!
(If you add unit tests, then it gets better)
 
@kleinfreund I think he says your main-method should be subdivided more clearly..
 
@Vogel612 It's about the smallestDivisor
 
is it`??
I am not so sure about that
 
0
Q: Finding the name of a file and chapter

AlanSmiththe program needs to be able to search the files in the directory, store them in the array then search by word the user enters to return the name of the file, chapter and verse. So far I believe I have got most of it working except for getting the file name that contains the word being searched a...

0
Q: Enum vs lookup table

KirdApeI'm implementing a solution in Java using Ebean and I'm having some issues choosing between using Enums or simply look up tables. I have a table "Tooth". A tooth can be "Temporary" or "Permanent". I could create a simple Enum: @EnumMapping(nameValuePairs = "TEMPORARY=T, PERMANENT=P") public en...

 
I could have the code essetially duplicated and write a method that returns true if the candidate is prime or false otherwise. The other method would calculate the smallest divisor like it's done currently.
 
10:12 AM
after the first sentence his answer is now gibberish after the edit.
 
@kleinfreund I don't really like that you are returning -1 there
It may be more efficient, but also more confusing
 
Yeah. :/
I have a conflict there.
 
It's somewhat c-ish, but there's not much you can do if you don't accept the prime itself as smallest divisor > 1...
 
I could return the candidate itself, right.
 
I'd need to take a clear look at the program to be of more use
As well of the problem statement
 
10:20 AM
I say "hello".
 
@Morwenn God, now I have that song stuck in my head!
 
I say "Hello".
 
@skiwi Haha, I don't even know which song.
 
@Morwenn Just say hello
 
Maybe I'm lucky not to know this song.
 
10:25 AM
> Calculate sqrt(primeCandidate) once instead of i*i in every loop. Saves time.
 
true dat..
 
Ah wait, I see.
 
@kleinfreund On one hand that's fair, but realize that calculating Math.sqrt is way heavier than multiplying the other side
Given the amount of iterations you have in the loop, it seems fair now though
 
So it benefits big values?
 
Also i * i may overflow at some point
 
10:29 AM
The problem when with have to deal with maths is that we have to take into account math and computer science.
Which means math + overflows + speed + floating point pitfalls.
2
 
So I check for i < primeCandidateSqrt?
 
yes..
well you should round up the primeCandidate sqrt, but that's the gist of it ,)
 
Memory problems are frustrating
 
0
Q: Require.js - the best way to define classes and packages

PashaTurokI've oprimized everything I could and got the following result: require.config({ paths: { 'com.company.MyClass': '....../MyClass' } }); MyClass.js: define([], function () { function MyClass () { var _name = 'module2 name2'; this.getName = function () { ...

 
Phew, that looks ugly:
int primeCandidateSqrt = Math.round((int) Math.sqrt(primeCandidate));
 
10:37 AM
rounding an int doesn't really do all that much....
 
I should get pen and paper before trying to get math and programming together.
 
that's awesome advice I should also follow more often..
 
There must be a way to trigger memory collection once the garbage fills up.
 
So I have an integer, calculate the sqrt which will be a floating point value and then I round up. So I have Math.round(Math.sqrt(n)).
 
System.gc();
 
10:44 AM
@Vogel612 It's kind of ugly
 
Why did I cast it to int? *sigh* -.-
 
@skiwi sure, but do you know a better alternative?
you can run it every somesuch iterations...
 
@Vogel612 Managing it via JVM settings would be better
I may need to review this whole system...
 
I'll make sure to read that at a later point today
 
10:52 AM
0
Q: On What Day Is That Date

HelloI got bored on my long weekend so I decided to have my coding exercise. And I successfully made a program that let you input the day and the month then it gives you the day of given date. But sadly it's only for 2014 calendar. import java.io.*; public class DaysToYears{ public static void main(...

 
I just submitted my first C++ proposal ever. Hope I will get a document number and it will be published in the next mailing :)
 
@Morwenn What is it about??
 
@skiwi Removing a detail about a feature that has been voted in the latest draft.
You can find the pdf here but I have to admit that it is not really an interesting read xD
Nothing exciting about the proposal. That's just to improve safety/consistency.
 
0
Q: Perl 6 oneliner to sum up all numbers in a text file

user7610The task is to sum up scores mentioned in a text file. Scores are floating point numbers as defined by the regexp float immediately preceded by a * character to distinguish them from other numbers in the text. Scientific notation is not permitted. Example input Day 1: Task 1: *5 Task 2:...

 
ok @Morwenn, so you non interesting stuff!
 
11:08 AM
hi
 
ho
 
ha
 
11:25 AM
Oh
 
11:42 AM
0
Q: Is my data correctly normalized to 3NV?

FredIm going to build a database in Access. Im trying to normalize my data to 3NV. My data(FAQ) consists of categories, questions, answersText and answersImage. The questions can be answered with text and/or image. Questions can be associate with multiple categories. The bold text are primary keys. ...

 
@rolfl Oh
 
11:58 AM
Monking!
 
> ...forces garbage collection; extremely dubious except in benchmarking code...
Oh hi, FindBugs
And also monking @rolfl
 
@skiwi So I'm not interesting? I find this offensive.
 
Though FindBugs is worng, as System.gc() doesn't force GC, it only requests it
@Morwenn I don't even know what I wanted to say there
 
@skiwi it forces...
 
@skiwi Well, I don't really understand either :p
 
12:00 PM
> When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
 
@Vogel612 "Best effort"
 
"has made"
> Runs the garbage collector.
 
0
Q: Generic Memory Pool - How to? - Design Issue

AdornI am creating my own memory pool for small and very frequently used objects. I am good with the allocation and d-allocation itself. Here is layout of my Pool class CPool { unsigned int m_uiBlocks; unsigned int m_uiSizeOfBlock; unsigned int m_uiFreeBlocks; unsigne...

 
Does anyone know a tool for phone/PC where you can enter small reminders? :D
With due date and annoying auto-repeat functions of course
 
@Vogel612 Technically you can supply: -XX:-DisableExplicitGC
> By default calls to System.gc() are enabled (-XX:-DisableExplicitGC). Use -XX:+DisableExplicitGC to disable calls to System.gc(). Note that the JVM still performs garbage collection when necessary.
 
12:14 PM
0
Q: Best way to create multidimensional default values array

BeNdErRI need to create a n x n multidimensional array filled with default values. Right now, I'm using this code: //--- how many columns? var colNumber = 10; //--- how many rows? var rowNumber = 20; //--- default value var defaultValue = "default"; var defRow = []; var defaultArray = []; for(var x...

 
12:31 PM
0
Q: python: generating a stacked bar chart

JoeI've got some code that I use to generate images like this: The code I use to generate the image itself is below. I'm interested in any feedback on style or simple 'actually you can do this in fewer lines... I've left out the large 'process' function that returns a links of Item objects. c...

 
12:50 PM
@Vogel612 best effort is still not forcing
in .NET you can force it, Java is only a strong nudge
 
@JeroenVannevel running the gc is a best effort to get all space from discarded objects
You're mixing stuff up here ;)
 
But System.GC() does not run the GC
System.GC() will promise a kiss to the lonely GC so the GC will try to make it work but sometimes he just has no choice but to go to the store to get food
2
.NET will put a gun to the GC's head
2
 
0
Q: which is a more semantic way of achieving a hover tooltip effect

Tenali RamanWell i have tried 2 approaches to creating a hover tooltip effect , one is rather simple and the other just a tinge complex . My questions is about semantics but also about which method is better even later on for code dubbing : below is the code for what i have tried : for the simple CSS-3 t...

0
Q: Speed up iteration in Python and check for correct sequence match

squeamish ossifrageThe archived material for the Stanford University course on cryptography at coursera.org includes a problem where you have to predict the next output of a weak PRG. It can be briefly restated as follows: $$P = 295075153$$ $$0 \le x_0, y_0 \lt P \ \ \ (unknown\ random\ integers)$$ $$z_{n} ...

 
53
Q: When does System.gc() do anything

harryI know that garbage collection is automated in Java. But I understood that if you write System.gc() in your code the Java VM may or may not decide at runtime to do a garbage collection at that point. How does this work precisely? On what basis/parameters exactly does the VM decide to do (or not d...

It might be an implementation vs specification detail though, as this answer indicates:
8
A: When does System.gc() do anything

Pierre LaporteThe Java Language Specification does not guarantee that the JVM will start a GC when you call System.gc(). This is the reason of this "may or may not decide to do a GC at that point". Now, if you look at OpenJDK source code, which is the backbone of Oracle JVM, you will see that a call to System...

> Now, if you look at OpenJDK source code, which is the backbone of Oracle JVM, you will see that a call to System.gc() does start a GC cycle. If you use another JVM, such as J9, you have to check their documentation to find out the answer. For instance, Azul's JVM has a garbage collector that runs continuously, so a call to System.gc() won't do anything
 

« first day (584 days earlier)      last day (3435 days later) »