WTF Bites
-
@tsaukpaetra said in WTF Bites:
@tsaukpaetra said in WTF Bites:
Status: Made a loop to move to the next delectable button in an array:
int LastSelectedIndex = SelectedIndex; int RotateDirection = Direction == EDirection::Left ? -1 : 1; for (int newSelectedIndex = SelectedIndex, loops = 0; !SelectButton(newSelectedIndex) || (newSelectedIndex == LastSelectedIndex && loops == 0); newSelectedIndex = newSelectedIndex + RotateDirection + ButtonArray.Num() % ButtonArray.Num()) { if (newSelectedIndex == LastSelectedIndex) loops++; }
I'm not entirely sure I need the
LastSelectedIndex
variable...Edit: And that
ButtonArray.Num()
(which returns the number of elements, natch) is incorrect here...This is so bad it hurts…
But it works!
Of course it does.
Why do you hate variables?
-
@tsaukpaetra said in WTF Bites:
@tsaukpaetra said in WTF Bites:
Status: Made a loop to move to the next delectable button in an array:
int LastSelectedIndex = SelectedIndex; int RotateDirection = Direction == EDirection::Left ? -1 : 1; for (int newSelectedIndex = SelectedIndex, loops = 0; !SelectButton(newSelectedIndex) || (newSelectedIndex == LastSelectedIndex && loops == 0); newSelectedIndex = newSelectedIndex + RotateDirection + ButtonArray.Num() % ButtonArray.Num()) { if (newSelectedIndex == LastSelectedIndex) loops++; }
I'm not entirely sure I need the
LastSelectedIndex
variable...Edit: And that
ButtonArray.Num()
(which returns the number of elements, natch) is incorrect here...This is so bad it hurts…
But it works!
Of course it does.
Why do you hate variables?
I don't? There's four of them right there! In fact, the variable-to-line ratio is nearly 1:2!
😜
-
@tsaukpaetra said in WTF Bites:
@tsaukpaetra said in WTF Bites:
@tsaukpaetra said in WTF Bites:
Status: Made a loop to move to the next delectable button in an array:
int LastSelectedIndex = SelectedIndex; int RotateDirection = Direction == EDirection::Left ? -1 : 1; for (int newSelectedIndex = SelectedIndex, loops = 0; !SelectButton(newSelectedIndex) || (newSelectedIndex == LastSelectedIndex && loops == 0); newSelectedIndex = newSelectedIndex + RotateDirection + ButtonArray.Num() % ButtonArray.Num()) { if (newSelectedIndex == LastSelectedIndex) loops++; }
I'm not entirely sure I need the
LastSelectedIndex
variable...Edit: And that
ButtonArray.Num()
(which returns the number of elements, natch) is incorrect here...This is so bad it hurts…
But it works!
Of course it does.
Why do you hate variables?
I don't? There's four of them right there! In fact, the variable-to-line ratio is nearly 1:2!
😜Yeah, yeah. Multiline for declaration should be considered capital crime.
-
@tsaukpaetra said in WTF Bites:
Status: Made a loop to move to the next delectable button in an array:
int LastSelectedIndex = SelectedIndex; int RotateDirection = Direction == EDirection::Left ? -1 : 1; for (int newSelectedIndex = SelectedIndex, loops = 0; !SelectButton(newSelectedIndex) || (newSelectedIndex == LastSelectedIndex && loops == 0); newSelectedIndex = newSelectedIndex + RotateDirection + ButtonArray.Num() % ButtonArray.Num()) { if (newSelectedIndex == LastSelectedIndex) loops++; }
I'm not entirely sure I need the
LastSelectedIndex
variable...Edit: And that
ButtonArray.Num()
(which returns the number of elements, natch) is incorrect here...int n = ButtonArray.Num(); int prev = SelectedIndex; bool left = (Direction == EDirection::Left) for( int i = 0 ; i < n ; i++ ) { if( SelectButton((left ? prev + n - i : prev + i) % n) ) { break; } }
All helper variables are only there because your variable names are insanely long.
-
-
@tsaukpaetra said in WTF Bites:
Status: Made a loop to move to the next delectable button in an array:
int LastSelectedIndex = SelectedIndex; int RotateDirection = Direction == EDirection::Left ? -1 : 1; for (int newSelectedIndex = SelectedIndex, loops = 0; !SelectButton(newSelectedIndex) || (newSelectedIndex == LastSelectedIndex && loops == 0); newSelectedIndex = newSelectedIndex + RotateDirection + ButtonArray.Num() % ButtonArray.Num()) { if (newSelectedIndex == LastSelectedIndex) loops++; }
I'm not entirely sure I need the
LastSelectedIndex
variable...Edit: And that
ButtonArray.Num()
(which returns the number of elements, natch) is incorrect here...int n = ButtonArray.Num(); int prev = SelectedIndex; bool left = (Direction == EDirection::Left) for( int i = 0 ; i < n ; i++ ) { if( SelectButton((left ? prev + n - i : prev + i) % n) ) { break; } }
All helper variables are only there because your variable names are insanely long.
You think my variable names are long?
And these aren't even the LONGEST ones, I just scanned one of the files I happened to have open.
-
@tsaukpaetra said in WTF Bites:
You think my variable names are long?
Yes. I've seen longer, and let's just say it's really quite annoying when coding feels like copying out War and Peace just because a colleague likes to blather in his identifiers.
-
Yes
Quite apart from that, it keeps the pattern clear. You can substitute in your extra-long identifiers if you like and break up in more lines.
The main pitfall in this piece is in the descending case, where
(prev-i)%n
will NOT do what you want.
-
@pleegwat
Pervy what now? :o
-
@izzion Pervy stuff? Where? Where? Where?
-
Yes
Quite apart from that, it keeps the pattern clear. You can substitute in your extra-long identifiers if you like and break up in more lines.
The main pitfall in this piece is in the descending case, where
(prev-i)%n
will NOT do what you want.That's why I did
(prev+n-i)%n
? I think?
-
@tsaukpaetra You had
idx = idx + dir + n % n
. I'm never sure on the precedence there but I think%
is before+
, so it simplifies toidx = idx + dir
.
-
How does JavaScript not have a
sprintf
/String.prototype.format
function built in to the standard library? And before you ask, yes, I know about template literals, and no, they don't seem to be very useful for localization.
-
@tsaukpaetra You had
idx = idx + dir + n % n
. I'm never sure on the precedence there but I think%
is before+
, so it simplifies toidx = idx + dir
.Right, later I corrected that.
-
@tsaukpaetra Not in your OP.
Honestly my main problem with your version is the division of logic. You have half the looping logic in the body, and the search condition in the
for
construct. IMO when doing a search loop the search condition should be in the body (with abreak
) and thefor
should be concerned with looping through the entire set being searched exactly once.
-
@cursorkeys said in WTF Bites:
Not a totally ridiculous premise, I mean you could if you were armed with a copy of the PE format and you were insane but this article isn't concerned with pesky things like the PE format or reality:
To create an "exe" file in Notepad, you must understand and know a programming language such as C++.
...
Step 4
Type the "exe" file for the program you want to create from the programming language into Notepad. Type the file in C++ programming language.They say "C++", but then they tell you to write what's basically compiled machine code directly into the file. I mean, even Assembly would be closer to that than C++, but even that's not quite right.
-
@pleegwat you used break. I like my
do ... while
version better.
-
A colleague was having problems doing a cherrypick. He copied the relevant command from the wiki page I wrote lo these many years ago, edited it, and was getting an inexplicable error:
% svn merge –c 31734 svn://host/repo/branches/sourcebranch svn: E195002: Invalid merge source '–c'; a working copy path can only be used with a repository revision (a number, a date, or head)
It took quite a while to figure out. See if you can as well.
Idiotic Confluence had changed the hyphen (in a code block!) to an en dash.
-
@tsaukpaetra Not in your OP.
Honestly my main problem with your version is the division of logic. You have half the looping logic in the body, and the search condition in the
for
construct. IMO when doing a search loop the search condition should be in the body (with abreak
) and thefor
should be concerned with looping through the entire set being searched exactly once.This is WTF Bites.</sparta>
-
Wait, wait, wait...
I know that hyphen and eM dash are different characters, but I thought that hyphen and eN dash were the same thing!..?
-
I know that hyphen and eM dash are different characters, but I thought that hyphen and eN dash were the same thing!..?
Nope:
-
: U+002D HYPHEN-MINUS
‒
: U+2012 FIGURE DASH
–
: U+2013 EN DASH
—
: U+2014 EM DASHand for completeness:
−
: U+2212 MINUS SIGN
-
@bulb Also, they look different in some fonts.
Here's a slew of different characters; guess which is which!
- - ‐ ‑ ‒ – — ― −
-
That's easy
Ctrl+C
$ unicode
Ctrl+VU+200C ZERO WIDTH NON-JOINER UTF-8: e2 80 8c UTF-16BE: 200c Decimal: ‌ Octal: \020014 Category: Cf (Other, Format) Bidi: BN (Boundary Neutral) U+002D HYPHEN-MINUS UTF-8: 2d UTF-16BE: 002d Decimal: - Octal: \055 - Category: Pd (Punctuation, Dash) Bidi: ES (European Number Separator) U+2010 HYPHEN UTF-8: e2 80 90 UTF-16BE: 2010 Decimal: ‐ Octal: \020020 ‐ Category: Pd (Punctuation, Dash) Bidi: ON (Other Neutrals) U+2011 NON-BREAKING HYPHEN UTF-8: e2 80 91 UTF-16BE: 2011 Decimal: ‑ Octal: \020021 ‑ Category: Pd (Punctuation, Dash) Bidi: ON (Other Neutrals) Decomposition: <noBreak> 2010 U+2012 FIGURE DASH UTF-8: e2 80 92 UTF-16BE: 2012 Decimal: ‒ Octal: \020022 ‒ Category: Pd (Punctuation, Dash) Bidi: ON (Other Neutrals) U+2013 EN DASH UTF-8: e2 80 93 UTF-16BE: 2013 Decimal: – Octal: \020023 – Category: Pd (Punctuation, Dash) Bidi: ON (Other Neutrals) U+2014 EM DASH UTF-8: e2 80 94 UTF-16BE: 2014 Decimal: — Octal: \020024 — Category: Pd (Punctuation, Dash) Bidi: ON (Other Neutrals) U+2015 HORIZONTAL BAR UTF-8: e2 80 95 UTF-16BE: 2015 Decimal: ― Octal: \020025 ― Category: Pd (Punctuation, Dash) Bidi: ON (Other Neutrals) U+2212 MINUS SIGN UTF-8: e2 88 92 UTF-16BE: 2212 Decimal: − Octal: \021022 − Category: Sm (Symbol, Math) Bidi: ES (European Number Separator)
:-D ;-)
-
@bulb The ZWNJ is just to stop from doing markdown stupids.
-
-
No, this is known as wish it was two factor.
Oh well, another Keepass entry I suppose
-
https://thumbs.gfycat.com/LeanNextAfricanbushviper-size_restricted.gif
I tried to scroll back up in your GIF.
-
Well, I found an Android WTF. So I was watching some Youtube yesterday on my iPad and I was low on data. But whatever, a couple hours left of the month so if I run out it's no biggie. I did get one automated SMS saying I should buy more data because I was running out that I ignored.
Jump forward to 23:50-ish when I actually did run out of data. So my phone got the special "no more data" system notification from Android. Which it got just slightly after midnight. So my phone ended up in a state where it would flat out refuse to connect to websites because it was under the impression there was no more data left, despite the fact that I had all of the data available from there being a new month. Also, as that notification cannot be removed at all (except if I buy more data from my provider I guess) I had to resort to rebooting my phone to make it go away. Meanwhile, the iPad had no issues with the whole deal. I guess Apple can score a rare victory over Android for that.
-
@atazhaia Don't you have to manually enter this information? On my android phone, I have to manually set limits via Connections -> Data Usage -> Billing Cycle and Data Warning in the settings menu. There's you also select the date on which a new billing period begins.
FWIW, I bought my phone independently, so there was no provider-specific stuff pre-installed/setup or so.
-
@greybeard Stupid people who copy and paste... I'm so used to that happening that whenever I type out commands in an email it's muscle memory to type <argument> <space> <Ctrl-Z to reverse the autocorrect>. I could also just DISABLE THE AUTOCORRECT, but... it's muscle memory now...
-
@cvi There are options for setting a limit and warning that are specific to the phone itself. I got warning set up, but I don't have a limit set as previously they'd just drop my speed to Edge speeds once I used up my data.
Also, I got shared data between my phone and tablet so setting a hard limit on either device wont work well.
-
Found hiding deep into our codebase:
#ifdef WIN32 char cmd[512]; sprintf(cmd, "/c xcopy /y \"%s\" \"%s\"", source, dest); wchar_t wcmd[512]; mbstowcs(wcmd, cmd, 512); SHELLEXECUTEINFO info = {0}; /* various info.xxx = yyy */ info.lpFile = L"cmd"; info.lpParameters = wcmd; if (ShellExecuteEx(&info)) { /* success */ } else { /* error */ } #endif
Count the for me, please.
Bonus question: why does this function fail with a Windows error popup
Windows cannot find ´c´. Make sure you typed the name correctly, and then try again.
?
-
Count the for me, please.
- WinAPI (unlike POSIX) has a
CopyFile
function; there is no excuse for not using it. xcopy
is an external command. There is no reason to run it throughcmd /c
.- There is a
swprintf
function to print directly into a wide string (and yes, it can take narrow arguments while writing wide output too), so the extrambstowcs
is silly.
The rest looks like standard WinAPI call to me though. The only reason that comes to my mind why it would not find just
c
is that the narrow version of the function is actually called (i.e.UNICODE
is not defined), but in that case theinfo.lpFile = L"cmd"
shouldn't compile, so I don't know.
- WinAPI (unlike POSIX) has a
-
WinAPI (unlike POSIX) has a CopyFile function; there is no excuse for not using it.
A simple google indicates that copies files; xcopy recursively copies directories. And a file data copy loop is only about 10 lines of code, I don't think it's a particularly glaring omission.
-
The only reason that comes to my mind why it would not find just
c
is that the narrow version of the function is actually called (i.e.UNICODE
is not defined)Yep. You're clearly much more Windows-savvy than I am, it took me much longer to find out
but in that case the
info.lpFile = L"cmd"
shouldn't compile, so I don't know.Code does compile, but with a warning. Which, as we all know, means the code is fine and we can commit and move on, right?
Bonus-bonus: how to edit the code to make it work (I said "make it work", not "make it good code") -- code-golf style i.e. changing as few chars as possible. I found a 2-chars-added/0-removed solution.
-
@pleegwat That code is actually copying a single file (not obvious from the snippet, but
source
is a full path to file, not a directory).
-
@pleegwat That code is actually copying a single file (not obvious from the snippet, but
source
is a full path to file, not a directory).That actually makes it unfortunately a bit harder to refactor to use
CopyFile
, since that one requires a full destination path and I only have a directory -- i.e. I haveC:\path\to\source\file
andC:\path\to\dest
, so to callCopyFile
I would need to extractfile
from the first one and add to the second, or change the function signature and all places where it's used, so it's... ugh
-
Count the for me, please.
- using C++, or C or whatever that shit is
- mbstowcs. Did the person who came up with that method just mash their hand over the keyboard?
-
Count the for me, please.
- using C++, or C or whatever that shit is
C, for weird and historical reasons. Be glad it's not FORTRAN, because if it had been so it would likely have been FORTRAN 77. And I don't know how that interfaces with Windows, so I guess the result would have been much uglier (I mean, even uglier than FORTRAN 77 by itself...).
- mbstowcs. Did the person who came up with that method just mash their hand over the keyboard?
That was my first reaction as well. I sure hope I never need to use that function, 'cause there is no way I can remember its name. Even Unix commands seem less cryptic, and that's saying a lot.
-
@remi in addition to what others have mentioned, I don't see any mention of the 512 limit in that
sprintf
call, so it could potentially create a buffer overflow ifsource
anddest
ever happen to not be properly capped.
-
@lb_ Ah, good, I was starting to worry that no-one was seeing that one! phew
(EDIT: and no, they are not properly capped in any way before calling this function, so long paths will definitely cause a buffer overflow)
-
@lb_ Ah, good, I was starting to worry that no-one was seeing that one! phew
I was about to post that - then for some strange reason I decided to finish reading the thread. I must be broken today...
-
-
@timebandit said in WTF Bites:
I must be broken today...
Did you try to turn it off and on again ?
Yes. And I missed the train and had to drive.
-
@dcon Don't worry, that monstruosity is on its way out.
It turned out that the function is only called in a handful of places (and it's an internal function so I don't have to worry about other modules using it (*)), and always in the same way, so changing the way it's called to add the destination file name is easy.
So I've replaced it by
CopyFile()
, and they lived happily ever after...(*) and if, despite it being clearly marked as internal, someone managed to use it in another module and their code is now broken, well that'll teach them to use an internal function
-
Translation:
Incorrect password or new invalid password. New password minimum length: 0. Non-alphanumeric characters required: 1.
So, my new password could be just @
-
@timebandit
Usually I have to turn it on first, and then it turns itself off at the end of its cycle
-
- mbstowcs. Did the person who came up with that method just mash their hand over the keyboard?
That was my first reaction as well. I sure hope I never need to use that function, 'cause there is no way I can remember its name. Even Unix commands seem less cryptic, and that's saying a lot.
That's clearly "multi-byte string to wide-character string".
-
@tsaukpaetra said in WTF Bites:
Made a loop to move to the next delectable button in an array:
Do you have a loop for the buttons that don't taste so good?
-