Wednesday, July 6, 2016

disassembly at repl?

I realize that "I just discovered something amazing about LISP that other people have known about for 30 years" posts can be kinda irritating, but I'm going to make one anyway.

Apparently in some (all?) dialects of common lisp, one can create a new function at the REPL, ask for its assembly at the REPL, and get the assembly for the function one just typed.

Check this out.

CL-USER> (defun snarf (n) (+ 5 n))
CL-USER> (disassemble 'snarf)
; disassembly for SNARF
; Size: 39 bytes. Origin: #x100606317C
; 7C:       498B4C2460       MOV RCX, [R12+96]                ; thread.binding-stack-pointer
                                                              ; no-arg-parsing entry point
; 81:       48894DF8         MOV [RBP-8], RCX
; 85:       BF0A000000       MOV EDI, 10
; 8A:       488BD3           MOV RDX, RBX
; 8D:       41BBD0010020     MOV R11D, 536871376              ; GENERIC-+
; 93:       41FFD3           CALL R11
; 96:       488B5DF0         MOV RBX, [RBP-16]
; 9A:       488BE5           MOV RSP, RBP
; 9D:       F8               CLC
; 9E:       5D               POP RBP
; 9F:       C3               RET
; A0:       0F0B10           BREAK 16                         ; Invalid argument count trap
CL-USER> (documentation 'disassemble 'function)
"Disassemble the compiled code associated with OBJECT, which can be a
  function, a lambda expression, or a symbol with a function definition. If
  it is not already compiled, the compiler is called to produce something to

Sunday, February 14, 2016

No more IR remotes.

At work I frequently program computers attached to banks of 9 or 12 HDMI screens, sometimes programming clusters of such computers to drive even larger display walls. At home, I only have one HDMI-compatible screen, but the array of small, cheap devices attached to it is growing by the minute. In each setting, the fact that these screens are designed to be controlled and configured via IR remotes is causing me a headache.

At work my IR-remote headache is that doing any sort of action to the screens (turning them on, turning them off, adjusting them) requires pointing the remote in such a way as to control one of them, but none of the identically-manufactured neighbors. For all I know, maybe there's a way to pair each one with a separate remote -- but then one would have to remember which remote went to which screen, and I doubt any such pairing would allow 45-way uniqueness. Our "solution" has been to try to avoid ever needing the remotes, and to stick a paper cup around the IR emitter so that the IR remote can be shielded from all but one screen at a time.

At home, I only have one screen I want to control, but to use it with any device I need to first find the thing I use to control the device (possibly a laptop or a smartphone) *and* the remote for the TV. Mostly I only need to turn the thing on/off, change the volume, and switch HDMI inputs -- but it'd be nice if I didn't have a separate remote I always lose for those actions

I can't be the only one facing these problems. Consumers seem likely to plug an ever-increasing array of strange devices into their home television sets, not all of which even come with IR remotes, while my belief that landscape of screens in the office environment will change radically enough to make this useful in the workplace is... ...something that I am implicitly gambling on in the "startup Lotto".

And it turns out the HDMI people thought of this already. So there is already most of a solution out there, called "HDMI-CEC" for "HDMI Consumer Electronics Control" (see Wikipedia's page on the topic). But, after fiddling with it, I cannot yet get it to do everything I want.

First off, I can't send HDMI-CEC signals over any HDMI connection from a discrete GPU from a (particular manufacturer of high-end graphics cards whose name starts with "nv"). The manufacturer, apparently, believes that HDMI-CEC is a consumer feature, and is not something their high-end cards should support. I beg to differ. I write software for walls of between 30 and 45 monitors and would like to be able to programmatically turn these monitors on, and apply things like "gamma correction", "color matching", "color temperature" and other settings. I would also like to do this on a per-program basis, so that one program driven by one set of designers/artists can have one set of monitor settings, and another program, designed by a different set of people, can have a different set of monitor settings. I'd also like to be able to individually address monitor settings for such a bank of monitors so that we can write our own software for calibrating them. Or, hey, so that some third-party can write software for calibrating large banks of monitors, and for storing the monitor settings in a way that allows us to programmatically re-apply them at any time. So, if anyone reading this works at a major graphics card manufacturer (particularly one whose HDMI outputs on their discrete GPUs don't support things like HDMI-CEC), please pass this along.

Second off, it is not clear to me whether HDMI-CEC is actually capable of changing all the settings I want to be able to change. Libraries exist that allow me to send commands for on/off, input selection and volume (although the volume for some TVs seems to only work if there is an external audio amplifier, which baffles me). But there seems to be a lower level of communication available which I have not fully sat down and understood. I don't know what this lower layer is capable of, I see some menu-related messages, but it is not clear what I can do with them. I suspect I should be able to record the sequence of menu actions required to apply a particular setting on a particular manufacturer, and play these back blindly, which means that it might be possible, albeit awkward, to be able to control any monitor setting reachable via the menu system normally accessed with the screen's IR remote. But it'd be nicest to have device-independent ways to set standard pieces of monitor configuration (color temperature, gamma value, audio volume) in a way that actually works, input selection in a way that I can figure out using the HDMI-CEC tools for the Raspberry Pi).


It turns out that, if I'm willing to stick with nvidia hardware only, nvidia-smi and friends will do almost everything I need. And what it doesn't do, I don't need to do for the massive display arrays I deal with at work (I have no need to individually power monitors on and off there, audio goes over a separate channel, and I have no need for input switching)

For home use, HDMI-CEC remains just barely inadequate -- but, hey, maybe buying a newer TV (and an external audio system) would fix the problem.

Sunday, August 9, 2015

A quick guide to visiting Downtown Los Angeles

When friends have visited LA, I used to give them a list of pieces of advice. Since then I've shifted to stating that I would collate my advice-to-visitors into a blog post, and forward it to each new visitor. I have yet to do that. But since this coming week is the week of SIGGRAPH, and many people I know are likely to be, not only in LA, but in the one part of LA I know well enough to give advice about, I feel it is time to finally write this up.

One of the problems to giving visiting advice for LA is that the "city" is actually comprised of many different subcities, visitors will want to visit sites scattered among many of them, the realities of traffic mean that one should not plan to visit sites in two different sub-cities in the same day, and the only areas I'm sufficiently familiar with to give advice on are Downtown, East LA, the San Gabriel Valley, and Orange County. This completely omits Hollywood, Mid-City and the Venice / Santa Monica areas, all of which are places any tourist should visit. Luckily SIGGRAPH (held next week) takes place in Downtown LA, meaning that I have a whole raft of acquaintances who primarily care about downtown.

Transit If all of your LA destinations, other than the airport, are downtown, you can get by using public transit alone. General schedule and route information can be found at a variety of places, but the first thing you're going to want to do is to travel from your airport of choice to Downtown LA.

    If you are flying into
  1. LAX : You should take the LAX Flyaway bus to "LA Union Station" LAX flyaway bus
  2. Ontaria Airport : Take a cab to the Rancho Cucamonga Metrolink Station. From there, take Metrolink to "LA Union Station"
  3. Burbank Airport : I have no idea.

By car If you do choose to arrive by car (and brave parking and traffic), you will spend a good chunk of time stuck in traffic. My only advice to you is to reprogram your car radio such that one of the stations is FM 89.8 KCRW. LA has other radio stations as well, pick them according to your musical tastes. But prepare to be disappointed by those that purportedly play the genres of music you like (unless you are into hip-hop, which has historically been big here).

Getting around downtown If you're pressed for time, there is a nearly-constant swarm of Uber cars. I'm sure the same is true of Lyft. Downtown is the part of LA that is best-served by public transit. You'll probably want a TAP card if you're doing this. I personally prefer to explore downtown by bicycle, but locking up one's bike safely can be a bit of a nightmare.

Things to visit downtown. The following points of interest are worth stumbling into once or twice.

  1. LA Union Station. I wouldn't go out of my way if you're going everywhere by car : but if your'e going by public transit, you'll probably end up here anyway. Take a look around. It is a beautiful building with fascinating crowds.
  2. Grand Central Market : A variety of food and grocery stands embedded within a larger building downtown. Great for lunch. It has moved slightly beyond the "gentrification sweet spot" into the edge of "upscale banal", but still beats the convention center for lunch.
  3. LA Centra Library : Kindof a nifty old building. Closer to the convention center than the other places I'm mentioning :
  4. Last bookstore LA : Don't pretend you don't have a use for a stack of used sci-fi novellas for your plane flight back to wherever you came from.

Where to eat. Lunch near the convention center is likely awful : but LA is emerging as a bit of a foodie city. Here are neighborhoods and destinations I can recommend.

  1. Grand Central Market : Google maps says this is a 33 minute walk from the convention center. I'd advise using public transit instead, which Google tells me takes 15 minutes. I don't know what the intervening neighborhoods are like, as I rarely travel near the convention center.
  2. Little Tokyo : If you're stuck at the convention center, it can be kinda tight to get here for lunch. But the ramen joints are well worth the effort, and it is an extremely compelling place to have dinner. I will not reveal my favorite ramen joint unless you are visiting me for dinner (partly because I only know its location, not its name), but my runner-ups include "daikokuya" and "shin-sen-gumi". Sushi is also available in this neighborhood.
  3. Boyle Heights : Famous for Mexican food. Food destinations should be clustered around "Guisado's tacos", near the "Mariachi Plaza" stop on the LA Metro Gold Line. Parking is plentiful.
  4. San Gabriel Valley : By public transit : The San Gabriel Valley is LA's suburban Chinese-American enclave, and arguably has some of the best Chinese food in North America. If you are going by transit, you probably want to take the 487 bus (or 489 bus) from LA Union Station to Del Mar and Marshall (or Del Mar and Valley). There are quite a few shopping plazas around there that are full of Chinese restaurants, very few of which are bad. I particularly recommend "Sam Woo". The third floor of the shopping plaza containing a "Daiso" store and a "Focus" store has an excellent dim sum restaurant (whose name keeps changing). Bear in mind that dim sum stops being served at the end of lunchtime. Those wishing for dim sum for dinner are likely out of luck. An alternative to the 487/489 is to take the LA Metro Silver Line express bus to El Monte Station, and then to take an Uber or a Lyft to your final food destination, which is an excellent way to reach Din Tai Fung. The area around El Monte station itself is not too interesting : it will take a car trip to get from there to where you want to eat. The 487/489, on the other hand, drops you immediately in the middle of a dense shopping-district full of restaurants.
  5. San Gabriel Valley : By car : If you are going by car, different parts of the SGV open up. For instance, one of the best dim sum restaurants in the area, "Ocean Star Seafood" in Monterey Park, is difficult to reach by public transit, but is easily accessible by car. Parking nearby, while non-trivial, is free, and normally feasible.
  6. Koreatown, mid-city, Hollywood, whatever -- I know there are good places to eat in these neighborhoods, but I don't know where they are. Sorry. The best I can do is advise you to look up whatever Jonathan Gold has had to say about these neighborhoods
  7. LA's so-called "arts district" -- a better destination for drinks and entertainment than for food. If you're headed there and you know me, give me a call. Get there the same way you would get to "Little Tokyo". It has a sausage restaurant as well as vegan and vegetarian options.
  8. Chinatown : If you have a car, don't bother. It'll probably be just as quick to hop on the 10 Fwy headed east, skirt around downtown, and wind up in Monterey Park, which has better food (take the Atlantic Blvd exit off the 10 and head south). Plus Monterey Park has parking! If you wind up here anyway, "Empress Pavilion" has decent dim sum, there is a Sam Woo, although I'd almost advise going to Olvera Street or Phillippe's instead.

Thursday, May 14, 2015

Folding bicycles, wheel size, stability

One of the problems with public transportation in many American cities is the problem of how to get the last 2 miles from where your train / express bus / CalTrain stops to where you're actually trying to go (equivalently, how to get from your starting position to your train/bus stop). In some cities the solution is to take a different bus/train line and transfer : but in Los Angeles County and in Silicon Valley this is often untenable, and can turn a 20-minute ride on an express bus into a multi-hour transit saga.

A frequently proposed solution is to take one's bicycle on the train/bus. This works somewhat well for trains, but busses (I live close to an express bus line) in Los Angeles County tend to have only two slots on the front of the bus for carrying bicycles. If those are full when you catch the bus, you're out of luck. At certain times of day, even trains will restrict the number of full-sized bicycles that can be brought on board.

One way around this is to use a folding bicycle, such as the one pictured above. Conceptually it is great, and it makes a bike-and-bus commute feasible for me that would otherwise be difficult or unreliable. But it has issues.

On the one hand, it is difficult to fit under the seat. The Metro web page states Folding bikes with 20 inch or smaller wheels can be taken on board. Make sure your bike is folded and stored under a rear seat so as not to block aisles and doorways. . This is difficult and awkward. The size of the bicycle when folded (as can be seen from the pictures above) is dominated by the size of the wheels.

On the other hand, the stability of the bicycle (and its ability to handle rough terrain) affect its ability to go fast. Already riding my 20-inch-wheeled folding bike feels sluggish and unstable compared to my full-sized bicycle

So how might one try to go about making a folding bicycle more stable while reducing the size of its wheels? Here is a proposal.

For lateral stability it turns out there has been some interesting recent work on what makes bicycles stable. This video shows a small-wheeled bicycle that rides stably, without the help of trail or angular inertia. Further details on this work can be found. The authors even mention folding bicycles in their excellent TED talk.

For stability going over rough terrain, potholes and curbs : NASA has already faced the problem of making a lightweight vehicle that can be folded into a tight package and retain the ability to traverse large obstacles. Their solution for many of the Mars rovers was the rocker-bogie suspension system. It is not designed to go at high speeds, and may have neglected dynamic stability : but it may be a good start. Note that a "bicycle" designed with such a system might end up having far more than 2 wheels.

Neither of these, by itself, constitutes a "solution" to the problem of making a stable folding bicycle with small wheels capable of riding over rough terrain. But hopefully it provides a direction. And maybe it'll bring us one step closer to Richard Register's desire for cities built around transit and bicycles.

P.S. for graduate students, inventors and entrepreneurs in the United States it may not be completely implausible to get funding from DARPA to develop better folding bicycles

Sunday, April 5, 2015

RSS / humans?

This is a post that I had meant to publish 2 or 3 years ago and had forgotten about. Having found it in my unpublished drafts, I decided that it was still interesting, even if the "demise of Google Reader" is no longer fresh news

The original post follows

There has been some noise, since the demise of Google Reader, about whether RSS is "dead." I think much of the discussion on the topic is somewhat missing the point : even if RSS feeds are not something that normal humans want to collect, curate, subscribe to, and aggregate, RSS is still a great interchange format for computer programs that collect, curate, subscribe to, aggregate, and repackage RSS feeds.

Case in point:

A nice thing about using RSS for such a purpose is that the content emitters don't have to run the same software or the same systems or even be run by the same people as the computer program reading the RSS. Now, of course, not all content emitters want their content to be scraped, collected,curated and repackaged. But, for those that do, RSS (or Atom) provide ideal means of interchange. Note, also, that the example above is probably not anywhere near the most efficient or scalable way to repackage a feed from one source in order to re-display in another.

I believe that this is a corollary to the idea that Twitter is the ideal medium for machines to broadcast short updates to one another and to humans in a medium that is authenticated, but not private.

Homebrew solar battery charger

A neighbor of mine recently build a solar-powered battery charger out of a variety of parts, including an old computer monitor stand as the stand for the solar panel

He was particularly proud of his energy efficiency, his use of predominantly analog components, even for tasks that seem akin to "logic", and the various clever tricks he used to achieve zero quiescent current

He admitted that a more digital (and, particularly, microprocessor-based) design would have been easier and more flexible, but contended that the level of efficiency he achieved would have been impossible to reach with anything other than analog design

His device had a serious of modular adapters for different levels of power, including USB, Sony laptop, an extra laptop battery, and a household-voltage AC adapter (capable of running a fan

Unfortunately he didn't have circuit diagrams to share, having designed most of the thing primarily in his head, and directly in circuitry.

Saturday, June 28, 2014


I recently had a conversation with a friend, who is interested in third world economic development, "leapfrogging" technologies, and energy, about AC vs. DC for electrical power transmission and distribution. He asked me for my further thoughts on the matter, so I will put them here, along with some caveats about what things I know that I don't know. I invite readers who know more about the topic to leave corrections and additions in the comments to this post.

A bit of history

The debate about whether to transmit power as AC or DC raged in the early part of the 20th century with Thomas Edison advocating for DC transmission of electricity, and Tesla advocating for AC. At the time, AC was adequate for most household applications (many of which involved the use of electrical current to produce heat, or to produce lighting through heat, and thus didn't care about the direction in which current travelled at any given time) and was vastly easier to efficiently step up or down in voltage, allowing for efficient transmission of power over long distances. One exception was that it was easier to build a variable-speed electric motors to run on DC (it is trivial to build single-speed AC motors, especially if one has 3-phase AC power, which is generally what is transmitted over longer distances, and what is supplied to industrial facilities). Older elevator technologies (circa early 1900s) tended to use DC motors, and tended to be installed in dense urban cores, where a large number of electricity customers could be served without the need for long-distance transmission. For these reasons, small DC power grids existed in many of America's large cities for decades after AC otherwise won what was known as the "war of the currents". See, for instance

To make a long story short, one generally wants low voltages, and the capability of producing high currents, at the place where the electrical energy is used. But it is far more efficient to transmit electrical power at high voltage (and comparatively low current). AC is fairly easy to step up and down in voltage using transformers. It has not, historically, been easy to do the same thing with DC power.

Advantages of DC in the modern world

One drawback to AC power stems form the fact that modern power grids are extremely interconnected. Placing two or more AC power sources on the same network requires that the sources be synchronized. This requires some form of dynamic control. A simple thought experiment should reveal why two out-of-phase AC sources wired to one another effectively create a short. Dealing with these synchronization issues has led to some fascinating control theory papers, but I could understand why practical engineers might want to dispense with these problems altogether and transmit electrical power via DC current. I don't know how much more complicated AC synchronization problems become when individual consumers are allowed to produce their own power and feed it back into the grid.

As an extra piece of terminology (and one which might be very important to understanding other discussions of the electrical grid), power engineers divide the grid, conceptually, into two distinct sorts of networks.

  1. Transmission networks carry high-voltage electricity over long distances and interconnect different power plants on the grid. It is my impression that AC synchronization problems generally occur in the transmission network portion of the power grid.
  2. Distribution networks carry lower-voltage electricity from the transmission networks to end users, either industrial, commercial or home consumers. It is my impression that there is generally only one logical path for power to take between any two points on the distribution network (with the note that a "path" in this case might be 2, 3 or even 4 wires, depending on the form of the AC current).

Further, modern appliances are quite different from those of the days of Edison and Tesla. Computers and other digital equipment generally require DC power sources (the "power supply" of your desktop computer contains a transformer, a voltage rectifier to convert AC to DC and a voltage regulator to maintains the voltage of the supply at a steady level, while your laptop likely has the same equipment mostly embedded in its power chord). LED lighting works with DC current (any LED light that you can screw in to your conventional lighting fixtures must come with, at bare minimum, a voltage rectifier to convert the AC of your light fixture into DC for the LEDs). Today's TVs, being digital appliances, require DC power internally.

DC is of particular appeal to off-grid power systems for a variety of reasons. For one thing, solar cells naturally produce DC current. Most conventional electrical power generation (coal, oil, nuclear and the sorts of large solar installations that use mirrors to heat water) at some point heats water to turn a turbine which turns a generator. It is fairly easy to design such a system to produce 3-phrase AC power. I am not sure how difficult or easy it is to make such a system generate DC without using a rectifier. Equally important, perhaps even more important, to off-grid systems is that DC is required to charge backup batteries, and is the natural output of chemical batteries. An off-grid power system using solar for energy generation and batteries for storage will naturally want to be DC. I note here that one should be wary about using off-grid solutions with battery backup to leapfrog economic development in the developing world : the most economical rechargeable battery solution at this point is still lead-acid batteries, which come with a host of problems. I will try to see if I can dig up resources on it. One might want to ask whether solar generation with battery backup becomes more feasible when all of one's appliances become much lower power (lighting could be LED-driven, heating is less of an issue in parts of the developing world, computing and communications are becoming more efficient everyday. I still wouldn't want to run my washing machine off of batteries though). Battery technology is also rapidly improving, driven by consumer demand for things like smartphones and laptops with long battery life.

A revolution in transmission technology

One of the main advantages of AC current for electrical distribution, as mentioned above, is the ease of stepping voltages up and down, to allow transmission to occur at very high voltages, while giving end-users safe and convenient low-voltage electrical energy with high current capacity. Safety aside, giving high-voltage to end users would be infeasible for a variety of basic electrical reasons. Common materials, such as air, behave differently under high voltage and would need extra considerations.

But, because of the problem of AC generator synchronization, utilities have found it to be desirable to have their large high-voltage interconnects run on DC power, which is much easier to synchronize and coordinate.

Thankfully the technology to convert high-voltage AC (HVAC) to high-voltage DC (HVDC) and to step DC voltages up and down have improved radically during the semiconductor revolution, as technologies originally designed for lower-power applications have found their way into the world of power electronics. A good summary of the state of things is provided by Wikipedia : see Photographs of some of these new pieces of equipment are spectacular in their scale and design, see . One of the more fascinating pieces of high-voltage DC interconnect technology is the proposed Tres Amigas Superstation in Texas which plans to use superconducting wires to transmit DC current to connect the three major energy grids in the US.


Advantages of AC current

  • Ease of stepping up/down voltage (for efficiency in transmission)
  • Ease of making a single-speed motor (for instance, your coffee grinder)
  • AC is the natural output of the sort of electrical generator I would design were I to design a generator
  • Adequate for heating applications

Advantages of DC current

  • Avoids the AC synchronization problem
  • Good for variable-speed motors (anything from the motor on the Honda insight, to the stepper motor in your hard drive, to wheelchair motors, and I think even washing machine motors).
  • What batteries want to be charged with
  • What batteries output
  • What solar cells output
  • What computers and digital electronics want to work with

Technologies to watch if one is interested in these issues

  • High-voltage rectification
  • High-voltage DC - DC step-up / step-down
  • Battery technology
  • Socio-economic situations that might produce micro-grids
  • Technology that allows households to accomplish basic tasks using less power (I suspect there is little to no room for improvement in this area for things like electric stoves and electric heaters, but quite a bit of recent progress for communications, computing, lighting and entertainment. I am curious as to basic things like "can one make a significantly lower-power automatic washing machine")

One thing I have not given much thought to is which form of power is easiest for people with little electrical knowledge to effectively deploy in micro-grids, and what sorts of technologies could change this.