WTF Bites
-
Filed under: you had one job!
-
WTF of my day: So, we have this honking projector hanging from the ceiling in the middle of our auditorium. In the floor below there are four (covered) floor outlet boxes with connectors for audio, light, video and power.
The connector for video is actually a RJ45 port because the cable is about 30 meters long (from the middle of the floor to the wall, up the wall and then from the wall to the middle of the ceiling) connected to a media converter because HDMI doesn't like lengths above 5 meters.
However, we rather quickly discovered (who'da thunk it!) that the real need for a video connector is to be on the stage - turns out that most presenters like it if they can see the screen of their laptops and actually don't like it when said laptop has to reside in the middle of the audience. Yeah, I know, big surprise. Don't look at me, I didn't have that brainfart.So, someone ran another network cable from the stage to the floor outlet box, plonked a dual RJ45 jack in there and connected them with a patch cable. Problem solved!
Yeah, no. First of all, he used some cheap-ass plastic jack and didn't even bother to wire the shielding correctly. Not nice but it did work at some point.
Second problem: The cable he ran was a bit too long (several meters of it). Instead of cutting the superfluous bits of cable he simply crammed everything in there.
Third problem: He didn't anchor the jack in any way but simply crammed that one in there as well.As anyone with a bit of experience will tell you: Cramming wires using very sharp angles into too small boxes won't make the wires happy.
Eventually we had a cable break.
I then had to take pictures of the whole thing, explain it to a group of six people (I'm not sure what's so complicated to understand about "this cable is broken!") and finally got bitched at by a network technician because we were not using a CAT6e patch cable (Dude, this is a single-purpose single-way cable not connected to a network in any way! Also, the media converters are perfectly happy with 100 MBit! Also, dude, chill, I'm not the one who did this - in fact I was specifically forbidden from repairing anything!)
Anyways, technician did his thing and things seemed to work.
Come Monday and the cable crapped out again. That was the point where I finally got myself a cheap network cable tester. This is how it should look like:
This is what greeted me:
Plus, there's this (the crooked jack is not the one with the problem, mind!)
Please note that this was the first time I opened the floor box since the technician had done his thing. Quality work, people!
-
@LaoC
in the Windows 10 thread.
-
-
@Tsaukpaetra Yeah, I'm definitely doing the "Not impressed" face should I see the guy again
-
Status: Why does Visual Studio offer DefaultRequestHeaders in the property-assignment-thingy if you're not allowed to assign to it?
What is the proper way to specify this then?
(Yes I'm just taking the constructed object and adding headers afterward, but the initial question remains)
-
@Rhywden Maybe get something like this:
I’m not perfectly happy with these things, but they mostly work well enough and seem to be made just for your scenario.
(Also, OMG why is this so expensive for what’s basically a general-purpose Chromecast?!)
-
-
Status: I want to iterate the properties of a specific object, but only most of them, to run the
ToString()
operation on them and, if not null, add them into a collection of strings.What's the easiest way (outside of reflection) to do this?
I honestly don't think there is other than creating a helper method and just banging them into the list one after the other...
-
-
@TimeBandit said in WTF Bites:
@Tsaukpaetra said in WTF Bites:
Licensing
Of what, HDMI?
The Chromecast is also HDMI
The BitchGiveMeMoney certificate license, of course!
-
@Tsaukpaetra said in WTF Bites:
Status: I want to iterate the properties of a specific object, but only most of them, to run the
ToString()
operation on them and, if not null, add them into a collection of strings.What's the easiest way (outside of reflection) to do this?
I honestly don't think there is other than creating a helper method and just banging them into the list one after the other...
You just described reflection. So yes, helper method.
-
@Tsaukpaetra said in WTF Bites:
Status: I want to iterate the properties of a specific object, but only most of them, to run the
ToString()
operation on them and, if not null, add them into a collection of strings.What's the easiest way (outside of reflection) to do this?
I honestly don't think there is other than creating a helper method and just banging them into the list one after the other...
Outside of reflection necessarily requires the list of properties to be known in advance, in which case you can do:
listOfStrings = listOfStrings.Concat(new []{ thing.Prop1?.ToString(), thing.Prop2.ToString(), // Prop2 is a not nullable type thing.Prop3?.ToString(), }.Where(s => s != null)).ToList();
-
@Tsaukpaetra said in WTF Bites:
Status: I want to iterate the properties of a specific object, but only most of them, to run the
ToString()
operation on them and, if not null, add them into a collection of strings.What's the easiest way (outside of reflection) to do this?
I honestly don't think there is other than creating a helper method and just banging them into the list one after the other...
Outside of reflection necessarily requires the list of properties to be known in advance, in which case you can do:
listOfStrings = listOfStrings.Concat(new []{
thing.Prop1?.ToString(),
thing.Prop2.ToString(), // Prop2 is a not nullable type
thing.Prop3?.ToString(),
}.Where(s => s != null)).ToList();@pie_flavor said in WTF Bites:
@Tsaukpaetra said in WTF Bites:
Status: I want to iterate the properties of a specific object, but only most of them, to run the
ToString()
operation on them and, if not null, add them into a collection of strings.What's the easiest way (outside of reflection) to do this?
I honestly don't think there is other than creating a helper method and just banging them into the list one after the other...
You just described reflection. So yes, helper method.
Yeah, I ended up just banging it.
The end result is the same either way, and neither code is less or more obscure than the other....
-
@Tsaukpaetra tip: C# has a
nameof
operator (e.g.nameof(Foo.Bar)
is"Bar"
), ensuring that you don't misspell anything and refactorings don't miss anything.
-
@Tsaukpaetra said in WTF Bites:
I ended up just banging it.
You're trying too hard to get into QooC.
-
@HardwareGeek said in WTF Bites:
@Tsaukpaetra said in WTF Bites:
I ended up just banging it.
You're trying too hard to get into QooC.
Nah, just followed up on an implicit promise from before.
-
got bitched at by a network technician because we were not using a CAT6e patch cable
If your network technician is bitching at you for not using Cat 6e cables he's not a very good network technician as there is no cable standard called 6e. The standard is called 6A, because who needs consistent naming schemes for stuff?
-
@Tsaukpaetra Expression trees!
Edit: see revised AddIfNotNull in the other post below for a version which can also get the member's name.
class Thing { public int Int = 42; public string String = "Hello mold"; public bool Bool; } static void Main() { Thing thing = new Thing(); string output = ""; AddIfNotNull(ref output, () => thing.Int); AddIfNotNull(ref output, () => thing.String); AddIfNotNull(ref output, () => thing.Bool); Console.WriteLine(output); // 42Hello moldFalse } static void AddIfNotNull(ref string output, Expression<Func<object>> expr) { Func<object> compiled = expr.Compile(); object value = compiled(); if(value != null) { output += value.ToString(); } }
-
Expression trees!
I've only very slightly dabbled in those, and much of what I've "written" was copy-pasta from SO so.....
-
Gordon Bennet, sometimes a LambdaExpression's Body is a UnaryExpression, sometimes it's directly a FieldExpression.
static void AddIfNotNull(ref string output, Expression<Func<object>> expr) { LambdaExpression lambda = expr as LambdaExpression; UnaryExpression unary = lambda.Body as UnaryExpression; MemberExpression member = lambda.Body as MemberExpression; if(member == null && unary != null){ // Being consistent was too much to ask member = unary.Operand as MemberExpression; } string propName = member.Member.Name; Func<object> compiled = expr.Compile(); object value = compiled(); if(value != null) { output += $"{propName} {value.ToString()} "; } }
WOMM for the cases I've tested (including a property of class type).
-
-
@Tsaukpaetra said in WTF Bites:
is not using rainbow brackets (2)
My existing rainbow-izer broke when I moved to 2017 and I haven't bothered reinstalling it.
-
@Tsaukpaetra said in WTF Bites:
What is the proper way to specify this then?
(Yes I'm just taking the constructed object and adding headers afterward, but the initial question remains)You expect the author to have actually thought through what would be useful? I stopped expecting that with Microsoft libraries long ago.
-
Status: message from the future!
-
@Tsaukpaetra
uh? 1 January 2019 is well in the past :date_troll:
-
-
-
Blazor syntax bugs me.
To specify an event handler with a lambda function you have to write<button @onclick="@(_ => DoThing("input"))">
The "@" tells the system to switch from HTML to C#, but... why the double quotes?!? Why do I have to quote something that's definitely NOT a string? And yes, the inner quotes just go straight there like that.
It feels dirty. I tried every variation, but no, it has to be exactly like that.
In contrast, if you just have to specify an event handler function, the following options all work fine:<button @onclick="@DoThing">a</button> <button @onclick=@DoThing>a</button> <button @onclick=DoThing>a</button> <button @onclick="DoThing">a</button>
-
@levicki said in WTF Bites:
it would greatly simplify the code?
Prove it.
@levicki said in WTF Bites:
a ref here
Sorry, been spending too much time in C++ world lately.
-
@levicki said in WTF Bites:
AsString
Note that I over-simplified the task I accomplished. Everyone seems hung up on the "make it a single string", and that's not what I said I was doing, but that's fine, feel free to keep going...
-
So I recently got this drive case for kicks and giggles:
https://www.amazon.com/gp/product/B01CFLOV4M/
First off, the instruction booklet says max 8 TB per drive. Really not sure why, but whatever.
Second, take a good look at the provided pictures. Notice anything strange? Well, besides the awkwardly-placed power port?
Yeah, that's right, NO VENTILATION!!!
Sure, it has a fan, but there aren't any other holes or other ways of air-ingress, so the fan is literally useless.
Reviews on Amazon say "Yeah duh, drive killer for sure".
I'm going to simply cut holes into the faceplate. Maybe install a bigger fan on the front.
-
@Tsaukpaetra said in WTF Bites:
@levicki said in WTF Bites:
it would greatly simplify the code?
Prove it.
Well... it is the sort of use case that reflection was designed for.
-
@Tsaukpaetra said in WTF Bites:
@levicki said in WTF Bites:
it would greatly simplify the code?
Prove it.
Well... it is the sort of use case that reflection was designed for.
I must be
. Every time I use reflection the code is messy, complicated, long, and (if SO is to be believed) less performant.
-
@Tsaukpaetra said in WTF Bites:
Yeah, that's right, NO VENTILATION!!!
Sure, it has a fan, but there aren't any other holes or other ways of air-ingress, so the fan is literally useless.But it's a SMART FAN! EASY TO REPLACE!
So the these aren't vents that allow air in?
-
@loopback0 said in WTF Bites:
@Tsaukpaetra said in WTF Bites:
Yeah, that's right, NO VENTILATION!!!
Sure, it has a fan, but there aren't any other holes or other ways of air-ingress, so the fan is literally useless.But it's a SMART FAN! EASY TO REPLACE!
So the these aren't vents that allow air in?
Nope! It's a solid piece of plastic. No holes anywhere but the fan!
-
-
@Tsaukpaetra said in WTF Bites:
Nope! It's a solid piece of plastic. No holes anywhere but the fan!
The Amazon listing has a picture with arrows indicating airflow in through those slots. You mean to tell me the ad lies???
According to the reviews, even if those are, in fact, ventilation openings on at least some units, the airflow is woefully inadequate, along with other problems.
-
@HardwareGeek said in WTF Bites:
airflow is woefully inadequate, along with other problems.
Yes, you can feel (and hear!) the difference opening the front panel.
I also plan on transplanting a fan controller into the airspace above the drives (lots of room there!) Or possibly putting my Latte Panda there.
.
-
@topspin Yeah, no. First of all, we're already using that (Microsoft's Miracast adapter to be exact) and while it works fine for presentations, we sometimes also want to show videos. Which, as you may have discovered, either are amazingly fickle (because you have to up the transfer rate which in turn makes reliability go down) or rather juddery.
Also, we usually would like for those videos to have audio as well - the projector has some smallish speakers but not suited for an auditorium filled with people. And you may also have discovered that running audio and video separately (and the latter one through a wireless solution) makes them go out of sync.
Plus, as I already hinted at, there's a general lack of reliability - sometimes the connection will work for hours on end. And sometimes it will crap out every 5 minutes or so.
For events with 200+ people attending I rather like the reliable "plug in and forget" solutions.
-
@Tsaukpaetra said in WTF Bites:
is not using rainbow brackets (2)
is using if-nulls instead of just
return this.trackingSpan ??= GetPresentationSpan()
. With a minor bonus for== null
instead ofis null
.
-
@pie_flavor said in WTF Bites:
With a minor bonus for
== null
instead ofis null
.What’s the difference?
Also,
is that font, especially the f in if.
-
@Tsaukpaetra said in WTF Bites:
What is the proper way to specify this then?
Add, change or remove headers from the provided collection, without swapping the collection itself for a different one.
@Tsaukpaetra said in WTF Bites:
What's the easiest way (outside of reflection) to do this?
Just use reflection!You have to create a helper method and bang them into the list one after another. If this is C#, you could use reflection and expression trees to build the helper method for you at runtime, or you could use Roslyn and the Text Template Transformation Toolkit to synthesize the method at compile time, but if it's C++ or those solutions are unpalatable, you have to write the helper yourself.
-- Maybe
AddIfNotNull
should be an extension method.I prefer using lines ("Visualize code structure") instead of matching colors.
@Tsaukpaetra said in WTF Bites:
Every time I use reflection the code is messy, complicated, long, and (if SO is to be believed) less performant.
If you cache the
MethodInfo
s it can be as performant, and in this specific case (enumerate all public properties/fields either tagged with a "use this" attribute or not tagged with a "don't use this" attribute) it's actually much cleaner and slightly shorter. Complicated... well, I'll give you that one.
-
@pie_flavor said in WTF Bites:
With a minor bonus for
== null
instead ofis null
.What’s the difference?
Also,
is that font, especially the f in if.
operator==
is still invoked if the right operand is null.
-
@pie_flavor I guess I was thinking of Java where
==
is pointer comparison, notequals
.
-
@topspin if only
operator==
wasEquals
rather than them being two separate things.
-
@TwelveBaud said in WTF Bites:
@Tsaukpaetra said in WTF Bites:
What is the proper way to specify this then?
Add, change or remove headers from the provided collection, without swapping the collection itself for a different one.
Right, but how to do that in the way shown?
-
Status: Internet Explorer has long had the ability to save (only somewhat broken) web pages.
This user decided that the best place for these to to is My Pictures.
In addition to, you know, actual pictures.
This is the same person who opens PDFs in Word.
-
@pie_flavor said in WTF Bites:
@topspin if only
operator==
wasEquals
rather than them being two separate things.Sometimes I feel Ben is clear and comprehensible compared to you.
-
@topspin C# has three methods of equality -
==
,IEquatable.Equals
, andobject.Equals
. All three are overridable, and all three could mean separate things.