Help Bites


  • Considered Harmful

    @dkf said in Help Bites:

    prevent altering things like the static string table

    Augh, now I miss ResEdit.



  • If you don't want to have an external text file and needs something that works on Linux, a variation on @dkf's idea would be adding a custom section in your executable file. Figuring out how to do that is left as an exercise for the reader.

    (There are probably linker options to do so, and/or utilities to add a section to an existing executable file. But I'm too :kneeling_warthog: to dig into it.)


  • Java Dev

    @remi I know in the past we just put it in a shared object somewhere. But then we only cared about identifying builds originating from the build server, which were always full rebuilds.

    We did have a different value to identify dev builds, but seeing a dev build externally would mean something had gone wrong already.


  • Java Dev

    We've relatively recently started working with git. I want to write a quick script, which I will run on login, which will print the following information about a git repository:

    • How many commits in origin/master are not visible in the current branch
    • What is the age of the oldest such commit
    • What is the age of the newest such commit

    The main intent here is to be alerted if the repository is 'out of date' and badly needs a refresh. Thus, the oldest invisible commit is probably the most important metric, and I may want to display a marker if this is older than a certain age.

    Does anyone know a straightforward way to obtain this information?


  • Java Dev

    @PleegWat Partial answer to my own question:

    • Must git fetch first, since you don't have access to things which don't exist in local repo
    • git log HEAD..origin/master selects the commits I'm interested in, presuming those commits have been fetched.
    • git log --oneline is close, but doesn't hold date information.

    I'll have to play around for an alternative git log format which does include date info. And/or write some awk.



  • @PleegWat

    git show -s --format=%ci HEAD..origin/master seems to work?


  • Discourse touched me in a no-no place

    @PleegWat said in Help Bites:

    @PleegWat Partial answer to my own question:

    • Must git fetch first, since you don't have access to things which don't exist in local repo

    You probably also want to set fetch.prune to true in the configuration so that when the origin repo deletes a branch you stop tracking it locally. (It won't nuke any actual local branches, just the remote tracking ones; for example, if some madman kills master on the origin server, you'll have origin/master removed but not your own master. Whacking, or changing/renaming, the default branch will break things... but that's a pretty rare operation.)



  • @dkf said in Help Bites:

    changing/renaming, the default branch will break things... but that's a pretty rare operation

    With the current wokeness about "master"? Not as rare... (luckily I've avoided any of that - and mine is still called 'master')


  • Discourse touched me in a no-no place

    @dcon said in Help Bites:

    Not as rare...

    But you don't rename the silly thing back and forth a few times a day?


  • Java Dev

    @dkf said in Help Bites:

    @PleegWat said in Help Bites:

    @PleegWat Partial answer to my own question:

    • Must git fetch first, since you don't have access to things which don't exist in local repo

    You probably also want to set fetch.prune to true in the configuration so that when the origin repo deletes a branch you stop tracking it locally. (It won't nuke any actual local branches, just the remote tracking ones; for example, if some madman kills master on the origin server, you'll have origin/master removed but not your own master. Whacking, or changing/renaming, the default branch will break things... but that's a pretty rare operation.)

    Eh, given the recommended (not by me) workflow is to re-clone everything for every project, I won't bother automating any of that for anyone else.



  • @dkf said in Help Bites:

    @dcon said in Help Bites:

    Not as rare...

    But you don't rename the silly thing back and forth a few times a day?

    I don't think anyone is that woke.


  • Java Dev

    @remi said in Help Bites:

    @PleegWat

    git show -s --format=%ci HEAD..origin/master seems to work?

    Fleshed out one-liner:

    git log HEAD..origin/master --format=%ct | awk '{ if( date == "" || date > $1 ) date = $1 } END { printf "%s new commits, oldest %s\n", NR, strftime("%c", date) }'


  • Discourse touched me in a no-no place

    @dcon said in Help Bites:

    @dkf said in Help Bites:

    @dcon said in Help Bites:

    Not as rare...

    But you don't rename the silly thing back and forth a few times a day?

    I don't think anyone is that woke.

    You'd need two stubborn idiots fighting back and forth over the name.


  • Java Dev

    @PleegWat And date is bloody useless, since it can be well before when you last rebased your branch, or even before when you started the branch. Just stick with commit count I guess.



  • @remi said in Help Bites:

    That is the nagging doubt that I have in the corner of my mind. If adding this (tiny) feature of being able to print the build date means I have to pay the (not-so-tiny) cost of a doing one or more additional links at each and every build... I will probably find the thing more annoying than useful!

    For ELF you can add a new section to the final binary with your timestamp with objcopy (replace timestamp with commit or whatever is more appropriate):

    date +"%Y-%m-%dT%H:%M:%S%z" > timestamp
    objcopy --add-section REMItimestamp=timestamp inputExecutable outputExecutable
    

    No need to relink.

    Get the data out again:

    objdump -s -j REMItimestamp outputExecutable
    Contents of section REMItimestamp:
     0000 32303233 2d30332d 30375431 393a3336  2023-03-07T19:36
     0010 3a35362b 30303030 0a                 :56+0000.
    

    Don't know the tools for PE32 on Windows off the top of my head, but I don't see why you couldn't pull it off there. (Not sure why signing would be a problem - you'd probably still do that at the end of your build and sign afterwards?)

    Edit: 1/2 :hanzo: by @Zerosquare. There are indeed utilities to add sections to stuff.


  • BINNED

    @cvi as mentioned above, on windows there is (was??) the resource compiler.

    While I still think this whole approach of changing the executable post-link is too complicated (it may be the more “correct” way to do things, but also not very portable), if I needed that then I’d just compile a unique string token into the executable (make sure it’s large enough) and patch that with the desired string after linking. That has the advantage of working no matter if it’s ELF or PE or whatever.



  • @dkf said in Help Bites:

    You'd need two stubborn idiots fighting

    No shortage of those. 👀 :seye:



  • @topspin said in Help Bites:

    @cvi as mentioned above, on windows there is (was??) the resource compiler.

    You can open the EXE directly in Visual Studio and edit the resources there. (In the Open file dialog, click the drop arrow on the Open button to choose the specific editor)



  • @topspin said in Help Bites:

    if I needed that then I’d just compile a unique string token into the executable (make sure it’s large enough) and patch that with the desired string after linking.

    I think I would also prefer that approach, yes.

    Also, @cvi, when adding a section in the final binary with objcopy, would there be a way to get that information back from the code itself? Because I also want the user to be able to tell me the version they're using which typically means printing that somewhere (in an Help window or in the console). Calling objdump is beyond them, simply because they don't really know where the actual binary lives (they call a script which sets some environment and calls the binary).

    Patching an existing string token means I can easily access that token from the code.


  • Considered Harmful

    @dkf said in Help Bites:

    Rewriting the executable post-link is one of the more exciting methods. The easiest way would be to store the build date as a fixed length string somewhere in close vicinity to some sort of marker that is otherwise not used but then you could locate the marker and directly edit the binary to update the build date. That would be pretty straight-forward.

    For PE you could use the useless space (42 bytes) otherwise taken by "This program cannot be run..." in the DOS stub at 0x4E. It's an ugly hack, though, and I suppose ELF doesn't have any compati[de]bility thing of similar uselessness.


  • BINNED

    @Applied-Mediocrity clever. Sounds like a good way to trigger anti-virus heuristics. 🏆

    (Without looking it up I’d assume there’s either an actual field for this in the PE header, or you should use the VERSION resource for what it’s for.)



  • @remi I think in that case, you could combine a custom section with (essentially) @topspin's suggestion of rewriting an existing identifier.

    E.g., somewhere in your source, define an object that holds the release information. Place it in a custom section (type const __attribute__((section("customSectionName"))) variable = foo in GCC/Clang or __declspec(allocate("customSectionName")) type const variable = foo in MSVC).

    You can access the data just through the variable name (so just like any other variable), but having it in a custom section will make changing it later (e.g., after linking) much easier.

    There are ways to enumerate sections in a file programmatically, but it's probably more trouble than it's worth.



  • @cvi that's starting to look like an overly complicated solution for a tiny problem, but which could work. I approve of all that. 👍 🎆 :complicators_gloves:

    Now to just poke the hive mind a bit more so that I don't have anything to do (:kneeling_warthog: FTW) and it'll be :mission-acomplished:!

    So, anybody cares to give me the objcopy line to edit the section? And the Windows equivalent? Plz 2 send the codez kthxbye!

    (I'm joking on the last paragraph, I can do my homework, and I'm joking in the rest of the post as well, I appreciate your help and this is truly starting to look like a viable solution -- for a tiny problem, yes, but still, if that can ultimately be achieved in a couple of lines, why not?)



  • @remi Yeah. I mean it really depends on how much of a requirement you want to make out of not having to recompile an extra file and/or relink. If you're OK with just always bumping a source file with the version/release/date, whenever a new build takes place, that's probably the easiest solution (both in terms of implementation and portability).

    If you're in C/C++ land, make sure the thing that you store the version in is an independent source file (and not a header), as to minimize the amount of rebuilding it causes. You won't avoid relinking (but incremental linking should still work, assuming it ever worked). You can alternatively try to generate a .o/.obj with the right contents more directly, but if all you have to recompile is a source file with a single <100 byte constant, it's probably also not worth the effort (especially w.r.t. portability).


  • BINNED

    @cvi said in Help Bites:

    You won't avoid relinking

    @topspin said in Help Bites:

    only contains the date but not the time

    The script checks the contents of the file before it attempts to write it, so it doesn't overwrite it if the contents would be identical, preventing time stamp modifications the build system would pick up.

    ☝



  • @topspin I meant that it won't avoid relinking whenever the version/release/date changes. Not touching the file unnecessarily is important for make et al., which rely on time stamps. IIRC something like scons already uses hashes, so it doesn't matter as much there.



  • I recently stumbled across SFP+, specifically for 10Gbps ethernet. It's not really something I've dealt with before, so I have a few (probably rather basic) questions.

    Unlike old RJ-45 ethernet, SFP+ seems to have another intermediate step. So you'd have these 'pluggable modules' which go into e.g. a switch/network card, and then the cable goes into the module. The module decides what type of cable you have (optical vs copper).

    I seem to mainly see three options:

    • Copper with normal-looking ethernet cable. But those that support 10Gbps seem comparatively expensive.
    • Optical with separate module and cable
    • Optical with the cable and module permanently joined

    Is there any significant advantages to the all-in-one optical solutions where you get both cable and module? Like, is it very fiddly to connect the optical cables to the module? (Is there any reason to not go with optical in the first place?)

    Can you mix-and-match optical modules from different sources? (Should you?)

    And maybe: how much can you bend the optical cables? I'm assuming 90-degree sharp corners are kinda out...


  • I survived the hour long Uno hand

    @cvi said in Help Bites:

    I recently stumbled across SFP+, specifically for 10Gbps ethernet. It's not really something I've dealt with before, so I have a few (probably rather basic) questions.

    Unlike old RJ-45 ethernet, SFP+ seems to have another intermediate step. So you'd have these 'pluggable modules' which go into e.g. a switch/network card, and then the cable goes into the module. The module decides what type of cable you have (optical vs copper).

    I seem to mainly see three options:

    • Copper with normal-looking ethernet cable. But those that support 10Gbps seem comparatively expensive.
    • Optical with separate module and cable
    • Optical with the cable and module permanently joined

    Is there any significant advantages to the all-in-one optical solutions where you get both cable and module? Like, is it very fiddly to connect the optical cables to the module? (Is there any reason to not go with optical in the first place?)

    Can you mix-and-match optical modules from different sources? (Should you?)

    And maybe: how much can you bend the optical cables? I'm assuming 90-degree sharp corners are kinda out...

    Optical cables cannot be bent. At best they should be gently looped (and most optical cable management trays will come with a series of pegs around which to do the looping).

    Direct attach SFP modules are the best choice for connecting to neighbors in the rack. Optical cables with the associated modules are the best choice for wire distances of more than 100m. The optical cable classification should be the same for all cable involved in the run (patch cables plus the rack to rack runs), and there are a couple different classifications depending on expected length. In datacenters, they’re moving more toward Single Mode fiber everywhere, but you do have to take care with short SMF runs to make sure you don’t burn the optics out. Multi Mode fiber (of which there are 4 grades supporting varying total lengths between optics up to about 1km) is more the variation intended for same building runs between different switch rooms.

    I would strongly recommend at least making sure both ends of a single link are the same optics model. Better still if you can use a single brand for everything of the same length range, so that your spares will work on any given link.

    Under 100m, Ethernet can work, but you need at least Cat6 cable to support 10Gbps. Fiber optics also provide an advantage of not being electrically conductive, which I would strongly recommend for runs between buildings or if you’re going between wings / floors in a building with questionable grounding.



  • @izzion said in Help Bites:

    Under 100m, Ethernet can work, but you need at least Cat6 cable to support 10Gbps.

    I'm guessing for short runs (e.g. <15m), the choice between copper and optical would mainly come down to the environment? E.g., if it's something like an office/lab/home, copper makes running the cables easier and less fragile, whereas if you were in a somewhat 'protected' environment (machine/server room or similar) or had physical channels to run the cables in, optical would be a reasonable choice.


  • I survived the hour long Uno hand

    @cvi
    If the run is short enough to get a DAC and it’s not somewhere a pet or small child (but I repeat myself) can mess with it, just get the DAC. Direct attach cables are pretty thick wires and often are actually copper wire that can handle some “manipulation” without issue, so they’ll be cheaper than copper modules plus a patch cable and work well.

    Otherwise, if it’s long enough to need an actual fiber optic patch cable then yes, use copper if it’s in a high traffic area (or the patch cable run would go through a cable management guide where you make frequent changes — having to be mindful of the fiber run is an annoyance and if people who aren’t necessarily aware of the cautions required when working near optical cables may be running other wires through that area, it’s better to not have to worry about Samuel Stonehands breaking your main uplink cable).



  • I'm trying to desolder something from a breakout board. Specifically the button from this.

    Didn't have much success in my initial attempts. Do I need to go at it with a higher temperature than for normal hand-soldering? Currently at ~330*C, which works well for normal soldering. Didn't find anything very conclusive when searching...

    (Tried with both one of those solder sucking things and with a copper based wick/desoldering braid. Not sure if I ever got the solder to melt - difficult to see in there.)



  • Are you trying to just get rid of the button, or do you want to reuse it?

    In the first case, the easiest way is to cut the leads close to the button's body using fine flush cutters. Then you just have to remove the remains of the leads/clean the pads with desoldering braid.

    In the second case, you've got several options:

    • adding low-temperature solder (Chipquik SMD1/SMD1NL, for example), which remains liquid for long enough that you can just push the button away. Not cheap, but the safest and most convenient way.
    • you can also use hot air, provided you protect nearby components from heat using Kapton tape or aluminum foil carefully, and do it quickly enough to avoid the button melting.
    • the low-tech way is to add plenty of ordinary solder to each pin, then gently pushing/rocking the button with a tool while you touch each pint successively with the soldering iron, until the button is loose. Then you clean the mess using a desoldering braid.

    Regardless of the method you choose, adding soldering flux will help. Upping the temperature of the iron may help, but don't overdo it if you don't don't want to burn the board (and don't forget to reset it to the normal temperature when you're done).

    EDIT: also, if you're using lead-free solder, switch to leaded solder. It's easier to work with because the fusion point is lower, and lead toxicity is a non-issue in a hobby context as long as you're careful. Just don't mix leaded and non-leaded solder on the same solder joint.



  • @Zerosquare said in Help Bites:

    Are you trying to just get rid of the button, or do you want to reuse it?

    Getting rid of it is fine in this case. Briefly looked at cutting it away - I don't have fine enough cutters at hand (last time I tried it, I ended up ripping away the pads). Button is something like 7mm on the long side. Might be time to get better cutters, though. (No hot air gun at hand either. Been looking at getting a small hotplate, though.)

    I'll try adding solder. I searched a bit more, somebody also mentioned that. Others said that they'd normally go for around 380*C to 400*C when desoldering. But from you it sounds like that might not be necessary?

    The board came presoldered, so I'm guessing they used lead-free solder. I guess I shouldn't mix solders for desoldering either? (I've been using lead-free solder for a few years now, mainly because it's much easier to find in stores. For soldering things, I don't think there's much of a problem; desoldering surface-mount components from a pre-made board is a new thing, though).



  • @cvi said in Help Bites:

    I'll try adding solder. I searched a bit more, somebody also mentioned that. Others said that they'd normally go for around 380C to 400C when desoldering. But from you it sounds like that might not be necessary?

    It depends on the soldering iron you have.
    Cheap/low-power ones tend to struggle to maintain the temperature when a solder joint is connected to a lot of copper (as it acts as a heat sink), so increasing the target temperature to compensate can help.
    But it comes with the risk of overheating things by accident, so be careful.

    @cvi said in Help Bites:

    The board came presoldered, so I'm guessing they used lead-free solder. I guess I shouldn't mix solders for desoldering either?

    Yes, unless it's an old board, it's been soldering with lead-free solder.
    For desoldering, mixing is not much of the problem, as long as you remove the mixture with desoldering braid afterwards.


  • Considered Harmful

    When I connect my work laptop to my home wifi, I'm getting obscenely high packet loss (>50%) and frequent disconnects (every few minutes). I don't think there's an issue with my wifi, because dozens of other devices have no problem at all with it, even ones physically located in the same room. The signal strength on the network shows strong, when it shows up at all. Also, I don't have this problem with the in-office wifi on the same machine.

    It's threatening my ability to "work" from home, so I need to get this resolved. When I search online it just tells me generic instructions to reset the router, install new drivers (which I tried), etc.


  • Discourse touched me in a no-no place

    @error Just checking: how many other devices are connected to the router? Domestic routers tend to have a fairly low maximum, above which they provide terrible service. (I know this because of once being at a large conference where the network provider tried to use domestic wifi hubs in order to save a few bucks. The conference organiser was not happy.)


  • Considered Harmful

    @dkf Probably a lot, but if that was the issue, I'd expect other devices to also have problems. As far as I can tell it's isolated to this one machine.


  • Considered Harmful

    Possibly related: the same machine doesn't like to stay connected to the Ethernet connection at the office either. So it might not be a wireless issue at all.


  • Notification Spam Recipient

    @error said in Help Bites:

    doesn't like to stay connected

    My bet is a VPN software package that's interfering with things.



  • @error said in Help Bites:

    connect my work laptop to my home wifi, I'm getting obscenely high packet loss (>50%) and frequent disconnects (every few minutes)

    At home, I have many cables lying around: that is still the most reliable connection.
    And a :fun: observation: previously, I set the wifi power to maximum in the router, and it was quite unstable. Later on I changed that to 10%, and hardly any issues anymore... A heat issue?


  • Considered Harmful

    Switched to 2.4GHz from 5GHz and the problem went away. :wtf_owl:


  • Discourse touched me in a no-no place

    @error Could still be my hypothesis; a different ARP table per network interface is very believable...


  • Notification Spam Recipient

    @BernieTheBernie said in Help Bites:

    And a :fun: observation: previously, I set the wifi power to maximum in the router, and it was quite unstable. Later on I changed that to 10%, and hardly any issues anymore... A heat issue?

    Yes. Sometimes too much power is indeed too much. I could explain it if I remember my college much, but brain no goody so much anymore.


  • BINNED

    Not really help, more idle curiosity.

    I've seen the following button widget in the Io💩 app for my car and thought "oh, probably some CSS gradient". Well, surely that's not a bitmap, right?

    gradient.jpg

    I first thought that's just a linear gradient with a 45° rotation and two stops in the middle for a hard edge. But then I realized that wouldn't work like that, because it also changes along the top/bottom direction, i.e. it's a hard edge at the bottom but soft at the top.

    Can this be done with a CSS gradient? Preferably without hacking several gradients on top of each other and transparency blending them.
    Are there 2d gradients? Or how would you do that?



  • @topspin Please send an email to BMW customer support, and then show us their answer.
    We are looking forward to needfully done :fun: .


  • BINNED

    @BernieTheBernie I don’t think it’s open source, so “pls send teh codez” probably doesn’t work.



  • @topspin so what. just try it. for :fun: !



  • @topspin the only way you’re doing this is with blending multiple gradients. There’s just too many parameters to get in otherwise.


  • Discourse touched me in a no-no place

    @topspin said in Help Bites:

    Or how would you do that?

    The simple way seems to me to be SVG.



  • @dkf I think you might even get into blending multiple gradients there.


Log in to reply