“Quit Patton yourself on the back”
Category Archives: general nonsense
Dumb Joke
Have you heard of the new short-form video app for software developers? It’s called Tcl/Tk.
Stupid C++ Threads and Lambdas
For a unit test that I’m writing for some code at the moment, I need to create a thread that doesn’t do anything. Well, the easiest way to do this is to do a lambda function. And since we don’t need to capture anything, and the thread doesn’t need to do anything, I have written the following line of code:
std::thread thr = std::thread( [](){} );
Just look at it in its simplicity. In case you missed it:
[](){}
I actually started laughing after I had written that, it’s just so stupid that it’s funny!
Fixing a Gamecube Disk read error
I recently wanted to play my Gamecube again, so I turned it on for the first time in a while. Unfortunately, it would no longer read any of the disks that I had. Upon some internet searching, it seemed like this is a well-known problem with Gamecubes, in that they will eventually stop reading disks. Fortunately, the fix is pretty simple: you need to adjust a variable resistor on the board in order to get the disks to read again.
I’d like to first say that the information that I got on how to adjust the laser was mostly from this very informative Youtube video, so I would recommend watching that video first. In terms of tools to open the Gamecube, I have the ifixit Moray set of screw bits, which has the special bit required to open the Gamecube.
In my particular case, I have a DOL-001 model of Gamecube. According to the information that I have found online, the value of VR-401 should be between 200-500 ohms for this model(other sources say it should be between 450-600 ohms). Upon opening up my Gamecube however, I noticed that it was below what the minimum level should be(I think it was about 195 ohms). I then spent quite a while adjusting the pot to try and get it to a good value, and was unsuccessful. I was tweaking it in very small increments(~5 ohm), putting it back in, and trying it out. Having finally gotten very frustrated with it, I turned it down to 152 ohms, and all of a sudden it started working! It didn’t work 100% of the time(it seems to need to warm up first), but it started working again.
Upon some further adjustment(after I discovered that it wasn’t super reliable), I eventually got it to reliably read disks at 100 ohms! This is much lower than I would have expected based on the model number and expected range of values for this resistor.
Hints when doing this:
* Make sure to take down the original value of VR-401 before you start.
* Try to go in very small increments. At least in my case, there is a very narrow band that VR-401 needs to be in for the disk to be read reliably
* Had I gone down in my adjustments first, I probably wouldn’t have wasted much time adjusting. I was confused because the original value that I got for VR-401 was so much lower than was was to be expected. My guess is that if you need to adjust the value of VR-401, the new value will probably be near the old value.
* Write down the values that you have done. I have probably adjusted VR-401 a hundred times at this point, so knowing where you have gone is good!
* Once you have a good value, write it on the housing inside of the Gamecube near the laser so that if you need to adjust it again, you know what worked!
Heh
NUMBERS!

C++ pimpl thoughts
Recently, I’ve been writing some C++ code that I would like to be ABI compliant. Because of that, I’ve been writing the code that uses a private class that holds all of the private data members. This results in code that looks something like the following:
// myclass.h
#include <memory>
class MyClass{
public:
MyClass();
~MyClass();
int foo() const;
void setFoo( int val );
private:
class priv;
std::unique_ptr<priv> m_priv;
};
// myclass.cpp
#include "myclass.h"
class MyClass::priv {
public:
priv() :
m_foo( 5 )
{}
int m_foo;
};
MyClass::MyClass(){
m_priv = std::make_unique<priv>();
}
MyClass::~MyClass(){
}
int MyClass::foo() const {
return m_priv->m_foo;
}
void MyClass::setFoo( int foo ){
m_priv->m_foo = foo;
}
However, after some further reading I realized that this creates a new problem with const methods: mainly that you can’t ensure const correctness! That is, if we change MyClass::foo to be the following, it’s perfectly legal:
int MyClass::foo() const {
m_priv->m_foo += 10;
return m_priv->m_foo;
}
Obviously, this particular design results in code that may look const-correct, but actually is not. You can get around that with having an actual pointer to the implementation and not just the private data members, but this seems like a lot of overhead and is really just a lot of boilerplate in my mind.
This leads me to some thoughts on what would make this nicer. The main problem seems to be this facet of C++:
Size and Layout: The calling code must know the size and layout of the class, including private data members.
https://herbsutter.com/gotw/_100/
Since the calling code needs to know the size and layout, any change to this causes ABI breakage, which is certainly not ideal, thus needing the pimpl pattern. What would be nice is if we didn’t have to do this. Thus, I bring my very simple 5-minute solution that hasn’t been thought out fully.
Add a new keyword! Called ‘privdata’.
Example usage:
// myclass.h
#include <memory>
class MyClass{
public:
MyClass();
~MyClass();
int foo() const;
void setFoo( int val );
private:
privdata int m_foo;
};
// myclass.cpp
#include "myclass.h"
MyClass::MyClass() : m_foo( 5 ){
}
MyClass::~MyClass(){
}
int MyClass::foo() const {
return m_foo;
}
void MyClass::setFoo( int foo ){
m_foo = foo;
}
The idea behind this is that just by declaring a private variable with ‘privdata’ effectively turns the code into what I posted before with the unique_ptr, so that no matter how many private variables you add(with the ‘privdata’ keyword) the class will stay the same size.
Advantages:
- One keyword to add
- Very easily make a class ABI compatible.
- No need to worry about a layer of indirection – the compiler takes care of this for you.
- Most tools(e.g. IDEs) will still work correctly. One problem with how I’ve been implementing is that Qt Creator doesn’t have nice auto completion for m_priv->…. That’s not the end of the world, but it would be nice!
- The compiler could still check for const correctness and only allow access in const methods and editing in non-const methods.
Disadvantages:
- I’ve spent longer writing this post than thinking about this, so I’m certainly missing something.
- Compilation speedups may not be possible at this point(assuming that you’re using make), since changing something in the header would cause all dependent files to be rebuilt. Maybe we need a new version of make that can parse code to know when things change and only rebuild when something important changes?
- This requires a lot of compiler changes. New standards require compiler changes anyway, but this probably can’t be implemented without compiler changes.
I did also start looking at some more recent posts from Herb Sutter, and I found this interesting post on making a clonable class. This makes me wonder if this would be possible to do using just standard C++ and some sort of reflection library…
If you want to learn more about the pimpl patter, check out the cppreference page, which also leads to Herb Sutter’s GotW page on pimpl. Herb Sutter’s page was useful for me in terms of learning about the alternatives and how they work.
ADDENDUM NEXT DAY: It turns out, this is possible using some experimental features(std::propagate_const). See this post on Stack Overflow for more information, or on cppreference!
Signing VMWare Drivers for UEFI
Earlier today, I had to install VMWare on a Linux host that had UEFI. Fortunately, there is a guide to how to do this on the VMWare KB, however at the end, the part “Reboot your machine. Follow the instructions to complete the enrollment from the UEFI console” is not clear on what exactly you need to do.
In order to get this to work on my Acer Aspire, I did the following(note: I’m not sure what exactly is required, as I was messing around with several settings).
- Reboot your system and add a password in the BIOS. Smash F2 when the system boots. Alternatively, GRUB should have an option to go to the BIOS. (this step may not be required)
- Generate the keys as shown in the VMWare KB article.
- Copy the .der file to /boot/efi/EFI/debian
- Reboot the system.
- You should get a screen that says ‘Perform MOK Management’. Enroll your key from here. See this site for more details.
And that should be it. It’s not hard to do, but it is not clear and may be different for each manufacturer.
London vs Washington DC
A few weeks ago, I took a trip to London and saw some very cool things! While I was there, I took the Underground most of the time and figured that I would make a quick list for anybody who ever wants to visit Washington, DC and is familiar with London.
First things first: some terminology. In London, the system is the Underground. In DC, the system is Metro. The long name of the system is WMATA, or Washington Metropolitan Area Transit Authority. Nobody actually calls it WMATA though, Metro would be the proper term.
Metro and Bus
Like the London Oyster card, the DC Metro uses a contactless card called Smartrip. Put it close to the reader, and the gates will open, allowing you to enter the system. Paper farecards were accepted until 2016, and were largely replaced because the maintenance of the machines to process the paper farecards became prohibitively expensive. Fares are based off of time(rush-hour or non-rush) and distance traveled.
Metro buses also accept the Smartrip card, making it easy to pay for the buses and trains. The convenient part about using a Smartrip card on the bus is that you get free two-hour transfers between buses, which can be useful if you need to travel on more than one bus.
A number of other local jurisdictions also have their own bus services. This includes Arlington Transit, Fairfax Connector, Alexandria Dash, Ride On, and DC Circulator. As far as I am aware, all of the other local bus services also take Smartrip cards as payment.
If you’re comfortable taking a bus, it is definitely a plausible way to travel around, but may be slow and not always direct.
You can pick up a Smartrip card at any Metro station(go to the fare machines). Cards can also be topped up there, or if you’re on a bus you can use the card reader on the bus to add more money to the card. If you need to do this, you probably want to wait until everybody else has boarded the bus. Press the button to add more money(left side of reader), tap Smartrip, insert money, and tap Smartrip again to have the fare loaded.
Other Metro Thoughts
The DC Metro is not as dense or have trains as often as the Underground, but it does have a few advantages. Like London, the trains display the last line on the route that they are going to. For example, the Silver line has two endpoints: Largo Town Center and Wiehle-Reston East. You need to know which direction you are going in order to get on the correct train. On the new 7000-series cars, the announcer on the train is a computerized voice; the earlier cars have the engineer making the announcements, which can be notoriously unclear.
Like London, each platform has an LED board showing the next train coming into the station. This board shows the line that the train is for(Green/Yellow/Blue/Orange/Silver/Red), the station it is going to, and how many cars the train has. There is a push to hopefully have all 8-car trains, however there are still many 6-car trains on the Metro, so those trains will be a little shorter. Since the Metro makes large use of having multiple lines share the same physical tracks, depending on where you are going you may not need to get on the same color train. For example, to get between Rosslyn and Smithsonian stations, you can take either the Orange line going to New Carrolton, the Blue line to Largo Town Center, or the Silver line to Largo Town Center.
The DC Metro is nicer than London in at least two respects: the accessibility of the stations, and the transfer from one line to another. On the accessibility side, all of the Metro trains are on straight platforms and have no steps up(or down!) into the cars. This also makes it very easy to use if you are disabled. If you need an elevator though, if the elevator at the station you are going to is broken you can get a bus transfer from another station; listen for station announcements or check the Metro website. Transferring from one line to another is also very easy, since the trains go to the same station, and at most you have one escalator to go up(or down). Why the Underground stations are very cramped and have a ton of stairs and turns between the stations is a mystery to me.
Walking Around
If you’re visiting DC as a tourist, you’re probably planning on going to the museums. The good news is that for the most part, all of the museums are situated around the national mall. This means that they are walkable, although you may walk a lot! Some places you probably want to want to take the Metro to so that you’re not walking a large distance. Unlike London, where the crosswalk is a separate stage in the light cycle, for the most part US traffic light cycles have you crossing with traffic at the same time. This makes it difficult for traffic to turn left or right, and so sometimes the cycle will allow pedestrians or traffic to go first. The indicators for if you can walk are also nice and clear, with either a walking man or a hand telling you to stop. When the hand comes up, nearly all of the walking indicators also have a separate display counting down the seconds that you have left until the light will change. This is very useful so that you can see how long you have until you need to clear the intersection, and is one thing that I missed when I was in London.
Conclusion
I don’t really have a conclusion, this is just some information for people who may be interested. There’s much more information that I could put here, but this post is long enough as-is. Have fun!
Don’t Lose the Fight
At least that’s apparently what Jason Statham and Dwayne Johnson have in their contracts.
It reminds me of the Teal’c vs Ronon fight.
Thoughts on Nuclear Power
A few weeks ago on Slashdot, there was an article on safer nuclear reactors. It sounded interesting, but of course since it was on Slashdot the comments turned into a not quite a flame-fest, but certainly there tends to be an undercurrent of “I’m right and you’re wrong” whenever something like this comes up(see also: systemd).
Anyway, while I don’t have anything against nuclear power per se, there are a bunch of problems that make it at least somewhat impractical. First of all, what are the good things about nuclear power?
- It’s low carbon – see this Wikipedia article for the exact numbers, but suffice to say that once it is running, it is low carbon.
- It is cheap electricity once it is running.
The ‘once it is running’ is a rather large caveat though – as we’ve seen in Georgia, building new plants is expensive. Currently, about 27 billion dollars. That’s quite a lot of money. Even once it is on-line, there are very expensive long-term costs from personnel to long-term storage of nuclear waste. A brother of a family friend of mine works at a nuclear power plant, and he’s now retired at ~50. He still goes back as a contractor, and apparently makes >$100/hour.
One other problem that probably can’t be solved easily is the NIMBY problem – people are afraid of nuclear power due to the accidents that have happened. I don’t see a way to solve this, since it is a similar problem to people not liking to fly. Even though flying is the safest mode of transportation, there are many people who don’t like flying. My suspicion is this is due to the lack of feeling in control, as well as the fear that if something bad does happen, you feel like you will certainly die. Most plane accidents that people probably think about are the ones where pretty much everybody dies, so they are afraid that there’s no way out if something bad does happen.
The next question of course, assuming that we don’t have nuclear power, is can we actually generate all of our power from renewable sources such as wind and solar? The answer may be yes, given that Scotland can(under favorable conditions) generate enough power to power it twice over.
Let’s take the above example of the Vogtle nuclear plant, and assume we were to put all of that $27 billion into wind turbines as well. Assuming that each turbine costs $4 million to install and has a capacity of 2 MW, that means we could install 6,750 turbines for the cost of the nuclear plant, giving us an installed capacity of 13,500 MW. Actual numbers will probably be lower, given that the wind does not blow all the time, but that’s the theoretical maximum. According to Wikipedia, the new reactors will have a capacity of 1117 MW each, giving us a grand total of 2234 MW capacity.
Assuming my math here is correct, it makes much more sense to build wind turbines than to build a nuclear plant(at least in the US). I suspect(but don’t have the numbers to back it up) that long-term costs are also lower for turbines, since I don’t think that they need much maintenance, plus you don’t have a problem with guarding spent fuel.
If we throw solar in the mix as well, that also has some interesting numbers. According to Dominion Energy(pg 19), a solar plant array lifetime is 35 years, with one year for construction/destruction takes it to 37 years. Given that building the Vogtle plant is at least an 8+ year project, it doesn’t seem very feasible to continue on the path of nuclear.
Conclusion: nuclear, while not a bad source of power, has quite a few practical problems compared to modern wind and solar energy. Of course, each power source has its own pros and cons. This is not intended to be a fully exhaustive comparison of all energy sources, so you may want to take this with a grain of salt.