AboutC hacken ist Krieg!
SkillsC, assembly, embedded, electronics
Joined devRant on 5/26/2018
Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
*LOL* The animal rights organisation PETA criticises the use of donkeys in the traditional Passion play in Oberammergau, Bavaria, Germany. PETA claims that Jesus would ride into Jerusalem on an e-scooter.
Have you always been missing ads in CLI applications? Have you been wondering how to bring such modern browsing experience to CLI? NPM has solved this problem, it has CLI ads now!
However, the are already people who spoil this great new experience with CLI ad blockers:
Yeah, my new e-scooter arrived today! I just have to get the insurance sticker that is legally required here; I'll do that on Monday.5
Toilets and race conditions!
A co-worker asked me what issues multi-threading and shared memory can have. So I explained him that stuff with the lock. He wasn't quite sure whether he got it.
Me: imagine you go to the toilet. You check whether there's enough toilet paper in the stall, and it is. BUT now someone else comes in, does business and uses up all paper. CPUs can do shit very fast, can't they? Yeah and now you're sitting on the bowl, and BAMM out of paper. This wouldn't have happened if you had locked the stall, right?
Him: yeah. And with a single thread?
Me: well if you're alone at home in your appartment, there's no reason to lock the door because there's nobody to interfere.
Him: ah, I see. And if I have two threads, but no shared memory, then it is as if my wife and me are at home with each a toilet of our own, then we don't need to lock either.
Ah well, it's double out of fashion because smoking is on the black list of the health maniacs, and nobody smokes pipes anyway. BUT! filling a pipe and smoking it for easily half an hour is quite some pleasure!74
Meeting with a co-worker who is supposed to do a code analysis on a large legacy project. Actually, HER project - she inherited it already years ago, and the original devs aren't in the company anymore.
Her: customer is asking this and that analysis.
Me: easily two weeks.
Her: but who will do that?
Me: you of course.
Her: but I don't know most of the code.
Me: me neither.
Her: and I don't know the protocols.
Me: google them. I'd have to do the same.
Really, I told her to google shit, which I consider as quite a slap for a co-worker. Basically, she tried to offload a complex analysis because she just wants the low effort parts of the job.
Won't happen. DO YOUR FUCKING JOB!14
Talk with a co-worker who has a bit of a motivational problem.
Him: if I had more fun, I would be more productive.
Me: you're not here for fun, that's why they pay us.
Him: how are you motivated?
Me: by money.
A bit later.
Him: do you plan for retirement some day?
Me: no. By then, there won't be retirement anymore. We will eat fried rats in the street.
He starts understanding why I'm wearing black metal shirts.10
Yeaaahhh that moment when the program flawlessly crunches through ten thousands of files, only limited by the slowish HDD! :-)
In full multi-threading, tons of dynamic buffer resizing, pointer shit left and right, also two star programming, and everything written in raw C!14
Yeah so I quickly hacked stuff together. Why make it beautiful before I know whether it will actually do? Hack now, refactor later!
Yeah and then that moment in refactoring where main() gets under 700 lines and I don't know whether what I'm feeling is joy or despair. Gaaaahhhh!
At least I have also written automatic tests so that I can see when something breaks.4
LOL that's why I love C!
The function pointer cast for strcmp because qsort expects a compare function with two const void * pointers instead of two const char * pointers, that's just beautiful.
Not to mention the hack to abuse strcmp on a struct - which just works because the first struct member is a string and the rest just gets swapped with memcpy as opaque data.
I guess that wouldn't pass a code review at work. :-)9
SPDX. Actually a cool idea, you slap one line of comment in your source files that gives the licence. Easy to understand at a glance, and grep friendly. Also no more "huh what exactly does this licence here say, is that MIT, BSD with or without shit or what".
But once you have something simple, you can bet some design committee tries to "improve" it and cover everything imaginable.
The result looks like this (see also screenshot): https://wiki.spdx.org/view/...
Holy shit. What was that about? Simplifying crap? Yeah sure that's totally what it looks like.3
Today, my PM dropped by in the morning and mentioned she had some customer feedback on some item in a project where I'm the holiday replacement for someone else. I already had work to do, so that kind of interruption wasn't welcome.
"Well yeah, just forward it to me, I'll see what I can do", I told her. She agreed. Half an hour later, still no email from her. Hey, that looked promising!
For the rest of the day, I didn't talk to her, avoided speaking at all when she was near and even sneaked by her room (open doors) in silent mode lest I drew her attention and she might have remembered the email.
Until afternoon when I went home, still no email. Success! :-)5
Somehow, a continue instead of break in a switch-case looks weird. Although it makes perfectly sense with regard to the outer for loop.8
So I'm writing some multithreaded shit in C that is supposed to work cross-platform. MingW has Posix threads for Windows, so that saved already half of the platform dependency. The other half was that these threads need to run external programs.
Well, there's system(), right? Uhm yes, but it sucks. It's incredibly slow on Windows, and it looks like you can have only one system() call ongoing at the same time. Which kinda defeats the multithreaded driver. Ok, but there's CreateProcessA(), and that doesn't suck.
Fine, now for Linux. The fork/exec hack is quite ugly, but it works and is even fast. Just never use fork() without immediate exec(). First try under Cygwin... crap I fork bombed my system! What is this shit? Ah I fucked up the path names so that the external executable couldn't be run.
Lesson learnt: put an exit() right after the exec() in the path for child process. Should never be reached, but if it goes there, the exit() at least prevents a fork bomb.
Well yeah, sort of works under Cygwin, but only with up to 3 threads. Beyond that, it seems like fork() at some point gives two processes the same PID, and then shit hangs.
Even slapping a mutex around the fork and releasing it only in the parent process didn't help. Fork in Cygwin is like a fork in the ass. posix_spawn() should work better because it can be mapped more easily to the Windows model, but still no dice.
OK, testing under real Linux. Yeah, no issues with that one! But instead, I get some obscure "free(): invalid size" abort. What the fuck would that even mean?! Checking my free() calls: all fine.
Time to fire up GDB in the terminal! Put a catch on the abort signal, mh got just hex data. Shit I forgot to compile with -O0 and -g. Next try. Backtrace shows the full call trace, back to the originating line in my program - which is fclose() on a file.
Ahhh I remember! Under Linux, fclosing a file that is already closed makes the program crash. So probably I was closing it twice. Checking back.. yeah that's where it was.
Shit runs fast on several cores now!9
The seventh fishcake.
Usually, I buy six fishcakes in the weekly shopping. Today, the seller accidentally put on seven, wanted to put back the seventh, but it fell into the egg salad. She took the fishcake and was about to throw it away because no customer would buy a fish cake with egg salad sauce on it. I intervened in time and bought it to avoid throwing food away.
Afterwards, I thought about how sick and decadent it actually is that it would have been perfectly normal to throw food away just because food was sticking on the food.13
Yeah Statler and Waldorf are my new role models. A code review in S&W style should be quite a killer, haha.
- I've never seen anything like this before.
- And I hope I'll never see anything like this again!8
Apple you drove of delusional suckers! When will your retarded fashion devices finally support WEBP?!
A gallery page with images, and thanks to WEBP, it's 408 kB. Because Google made WEBP and handed out a well documented CLI FOSS compression tool that even can convert the source PNGs to lossy WEBP with bloody transparency. Well done, Google!
Except that Apple's shitty management can't take it that Google actually made something nice, so no WEBP. Instead, JPEG-2000 that enjoys nearly no fucking tool support. The free tools that even can deal with that mostly don't support transparency, and the encoder sucks donkeys so that JPEG still fucks JPEG-2000 big time.
So it's JPEG with matching background for iOS. Fine, but since JPEG's blocky artifacts are much more visible, the compression can't be that high, and it's 769 kB. That's 88% more image data for Shittari than for non-retarded browsers and even Edge! EDGE!!
Oh and if the user changes light/dark system mode according to surrounding light conditions, guess what happens? Yep, since JPEG doesn't support transparency, now it's different JPEGs with dark background via the media query in the "picture" element, and it's another 754 kB download. Bloody 1523 kB instead of 408 kB, that's a factor of 3.7!
Fuck your ass Crapple, with an electric eel!19
Ah I love that movie.. Hero, from 2002. I've seen it in the cinema three times. It's a real marvel, especially the scene where the forest turns red right after Snow killed Moon.
I also like how the quotes are adaptable:
Martial arts and programming are quite different, but they are based on the same principle: striving for highest perfection.
The essence of programming reveals itself through study and meditation.
(The latter one is also one of my favourite lines at work when being asked how come I know some esoteric stuff: it revealed itself through study and meditation.)5
Mozilla you stinking kangaroo pouches!
When you set an object's CSS translation via JS like so:
and then read it back, every browser including FF until 66 gives this, with additional space:
However, bloody FF 67 returns "translate(0px)". Because it's always a good idea to just introduce external changes nilly-willy, right?
That screwed up my crappy string slicing because it relied on the presence of the comma. It was a quick and dirty solution, but with additional future proof if/else logic, it wouldn't even be quick anymore.
Besides, the whole string slicing looked like yo-yo code anyway so that I instead added shadow integer variables to the objects. That solution not only works, but is even faster.21
Uh-oh I fucked up.
Not at work, but with my website where I had an email forwarder to an external address. The forwarding was everything so that I could do the spam filtering and occasional check in one place. Unfortunately, that triggered the spam detection at the external address (after some years!), and my provider ended up on a blacklist.
That got me a pretty angry mail from my hosting provider who had already disabled the forwarding and wanted to make sure that I understood the issue and would not put it in again.
I thought about whether they had fucked up because it was even possible to do that, or whether I had fucked up because I should have known. Hm yeah I opted for the latter and apologised.
The support guy seemed happy that I didn't try to argue (possibly like other customers...), and advised that I just should add another account in my email client. Sure, at least that will prevent this shit from happening again.
He also mentioned that every single blacklist issue they had experienced in this year was accidental due to external forwarding issues and that they would consider just disabling it altogether.
Which is probably a smart move, just as hint for these ranters here who work at hosting companies. Or at least only enable external forwarding if spam assassin or so is in place.3
So I've kicked off the motorcycle season for this year! Scanned some nice roads for speed control traps or road dirt, then the same route with more WABROOOOOO.
That machine is whopping 19 years old, and I still like it as much as on the first day when I bought it as new. Plus that it doesn't have software nonsense, not even injection. Means, it fucking works.9
What a coincidence. JQuery gets an update to 3.4.0 - and I removed the JQuery dependency that a mid-sized widget (15 kB minified) needed.
Rewriting the selector, css and trim stuff was easy. Each, children, append, empty, remove and extend were not too hard. Animations gave me more headache, but in the end, JS triggered CSS transitions worked nicely.
I was able to shave off the usual 30 kB over the wire for JQuery, and the whole thing seems snappier. Finally, I'm at vanilla everything!
Of course, it's largely due to JQuery's merits that vanilla JS is where it is today. So, thank you JQuery, and farewell.4
What's wrong with Mozilla?!
Savvy webdevs use link preloading to break up dependency chains for late discovered resources, and users like the faster loading as result. Firefox 56 started supporting that two and a half years ago. Turned out they had screwed up and it didn't work with non-cacheable resources. So Mozilla "fixed" that by disabling the feature altogether behind some config flag.
And they left it at that - still not supported. They even had patches, but decided not to merge them and instead try something different, some day.
Is Firefox becoming the new IE or what?6
I came around the corner in the corridor where a senior PM talked with an engineer.
PM: ... and that's why a good team is so important and we also need sensitive people.
Me: do we have some here?
PM: oh yes, I'm highly sensitive.
Me: one learns something new every day. :-)1
In my master equivalent thesis, I was supposed to build upon a year of work from my predecessors. However, I argued that it had no actual foundation and would never work properly, so I threw it away and started from scratch.
The prof was astonished and commented "well it's your thesis", insinuating that the risk was on me. Turned out I had been right.2
Interesting bug hunt!
Got called in because a co-team had a strange bug and couldn't make sense of it. After a compiler update, things had stopped working.
They had already hunted down the bug to something equivalent to the screenshot and put a breakpoint on the if-statement. The memory window showed the memory content, and it was indeed 42. However, the debugger would still jump over do_stuff(), both in single step and when setting a breakpoint on the function call. Very unusual, but the rest worked.
Looking closer, I noticed that the pointer's content was an odd number, but was supposed to be of type uint32_t *. So I dug out the controller's manual and looked up the instruction set what it would do with a 32 bit load from an unaligned address: the most braindead thing possible, it would just ignore the lowest two address bits. So the actual load happened from a different address, that's why the comparison failed.
I think the debugger fetched the memory content bytewise because that would work for any kind of data structure with only one code path, that's how it bypassed the alignment issue. Nice pitfall!
Investigating further why the pointer was off, it turned out that it pointed into an underlying array of type char. The offset into the array was correctly divisible by 4, but the beginning had no alignment, and a char array doesn't need one. I checked the mapfiles and indeed, the old compiler had put the array to a 4 byte boundary and the new one didn't.
Sure enough, after giving the array a 4 byte alignment directive, the code worked as intended.9
Code review, here the simplified version. What the fuck has to be wrong with someone who seriously codes the first variant in production code?!19