Words

    Cleaning Out Argument Labels

    The guys over at CleanCoders made a video series on the creation of an iOS app. While refractoring, they decided to remove keyword arguments.

    We also walked through the code replacing most of the keyword arguments with positional arguments – something that swift does not make particularly convenient. We did this because the code just looked better once it was done.

    I think this is a terrible idea.

    Coincidentally, I’m in the middle of the chapter on function naming in Clean Code. He argues against ternary arguments because it’s too easy to lose track of what arguments belong in the first, second, and third position. “Sounds like argument labels would help,” was my first thought. Looks like he disagrees. It makes me more skeptical of his other advice.

    WSJ on Trump's Carrier Deal

    The Wall Street Journal editorial board critizies Trump’s Carrier deal, calling it a “shakedown:”

    A mercantilist Trump trade policy that jeopardized those exports would throw far more Americans out of work than the relatively low-paying jobs he’s preserved for now in Indianapolis. Mr. Trump’s Carrier squeeze might even cost more U.S. jobs if it makes CEOs more reluctant to build plants in the U.S. because it would be politically difficult to close them.

    Mr. Trump has now muscled his way into at least two corporate decisions about where and how to do business. But who would you rather have making a decision about where to make furnaces or cars? A company whose profitability depends on making good decisions, or a branding executive turned politician who wants to claim political credit?

    I fully expected them to give Trump a pass. Credit to them for sticking to their principles.

    At the Washington Post, Fred Hiatt characterized the deal as right out of Putin’s playbook:

    It’s good that about 1,000 Carrier Corp. workers will not be losing their jobs. But there is a whiff of Putinism in the combination of bribery and menace that may have affected Carrier’s decision – the bribery of tax breaks, the menace of potential lost defense contracts for Carrier’s parent company, United Technologies.

    If this were to become the U.S. government’s standard method of operation, the results would be Russian, too: dwindling investment, slowing economic growth, fewer jobs.

    It’s always been clear that Trump understands bullying, but doesn’t care about policy. This deal is a reflection of that. There’s no policy or plan to keep manufacturing jobs; just a willingness to bully and bribe a specific company.

    Secret Lambda Permissions

    This is the culmination of half a days work trying to figure out why my Lambda function didn’t fire:

    The console doesn’t support directly modifying permissions in a function policy. You must use either the AWS CLI or the AWS SDKs.

    In other words: it is a secret setting that we hide from you. Just in case you’re trying to use a versioned lambda function or a function alias.

    Election Percentages

    Courtesy David Frum:

    Nixon 1960: 49.55% Gore 2000: 48.38% Kerry 2004: 48.26% Ford 1976: 48.01% Romney 2012: 47.15% Trump 2016: 46.17%

    Fair Elections

    I keep thinking about this tweet from Garry Kasparov:

    Saying that fair elections are rigged is as much a crime against democracy as saying that rigged elections are fair.

    It’s an odd twist that Trump is casting doubt on an election that he legally won (even if it was with a national minority). I attribute that to a strategy of working the ref. The lie of voter fraud is groundwork on propaganda that will be needed in future efforts to suppress voting rights.

    It also made me think the same idea applies to the news: Saying that fair journalism is biased is as much a crime against truth as saying that biased journalism is fair.

    iTunes Visualizer

    I just realized the iTunes visualizer is still there. I remember Steve Jobs getting up and demonstrating this in a keynote. Does anybody still use this? The only way I would possibly use this is if it were on the AppleTV. As far as I know, it’s not.

    The Case for Identity Politics

    There has been lots of ink spilled on the evils of identitly politics and how the Democrats have to embrace the color-blind notion of class. Here are a couple of articles that push back on that.

    Michelle Goldberg, in Slate:

    The focus of left-of-center politics in the dark years to come must be on protecting the groups of people who are targets precisely because of their identities. To sideline their interests is to accede to a backlash that has just begun and will only get worse. If Democrats standing up for diversity makes Trump voters feel disrespected, the best response is a slogan popular among enemies of political correctness at Trump rallies: Fuck your feelings.

    Rebecca Traister, in New York Magazine:

    But what’s not funny about all this is that we are in a moment of national crisis, in which the developmental stage of the Dirtbag Left might be mistaken for a flash of political wisdom, when prioritization of the (yes, systemic) approaches to reducing racial, gender, and class inequality is most likely to be walked back in the name of distancing the party from the women and people of color who lost the election.

    Laborious Autoposting

    I spent the better part of the evening reading up on the Facebook Graph API and writing a tool that can do my auto-posting for me. Right now it only works with Facebook. It can post images, status updates, and links in their native format. It’s not too smart about interpreting which of those formats it should use. Also, it’s comically inept at getting an authentication token. Long-lived tokens last about 60 days, so I have a while to fix it.

    If you see this, and it says that it was posted by “Emposter,” then it works.

    Trump Appointments and Transparency

    From the Center for Economic and Policy Research:

    The Senate can [demand transparency] by refusing to confirm any nominations until Trump takes the following steps to promote faith that a Trump presidency will not enrich himself and his family:

    1. Releases his tax returns;

    2. Releases a detailed and current financial disclosure that includes beneficial ownership information on all “shell companies” that are part of the Trump Organization;

    3. Follows the advice of the The Wall Street Journal editorial page that “Mr. Trump’s best option is to liquidate his stake in the company” via “a leveraged buyout or an initial public offering";

    Entrepreneurs to Trump

    Entrepreneurs to Trump: Don’t take away our Obamacare

    (Warning: Obnoxious autoplay video on that page.)

    Before Obamacare, people were tied to their jobs because of a lack of health insurance options on the individual market. Here are five people who were empowered by Obamacare to leave their wage jobs and start new businesses.

    Posting Links is Lame

    The last couple of posts I made went to Facebook as links back to my site. That is not how I meant things to go. I’m not trying to drive traffic to my site. I don’t even have any traffic analytics installed. I just want this to show up in the timeline.

    Hopefully, the full text of this post will appear on Facebook. You can read it in its entirety in your timeline, and never visit my site. That it he goal.

    Improve Your Writing with Flesch‑Kinkaid

    I came across this little bit of wisdom via Hacker News:

    There’s one trick that everybody who writes sales knows and nobody else seems to know. This trick is so effective that Microsoft Word has it even built in so you can test while you write.

    The F-K score.

    The Flesch-Kincaid score determines what grade level you are writing. If your score is 10, you are writing at a 10th grade reading level. If your score is 12, you are writing at a 12th grade level. And so on.

    As it turns out, I wrote an app for that. The thing it has over Microsoft Word is that it caculates the F-K score continuously in the background. It also has a couple of tools that suggests how you can improve your score.

    I had a very specific use case for that app: a project my wife had in her publishing job. It also does vocabulary tracking, which she needed. Now that her project is over, I find it hard to get motivated to update it. It makes virtually no money. Maybe I should add a Post to Web feature and reposition it as Write Sales Copy That Coverts kind of tool.

    Publish (on your) Own Site, Syndicate Elsewhere

    I’ve been reading about IndieWeb and the goal of publishing on my own site and syndicating the content out, or POSSE. I’ve had a personal blog for years, but never really posted to it much. Never as much as Facebook. In part, this is an attempt to break out of those networks. Or at least de-emphasize them.

    My current attempt is the SNAP plugin on WordPress. It’s going ok. I like that it doesn’t brand itself when posting. It’s my Facebook app that has permission to post. It has pretty good customization of the post format.

    I’d like the ability to customize the post format based on the WordPress post type. The template for a Photo post should be different from a Link, which should be different from a long text article. I’d also like is a way to pull in links to article I’ve liked, or retweeted. It looks like I’ll have to use another tool for that.

    Autoposter Experiment

    I set up an auto poster that will post content from my personal site to Facebook and Twitter. I’d like to make everything originate on my site and get pushed out to other places. I don’t want to be obnoxious about it though. My pet peeve is a tweet that links to a Facebook post. We’ll see how it goes.

    Being a Snob is a Bad Thing

    Today’s example was a Verge article titled Oh my heavens, the British went and made a Top Gear for wine snobs, but i’ve been annoyed at this usage for a long time. Being a snob does not make you sophisticated. Being a snob doesn’t even mean you like the subject in question (e.g., wine). It means you use your knowledge of the subject as a means to draw a social distinction between you and other clods you perceive as beneath you.

    Maybe The Verge is trying to put down the show’s audience (I didn’t actually read the article), but I hear it a lot. This usage may have started as a form of ironic self-deprecation, but it has become so overused that I no longer hear that.

    How about enthusiast? Of if you really need a word with an air of sophistication, a connoisseur? Of course, you can call yourself anything you want, but if I call you a snob, it won’t be a complement.

    Choosing a VPS Hosting Provider

    I finally got my site up and running. I could have launched it a lot sooner, but I decided to take a detour in the realm of VPS providers. It makes sense that one of my first posts would summarize my findings.

    If you’re in the market for a Virtual Private Server (VPS), there’s a good chance you’ve looked at Amazon EC2, Linode, and DigitalOcean. Amazon essentially defined the market. Linone is a longtime darling of the Hacker News crowd. DigitalOcean is the venture capitalist-funded upstart. All are worthy of your business. Here’s my unscientific, unquantified impression of their relative strengths and weaknesses.

    Amazon Web Services

    Amazon Web Services (AWS) is a smorgasboard of services, of which EC2 is just one. All services are supported by a comprehensive API with client libraries in just about any language you’re likely to care about. The array of services is their greatest advantage and their greatest weakness. Amazon has the tools to build just about anything you can imagine. Way beyond virtual servers, they have globally distributed CDN, hosted NoSQL and SQL servers, persistant virtualized storage (EBS), a way to declare and instantiate all your services (CloudFormation), and authentication scheme to tie it all together. Even that just scratches the surface. Email, SMS, APNS…the list goes on. But where to start? It’s hard to get your head around it all, and it’s easy to get overwhelmed by the information. You have a site to launch; it’s better not to get too distracted.

    EC2 has a reputation for being overpriced and slow. But this is all relative to your use case. EBS is blamed for much of the slowness. I can buy EBS-optimized EC2 instances, but then I’m in a $50/month/server scenario, and I’m looking at $10-$20 price range. If I had an infrastructure than could truly take advantage of the flexibility of EBS, and leverage the synergy of complementary AWS services, I’d probably be happy to pay the difference. In short, it feels like it is built for the likes of Netflix, not the small app builder or blogger.

    Also, pricing can be hard to estimate. If you’re using Amazon’s pricing estimator, plug in a couple terabytes of outgoing data (the amount you get for free at DigitalOcean and Linode). Your cost just went up a couple of hundred dollars.

    Linode

    Linode was doing VPS before it was cool. They have a dedicated following who praise their tech support. Their web UI is an eyesore but complete. And if you’re doing it right, you’re setting up your server with the API instead of the web UI.

    Linode exposes their virtualization underpinnings more than others. Setting up a server is a multistsep process. Choose a distribution, initialize a disk, apply the image, boot the image. This reflects the reality, but sometimes I wonder if it would be better to present a more abstract interface.

    Linode has a unique initialization process. It uses standard scripts (shell scripts, or python, etc., if you image has that installed). They have special syntax to collect variables via web form (so you can enter the MySQL password, for example), and to include (or “source”) other StackScripts. Stackscripts can be shared with the Linode community.

    DigitalOcean

    DigitalOcean is slick and clean. They have a nice UI which feels simple and much less powerful than Linode. Again, you’re probably using an API instead of the web UI, so it is less important than it might seem.

    DigitalOcean supports cloud-init for images that take advantage of it. You can provide a cloud-init configuration file as user data that is available to the image the first time it boots up. It’s no more functional that Linode’s stackscripts, but the configuration file is more delcarative, where the StackScript approach is more procedural. It’s really easy to declare, say, package requirements and let cloud-init take care of the process of installing the package.

    DigitalOcean supports associating an SSH public key with your account and have any new image use that public key for login. Linode supports public key insofar as you can add it to a StackScript and put it in the right place, but it was nice to have it build into the deployment process.

    If you’re a FreeBSD fan DigitalOcean has images for you.

    Conclusion

    I decided that I was spending to omuch time reading documentatin with AWS. For the most part I had decided on DigitalOcean, and had built up a nice workflow to setup and manage a wordpress installation. My informal benchmarks didn’t show much of a difference between DigitalOcean and Linode. As it turns out, I don’t have much of a strong preference between the two. If the workflow offered by Linode fits your style better, I have no doubt you’d be pleased.

    Easy Network Scripting

    I just learned about nc and was so excited I had to write about it. From the man page:

    The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. Unlike telnet(1), nc scripts nicely, and separates error messages onto standard error instead of sending them to standard output, as telnet(1) does with some.

    It also communicates with UNIX Domain Sockets easily. I have been using Python for that, but this is easier for simple and one-off tasks.

    Better Wordpress Management through Fabric

    One of my goals in setting up a Wordpress site was to automate the deployment, configuration, and maintentance. More specifically, I wanted the following:

    • Provider intependence. I should be albe to easily move my site to another hosting provider.
    • Automanted restore. I couldn’t be in a posistion where restoring from backup meant manually tapping in SQL load statements.

    There’s more I want to do long-term, but that’s the bare minimum. The easiest way I found was Fabric. Fabric has a low barrier to entry because it is straigtforwardly build on top of Python functions and the commands on the target machine.

    If you need to run apt-get -y install mysql-server on the target host, the Fabric call for that is:

    run('apt-get -y install mysql-server')
    

    To make the command available outside the script (e.g., from the command line), just add it in a function:

    def install_msql():
        run('apt-get -y install mysql-server')
    

    Then from the shell you can run

    $ fab install_mysql
    

    and you computer will connect to the sever and run the apt-get call above.

    There’s a little bit more to it in getting your hosts, user, and paswords or keys set up, but it’s all pretty straightforward. It works over SSH so there’s no agent to install on the server.

    All your functions can be parameterized in pretty obvious ways. Your backup function might look like

    def backup(dbname, dbuser):
        run('mysqldump -u {0} {1} > $HOME/{1}.sql'.format(dbuser, dbname))
    

    There are additional commands to upload and download files, to sync a directory, and other utilities.

    There are drawbacks. One is that when I say “obvious,” I mean “obvious if you know Python.” It helps if you’re familiar with installing Python packages and some basic syntax.

    Another drawback is the lack of idempotence. I can run apt-get -y install mysql-server multiple times without consequence. But if I run the Wordpress cli, wp core install installs wordpress the first time I call it. If I call it again (after the files are already there), it throws an error.

    I can live with this for now. I really want the initial setup, which always starts with a clean slate. Extending it modify an existing installation can wait for another day.

    Default Arguments in Swift Functions

    Default Parameters in Swift

    Its the little things that make my life as programmer easier. Like default parameters in Swift. From the The Swift Programming Language (Swift 2.1):

    You can define a default value for any parameter in a function by assigning a value to the parameter after that parameter’s type. If a default value is defined, you can omit that parameter when calling the function.

    I was working on a swifty implementation of the DigitalOcean API and I came up with a monster function definition, like this:

    func createDropletNamed(name: String,
        region: String = "nyc3",
        size:String = "512mb",
        image:String = "ubuntu-14-04-x64",
        keys:[String] = [],
        backups:Bool = false,
        ipv6:Bool = true,
        userData:String = "",
        privateNetworking:Bool = false,
        callback:(NSDictionary?, ErrorType?) -> Void = {_,_ in }) {
    

    In the days of Objecective-C, if I wanted simpler convenience versions of this call, I’d define additional functions which take fewer arguments,[1] and then call the monser function by suppliying some defaults. You see that pattern all the time in Objective-C initializers.

    Thanks to the magic of default parameters, that’s not nececcary. Any of the following calls are valid based on the original definition with default arguments:

    createDroplenNamed("devserver1")
    
    createDropletNamed("devserver2", size: "1gb")
    
    createDropletNamed("devserver3") { result, error in
        //handle callback
    }
    

    The swift manual advises lising arameters with default arguments after paramters that always require arguments. Elsewhere, it recommneds that closures always come in the last position to support the trailing closure syntax. Those two rules together imply that if you have a funciton with default arguments and a closure, the closure must take a default argument. Luckily it’s pretty easy to define an empty closure like {_,_ in }.


    1. Actually, I’d probably define a function that takes an NSDictionary, but then I’d lose auto-completion and type checking.  ↩

    Goals for this Site

    My goals this blog are to develop a habbit of publishing writing and photographs. The key thing to both these activities is to practice regularly and to publish. This is my place to do that.

    I used to have a job writing for a living. I was pretty good at it, and I was generally productive. I also enjoyed it. Now my job is coding, not writing. I always intended to keep writing stuff, but that hasn’t happened. This is an effort to publish a few times a week. I’m sure that in the beginning meeting that goal will mean publishing some mediocre to poor articles. For now, publishing a poor article is a minor improvement over publishing nothing.

    Photography is similar to writing in that I always think I’m going to do a lot more than I actually do. My goal for photography to post a few pictures every week or two. These will be new pictures I’ve taken in the previous week, not a dive into my archive. This might include poor photographs taken in my back yard. Again, I consider this a minor improvement over publishing nothing.

    For now at least, the goals are personal. I don’t have any goals of readership or income. I doubt I’ll every change that for this particular blog.

← Newer Posts Older Posts →