<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kevin Cantwell on Medium]]></title>
        <description><![CDATA[Stories by Kevin Cantwell on Medium]]></description>
        <link>https://medium.com/@kevrone?source=rss-9393dcfd6928------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S0w8ZbQwK9MA6DSBM-7icg.png</url>
            <title>Stories by Kevin Cantwell on Medium</title>
            <link>https://medium.com/@kevrone?source=rss-9393dcfd6928------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:35:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kevrone/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Go and Braille to Render Images and Video to a Terminal]]></title>
            <link>https://medium.com/@kevrone/using-go-and-braille-to-render-images-and-video-to-a-terminal-edc8ecfba50?source=rss-9393dcfd6928------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc8ecfba50</guid>
            <category><![CDATA[image]]></category>
            <category><![CDATA[gophercon]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[braille]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Kevin Cantwell]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 21:20:47 GMT</pubDate>
            <atom:updated>2017-07-11T21:20:47.262Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or: I’m Sad and Jealous to be Missing GopherCon This Year, so I Wrote This in Absentia</h4><p>I generally hate going to tech conventions but I do love me some <a href="https://gophercon.com/">GopherCon</a>. The talks are rarely boring or a waste of time, the community is generous and kind, and the passion for the language is driven less by fanaticism and more by pragmatic endeavor. I’ve been to every single GopherCon so far and <a href="https://www.youtube.com/watch?v=VC3QXZ-x5yI">even had the honor of speaking at one</a>, but sadly I’m going to miss this year’s event. So, in a nod to GopherCon’s tradition of hosting a day of lightning talks (a series of short talks by many presenters, each lasting 5 minutes or less) I present you with a brief story about a fun little tool I created — <a href="https://github.com/kevin-cantwell/dotmatrix">Dotmatrix</a> — which uses braille Unicode characters to render images, animated gifs, and even streaming video. I hope you enjoy it :)</p><h3>Inspiration</h3><p>A while ago I was tickled by a small update to the Heroku cli which added a unique spinner I hadn’t seen before:</p><h3>Kevin ✏️🗯 on Twitter</h3><p>I love @heroku tool&#39;s clever use of utf-8 braille characters as a command-line cursor spinner: ⣾⣷⣯⣟⡿⢿⣻⣽</p><p>I didn’t know about the braille Unicode set before then and for some reason my brain wouldn’t shut up about it. I wondered: If arranged in a matrix, couldn’t this character set be used to render pixel-perfect monochromatic images? You know, just like one of those old dot matrix printers? I knew of tools like <a href="https://linux.die.net/man/1/cacaview">cacaview</a> and <a href="https://github.com/eddieantonio/imgcat">imgcat</a> that print images to the terminal using ANSI color codes, but the braille method could display images at twice the resolution. I had just found my new side project!</p><h3>A Type Alias is Born</h3><p>Turns out, each braille Unicode pattern can be calculated from a simple algorithm [<a href="https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering">source</a>]. I declared a type alias of a 2x4 int array and implemented a method to calculate the corresponding Unicode rune:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8H8cevJDdzZ_dGVTYMRw9A.png" /><figcaption><a href="https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering">https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering</a></figcaption></figure><p>I then wrote a command-line tool that would accept an image as input, carve it into a grid of Braille types, print the result as lines of text, and…voilà!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*idfEBUNjubcP6OG4FB_P2Q.png" /></figure><p>Well, would you look at that! Just like those old dot matrix printers but without the perforated margins. I could have left it there, considered it a job well-enough done, but I was unsatisfied. Although this program worked for high-contrast images, it kinda sucked for anything with lots of shading or color. Even this image of Saturn loses all detail on the planet and its rings.</p><h3>Diffusion Confusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*LVhZRVzurhLdSpn1a-famQ.png" /></figure><p>I knew I was limited to strictly black and white pixels, but I thought there <em>must </em>be some way to “shade” neighboring areas of color in grayscale like our man David here on the left. I’m pretty ignorant when it comes to image manipulation techniques, so I called in some backup. My brother is a <a href="https://twitter.com/The_Daily_Bird">skilled photographer</a> and when he took a look at my work he said many things, most of it going right over my head. However, I did catch at least one phrase that made my ears perk up: “Floyd Steinberg diffusion”. Hmm, where have I seen that name before… Oh! That’s right, it’s right there in the draw package:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjpeQwQbZnuCK9WxtFhT6w.png" /><figcaption><a href="https://golang.org/pkg/image/draw/#Drawer">https://golang.org/pkg/image/draw/#Drawer</a></figcaption></figure><p>Thank you standard lib! Now I could achieve much more accurate results without any additional work, which was perfect because I hate work ;)</p><p>Look how much more detail the below rendering captures using the FloydSteinberg drawer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WT19IFDqFtTwk_6aVTAitA.png" /></figure><p>You can make out the rings and even some of the surface detail. Cool!</p><p>A few more examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jZYXahDoNTWy729893qEw.png" /><figcaption>High contrast black and white images look best.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7z8f_HAO3SI31dpOE_d1g.png" /><figcaption>R2 looks good in any setting.</figcaption></figure><h3>Animated Gifs</h3><p>At this point static images looked good and I was pretty happy with that. I even added a few image manipulation functions to my tool such as brightness and contrast adjustments. But the image/gif package is capable of decoding animated gifs and I just <em>had </em>to have that feature<em>.</em> Scope creep!</p><p>Each frame of the gif had to be calculated according to the method specified in the gif file, converted to a Braille matrix, and printed to the terminal with the correct delay. I also had to make some use of ANSI escape sequences in order to reposition the cursor after each frame.</p><p>This took quite a bit of extra time to get right, but the results are pretty satisfying (if I do say so myself). I also learned a lot about the various gif-rendering algorithms in the process (AMA). These are some screen-caps from OSX’s Terminal app, scaled down to reduce file size:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*V4dP2BS66c2Ukqi0r9k4Aw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*sfwaB8Lqip8C_wOpQSCOhA.gif" /><figcaption>Beyoncé’s Lemonade and Akira</figcaption></figure><h3>Video Streaming</h3><p>I’m nowhere close to being able to decode most video formats, but there is one common format — used by many webcams — that was a natural fit for the Dotmatrix tool: Motion JPEG (or mjpeg). This format is nothing more than a bunch of jpeg files concatenated together by a special delimiter. It seems that most webcams can deliver their video in this format when captured from a browser, but if you own a Mac you can also capture the iSight camera feed and convert it to an mjpeg stream using ffmpeg:</p><pre><em>ffmpeg -r 30 -f avfoundation -i FaceTime -vf hflip -f mjpeg -loglevel error pipe:1</em></pre><p>Dotmatrix accepts this mjpeg stream as input and you can use it to render live video to your terminal. Here’s me while writing this article and “printing” myself to iTerm at 12 frames per second :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U36o6QiT117rjdBNx3QgCg.gif" /></figure><h3>Thanks for Reading!</h3><p>That’s it, short and sweet. This was fun to write and I hope you enjoyed it. If you want to take a closer look at the code responsible for this, check out my Github or feel free to DM me via Gmail or Twitter. To all my peeps at GopherCon 2017, especially those organizing and speaking, I salute you. I shall be living vicariously through you on Twitter over the next few days :)</p><h4>References:</h4><ul><li><em>Source code: </em><a href="https://github.com/kevin-cantwell/dotmatrix"><em>https://github.com/kevin-cantwell/dotmatrix</em></a></li><li><em>Braille Unicode pattern: </em><a href="https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering"><em>https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering</em></a></li><li><em>GopherCon website: </em><a href="https://gophercon.com/"><em>https://gophercon.com/</em></a></li><li><em>My 2015 GopherCon talk, What Could Go Wrong: </em><a href="https://www.youtube.com/watch?v=VC3QXZ-x5yI"><em>https://www.youtube.com/watch?v=VC3QXZ-x5yI</em></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc8ecfba50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Travel Guide to Havana for Americans]]></title>
            <link>https://medium.com/@kevrone/a-travel-guide-to-havana-for-americans-954ca3aa8d2f?source=rss-9393dcfd6928------2</link>
            <guid isPermaLink="false">https://medium.com/p/954ca3aa8d2f</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[cuba]]></category>
            <category><![CDATA[havana]]></category>
            <dc:creator><![CDATA[Kevin Cantwell]]></dc:creator>
            <pubDate>Wed, 18 Jan 2017 15:59:15 GMT</pubDate>
            <atom:updated>2017-01-18T19:27:43.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuqsT0gGJZ9W6_WbbsGkzg.png" /><figcaption>El Capitolio, Havana, Cuba. The cars in Cuba are famously retro.</figcaption></figure><p>Cuba is still considered by many to be an enemy of the United States. The Cold War and Cuban Missile Crisis pitted our two nations against each other and the embargoes and diplomatic animosity continue to this day. Up until a few years ago travel to Cuba for US citizens was not possible (or at least illegal) and vice versa. Thanks to improved relations Americans <em>can</em> now travel to Cuba under certain conditions and the influx of American tourists has already begun. Now is your opportunity to experience Cuba <em>before </em>American commercial interests take root. And yes, I’m aware of the irony of that statement!</p><h4>Acquiring a Visa for Travel to Cuba</h4><p>Technically, a pure tourist visa is not possible, but this past weekend my wife and I took advantage of the new — and loosely defined — visa categories to educate ourselves about the small country, enjoy artistic performances, and interact meaningfully with Cubans as a way to celebrate our first anniversary and my 40th birthday. <a href="http://blog.jetblue.com/21-cuba-travel-questions-answered/">There are 12 categories of visa available</a>, but the one we used and that most closely resembles a tourist visa is this one:</p><blockquote>Educational activities, including people-to-people exchanges open to everyone.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*9dt_bnxi4M9VndKbkXC1ag.png" /><figcaption><em>*I am in no way affiliated with JetBlue, I’m just a happy customer!</em></figcaption></figure><p>That’s a pretty broad classification. What exactly defines “educational activities” and “people-to-people exchanges” is unclear. However, <a href="https://www.treasury.gov/resource-center/sanctions/Programs/Documents/cuba_faqs_new.pdf">the legal definition is fairly inclusive</a> and almost anything you would do as a tourist can be considered a qualifying activity. As far as filling out the paperwork, the easiest way to do it is to book travel with JetBlue*, which handles all the red tape on your behalf and charges $50 per visa. All you have to do is select the visa type in a drop-down menu when you book your flight online. Easy!</p><p>It seemed to us that JetBlue is aggressively positioning itself as the best way to fly from the US to Cuba. If you’re departing from JFK they have an entirely separate checkin counter dedicated to issuing Cuban visas (somewhat awkwardly located downstairs in the baggage claim area). The whole experience is pretty smooth. There is an immigration form you must fill out either online or at checkin and I recommend filling it out online before you arrive, as it will save you time at the airport.</p><h4>Money</h4><p>Take cash. There’s no credit card usage in Cuba that I saw. US ATM cards won’t work either. You can’t buy Cuban currency until you’re in Cuba and you might feel disinclined to stand in the 30–40 minute line at the airport. <em>Do not listen to this feeling!</em> It’s very difficult to find a money changer in Havana. The only other place I saw one was in the Hotel Nacional and it had similarly long lines. Better to deal with the line at the airport and plan for the extra time. It’s very safe in Havana, so don&#39;t feel nervous about carrying cash.</p><p>There are two types of currencies in Cuba: The Cuban Peso (CUP) and the Cuban <em>Convertible</em> Peso (CUC). CUP is the older, less valuable, currency. CUC was created to remove US currency from the market and as such it is defined as exactly equal to one US Dollar. One CUC can be exchanged for twenty four CUP, but I don’t recommend it as everything in Havana appears to be priced in CUC. Outside of Havana CUP may be more useful, but I don’t really know.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*owvC5aAyc_XtF-dsFkJWrg.png" /><figcaption>1 USD = 1 CUC. All CUC notes have the words “pesos convertibles” printed on them.</figcaption></figure><p>Diplomatic relations are improving, but the US-Cuban trade embargo still exists. The Cuban government has stated that until the embargo is lifted there will continue to be a 10% penalty applied to converting USD to CUC. You <em>can</em> get around this penalty, however. Our Cuban friends tipped us off that there is no such fee for converting from Euros so before we left New York I exchanged all our USD to EUR at a Travelex downtown.</p><p><strong>Pro-tip:</strong> Travelex currently has a special deal where if you exchange at least $1250 USD to EUR they charge no fees. Using this “one weird trick” we were able to limit our exchange penalty to about 3.5% at the Havana airport by buying CUC with Euros. We haven’t bothered to exchange our CUC back because we know lots of friends planning their own trips to Cuba with whom we can execute a zero-fee transaction :)</p><h4>Getting Around</h4><p>Taxis are everywhere in Havana and easy to flag down. No need to rent a car. My impression was that there are 3 types of cabs: fleet cabs with the familiar yellow checkered logos and meters; classic-car cabs driven by licensed drivers; and unlicensed opportunists looking for a buck. The yellow cab we took from the airport had a broken meter and charged us $35 to get to our Airbnb. We realized later that this was quite expensive as our return trip — also in a yellow cab with a broken meter — only cost us $20. Fleecing of American tourists in this way is not unheard of. The best way to deal with it is some friendly haggling; no need to be a jerk about it. Usually they will come down in price. The truth is, it’s still way cheaper than</p><p>taking a cab from JFK to Brooklyn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-egx1yU7TwTQh-pRDg8yQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9IMOGd5WQE48O9wpoqBOQ.png" /><figcaption>Two typical classic car taxis. Don’t expect to find any seat belts!</figcaption></figure><p>Most of the time you can flag down any of the classic cars driving around as many of them are taxis. Some have a taxi light and some don’t. Some are extremely well cared for and others are downright decrepit. In Old Havana you’re probably going to get a whole taxi to yourself, simply because of the tourist culture, but it’s common for the locals to ride-share. Don’t be shocked if your driver pulls over to pick up extra fares. Ride sharing makes the trip vastly less expensive too! Our short ride from the Hotel Nacional (where we stopped for a sunset mojito) to our Airbnb in Old Havana cost $15, a rip-off. But our shared ride in the Vedado neighborhood only cost $1 each. I’m not a great negotiator — I usually just accept the price quoted — but I probably wouldn’t go for a similar $15 ride after that!</p><p>There was just one time where we found ourselves in a place devoid of many taxis. But we walked to a busy street and only had to stick our arms out before an unlicensed opportunist stopped to pick us up in his teensy tiny personal vehicle (smaller than a smart car!). He quoted a $10 ride from Playa Havana to Old Havana – our furthest trip – and after 3 hours of walking we were happy to pay it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TjDDx4mWea-4yWNBfGrc6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ef9GJdIrIM5DAPUCW7UFGQ.png" /><figcaption>You can walk for hours down streets like these in Havana. If you’re pasty white like me (left) and sensitive to sun, a hat is a must!</figcaption></figure><p>A note about maps: Keep a paper map with you. Yes, GPS works, but there is no cheap or reliable data connection and for some reason Google Maps does not support offline downloads for the Havana area. I ended up downloading <a href="https://itunes.apple.com/gb/app/cuba-travel-guide-featuring/id497675447?mt=8">some off-brand map application</a> that had most of the streets labeled and I’m <em>very</em> glad I did. Just walking around can be a bit confusing if you’re not familiar with the area. There were also a few times I caught our driver making a wrong turn.</p><h4>The Language Barrier</h4><p>Lots of Cubans speak perfect English, but many do not. You <em>could</em> get by without learning any Spanish, but c’mon, if you’re traveling to Cuba the least you could do is download a translator app or buy a phrasebook. It makes those confusing moments so much easier. Many waiters and shop owners speak English, especially in Old Havana, but cab drivers are hit-or-miss. I found that if you at least make an attempt at Spanish people warm up to you very quickly and become more willing to make an effort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*PkkCWJQGtxVkNpoygeGEQA.png" /></figure><p>I personally only have a high-school Spanish education, most of which I’ve forgotten. I can remember some nouns, but my verb conjugation is shit. Before I arrived I downloaded a few dictionary apps, but I found the <a href="https://itunes.apple.com/us/app/google-translate/id414706506?mt=8">Google Translate app</a> to be the most useful. You can download any language for offline use and it <em>just works. </em>I found myself using the app to prepare a few questions I knew I was likely to ask or to confirm a word or phrase I thought I already knew. But there were a couple of times where I’d resort to simply showing the app to someone to get a point across or clarify a question. At the very least, learn how to say “Do you speak English?” and “I don’t understand”.</p><p>A Mexican friend of mine says that Cuban Spanish is sometimes hard for her to understand because they don’t pronounce the last syllable. As a non-Spanish speaker I didn’t notice that, but if you’re used to hearing other forms of Spanish you might keep that in mind.</p><h4>Where to Stay</h4><p>Havana is famous for its atmospheric Hotels. By all means you should check out the Hotel Nacional or Saratoga if you can afford it, but you might be disappointed by the cost vs. value. Instead, consider using Airbnb and sending your dollars directly into the pockets of a local.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gapw_AH3Ffeizbq64y3F5w.png" /><figcaption>The view from our Airbnb smack dab in Old Havana.</figcaption></figure><p>The <a href="https://www.airbnb.com/rooms/16183633">Airbnb we used</a> is located directly in Old Havana and owned and operated by a kindly lady named Mirtha. She doesn’t speak much English, but her account is managed by a helpful woman named Giselle who does. For about $90/night we got two rooms, 4 beds, a kitchen, two bathrooms, a living room, and a balcony overlooking an old fortress (now a police station). The fridge was stocked with water and beer and they served a continental breakfast for $5. Friends told us to bring our own toilet paper, but we needn’t have bothered.</p><p>Something you should know: Nobody is coming down to open the door when you ring. It’s more common for people to throw keys down to the street or lower a bag on a rope. When we arrived we spent a few minutes nervously hitting the buzzer before we realized our host was calling to us from the top floor balcony. So look up!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w5sIr1raOT5ZNit2NWrCVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjwbLfqc2ZbHQvDCDPcNFA.png" /><figcaption>Fancy hotel on the left. Potential Airbnb on the right.</figcaption></figure><h4>Where to Eat</h4><p>Food is relatively cheap. Compared to New York prices it’s about 1/4 or 1/2 of what we’re used to paying. The drinks are especially cheap. Mojitos are typically $2–4. Breakfasts are $3–5. Dinners are $7–15, $20–25 for high end joints. But if you don’t know what you’re looking for, finding quality food can be luck-based. Luckily, we know a few Cuban-Americans who travel regularly to Havana and provided recommendations. Allow me pass on the goods to you!</p><p>Nobody drinks the tap water and you shouldn’t either. Bottled water is available in almost every shop. I’ve also heard that the meat quality is…variable. We had no issues, but we only ate at well-reviewed locations based on recommendations. Typically, what you see is what you get. If a place looks a little unclean or questionable, it’s probably best to avoid drinking anything with ice or eating the meat. Likewise, if the establishment looks clean the food is probably clean too and the ice made from boiled water (we drank a lot of mojitos without any problems). Thankfully the food is relatively cheap so eating at nicer locations won’t break the bank.</p><p>Our Cuban friends all told us to call ahead from the States and make reservations (Start with “<a href="https://translate.google.com/#auto/es/Do%20you%20speak%20English%3F">¿Habla usted Inglés?</a>” if you’re not sure how to approach the call as most phone operators speak perfect English), and it <em>was</em> difficult to find availability. However, we simply showed up to a few restaurants that we were previously told were fully booked and never had a problem getting a seat. My instinct tells me that good restaurants fill up without a problem and they would rather take reservations in person than deal with an international caller who might flake out and leave a table empty, but who knows. Here’s where we ate:</p><p><a href="https://goo.gl/maps/UUBEmVBEGNm"><strong>5 Esquinas Trattoria</strong></a>: This romantic breakfast and dinner spot is in the heart of Old Havana. It takes its name from its location, which is at a 5-way intersection of ancient cobble-stone streets. The outdoor seating is surrounded by colonial architecture that has a Romanesque feel to it. By phone we were told there was no availability, but when we walked in at 6:30pm we had no problem getting a seat. A long line formed quickly thereafter, so we got lucky I guess. You probably won’t see many locals eating here, but the food is still good. There’s a <em>very</em> friendly waiter named Johnny that works here (seemingly at all hours). I doubt he’d remember <em>us</em>, but he’s one of those people who makes a trip like this memorable. I ordered a white bean and dried fruit lasagna that was highly enjoyable and my wife had a tasty white fish (unidentified). Mains are ~$8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFG-4LRod5N4XEOAboP3pA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*lBqNh1-5lh5XHt5sWpah3w.png" /><figcaption>5 Esquinas: Johnny on the right. He seems to always be there, breakfast, lunch, and dinner! (Right photo credit: tripadvisor.com)</figcaption></figure><p><a href="https://goo.gl/maps/zK2wLgjQ4do"><strong>Jaqueline Fumero Cafe &amp; Boutique</strong></a><strong>:</strong> Just one block uphill from 5 Esquinas and outside of the Iglesia del Santo church is a breakfast spot with perhaps the most secluded outdoor seating in Old Havana. We found this place on our own and ate there both mornings. The food is good, not great, and a little slow to arrive, but it’s a beautiful spot to sit and plan your day. I recommend the savory crepes and the smoothies, which are more like creamy milkshakes. A continental breakfast (juice, coffee, bread, &amp; fruit) will only set you back $3.50. Watch out for a young little rascal combing the tables for candy money!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TxnkuXFsMBQSeJ8sZdmWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3DP_jL5nCllw3bq7hZyGg.png" /><figcaption>Jaqueline Fumero: Bed-head on the left. Steps of Iglesia del Santo Angel Custodio on the right.</figcaption></figure><p><a href="https://goo.gl/maps/PExN1hMupsp"><strong>El Cocinero</strong></a>: This out of the way hotspot has a great view and even better food. Located on the edge of the hip Vedado neighborhood, this converted factory has an outdoor terrace surrounded by plants one one side and an old smoke stack on the other. You enter the restaurant via a spiral staircase built directly inside the smoke stack itself. One piece of advice: the canvas bucket seats aren’t that comfortable. If you can, sit at an edge table across from the bar. You’ll be more comfortable and have a better view of the restaurant. The food was very good to excellent. I had a tasty lamb roast that fell off the bone, but I thought our starters — a layered crab cake and cheese empanadillas — were more creative and flavorful. Mains ~$10.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZMz5dgGJHwGyaZqPDFY_uA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_IVPA0V8oHUqUKc8MQsL7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NL_Fi0pnNJHBFKwJu-Bl_Q.png" /><figcaption>El Cocinero is popular at night and quiet during the day. (Left and right photo credits: insidecuba.havana-club.com, paseosporlahabana.com)</figcaption></figure><p><a href="https://goo.gl/maps/NgLHTyEWik52"><strong>Paladar La Cocina de Lilliam:</strong></a> This place. This place! Highly recommended by a friend, this was without a doubt the best experience and food we had in Cuba. A “paladar” is a type of Cuban restaurant run directly out of a home. Lilliam is a high-end paladar located deep in the residential Playa Havana neighborhood (you’ll want to take a taxi if coming from Old Havana: $10–20). The homeowner is a former fashion designer who turned her passion for cooking — and her home — into a well-respected restaurant with top-notch service. The grounds are beautiful, lush with vegetation, with a dark wood, labyrinthine feel. We showed up earlier in the day to make a reservation and almost gave up looking for the place, it’s that easy to miss! A porter opened the gate as we walked up and we entered the house via a porch door. Sitting out on the porch was the friendly grandfather who let us pet his dog. I think we surprised the family as they ate lunch together, but they were very kind to us and tolerant of my poor Spanish as I booked a time for that evening. This is the kind of personal experience we travel for. Others may find it frustrating not to have that formal restaurant vibe, but we thought it was magical. When we returned for our reservation at night (semi-formal attire is appropriate here) the service was impeccable. We were shown through the seating area, past a piano player playing a mix of classics and modern tunes, to our table at a private section in back where every inch of every wall was covered in some kind of personal memento of the family. We ordered just two items off the menu: A chickpea dish served in a skillet with fresh veggies and ham that, trust me, tasted far better than it sounds; And a tremendous lobster paella dish for two (“for two” turned out to be a gross understatement!). Our server, Neil, took great care of us, even ordering a complimentary and delicious guava chocolate cake for us (plus a shot of homemade rum) when he found out it was my birthday. Thanks Neil! Mains: $14–26.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-d0jZwkYfpaWbfHip6Jvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7GNEpdUA7tcDq6zQ8lCFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsOxRdUAmT95uNHyKPSWTQ.png" /><figcaption>La Cocina de Lilliam: A hidden gem full of magical people and magical food!</figcaption></figure><p>Some other recommended restaurants that we were unable to try:</p><ul><li><a href="https://goo.gl/maps/LS9UeLxvJAk"><strong>El Ajibe</strong></a><strong>:</strong> A chicken and rice and bean place that is supposed to be delicious and cheap.</li><li><a href="https://goo.gl/maps/qJmCKsvhbnm"><strong>El Corte del Principe</strong></a>: An Italian place located south of central Havana.</li><li><a href="https://goo.gl/maps/6tx74q88tHF2"><strong>Area 53</strong></a><strong>:</strong> A hip place near the beach.</li><li><a href="https://goo.gl/maps/aB7dLSPg5Av"><strong>StarBien</strong></a><strong>: </strong>Pricey but good food.</li><li><a href="https://goo.gl/maps/DZjbWz4qu8u"><strong>Paladar Dona Eutimia</strong></a><strong>: </strong>Another home-run restaurant smack dab in Old Havana.</li></ul><h4>The Arts</h4><p>Cuba is known for its music and performing arts, such as cabaret. There’s also a rich art scene all over Havana. Scattered all over Old Havana are art galleries and antique shops where you can find large high-quality oil painting for under $200. Just keep your eyes peeled. Cuban art is everywhere. Museums are all nearby one another in Old Havana and some are quite large. Unfortunately, we didn’t have much time to seriously explore any museums.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UzdZc58o1yK95DvvsUzl3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8vSdgeL2M6W_y22i134HpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tNKUokI3afWjvQKCg0fkg.png" /><figcaption>Street art and large galleries aren’t hard to find, but they may not be open when you are there.</figcaption></figure><p>The cars themselves are quite artistic as well. Classic cars straight out of a time warp and customized for a modern aesthetic. Some are recognizable, others are quite bizarre to Western eyes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*esoldujcvSvH7JPjnbeedQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jz4NtysAw_BAKKTGKXjQfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-iB24gqME48RsU_BJhbJ9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhqsl2DMW-fGJ64yjX7NNg.png" /><figcaption>Che’s image is everywhere!</figcaption></figure><p><a href="https://goo.gl/maps/srwtWbqQ2L62"><strong>Cabaret Tropicana</strong></a><strong>:</strong> The Tropicana is something every tourist hears about when planning a trip to Havana. Its cabaret is world-famous, yet some of the reviews are lackluster and the tickets are expensive ($90–110 per person; the more expensive tickets get you closer to the stage). We decided we would try it, despite the mixed reviews (yolo!). The ticket price included preferred seating and dinner with a bottle of rum. We were pretty convinced the dinner was going to suck and one local we spoke to about it confirmed that “cabaret food is always terrible”. Luckily we had our reservation at Lilliam that night, so food wasn’t a problem. The show itself started at about 10:30pm and we arrived at 11:00pm to catch the last hour. My impression is the Tropicana was once glamorous, but has since been eroded by time and tourism. The online booking explicitly indicated a formal dress code, and we abided, but judging from the crowd it was clear that as long as you wear long pants and a collared shirt anything else goes. I saw plenty of ripped jeans and short sleeves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JX7RGi-3ENrikk-cUfA0ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2oDIKXB0nQOOjgbdSF4y3A.png" /><figcaption>Tropicana Cabaret is a mix of song and dance performances. The audience is 100% tourists.</figcaption></figure><p>We also felt the dancing and singing, while technically impressive, was not as well-synchronized or choreographed as expected. It felt a bit dated as well. As though we were inside a Vegas club in the 1980’s, complete with (to my Western sensibilities anyway) tired depictions of African cultures and sexist motifs. Nothing cutting edge or innovative. Crazy Horse in Paris blows this place out of the water, to be honest. Out of everything we did in Havana, this is the one place I wouldn’t go back to. Sorry Tropicana!</p><h4>Internet</h4><p>Wifi is almost impossible to find. There are a few locations around the city where public wifi is available, but it requires a login that I never figured out how to acquire. You can usually spot these locations by the crowds of people huddled around their smart phones. Otherwise, you can find an internet cafe here and there. I know T-Mobile offers a data plan at $2/mb, but we didn’t even bother. We spent the entire weekend untethered and we have no regrets!</p><p>I did use my phone quite often, however, in order to use offline maps and translator apps. Plugs are US-compatible for charging.</p><h4>Safety</h4><p>Havana has a reputation for being very safe. There are police every couple of blocks and the government is tough on crime. Cuba does have a ‘Machismo’ culture and females walking by themselves are likely to get cat-called, which can be traumatizing for some. The one time my wife and I walked a distance apart she received some hissing from across the street (a form of cat-call). Actual touching, however, is highly unlikely due to the police presence and crowded streets. In my opinion, the business is what makes it so safe. There’s always pedestrians around.</p><h4>Do’s and Don’ts</h4><ul><li>Do: Use Airbnb. It’s cheaper, you can find quality lodging without too much trouble, and the money will go into the locals’ pockets.</li><li>Do: Download some offline maps and translator apps before you arrive.</li><li>Do: Book a reservation at La Cocina de Lilliam!</li><li>Do: Exchange Euros instead of USD to avoid the 10% penalty fee.</li><li>Do: Buy art!</li><li>Don’t: Wait until you get to Havana city to exchange your cash.</li><li>Don’t: Expect to have wifi, use credit cards, or an ATM.</li><li>Don’t: Rent a car. Use taxis.</li><li>Don’t: Insult Castro publicly. Cubans are <em>very</em> patriotic.</li></ul><h4>Conclusion</h4><p>Go to Cuba. Experience it. It’s romantic! But remember also that you are an unofficial ambassador of the United States and the political relationship of our two nations is still delicate. Your behavior leaves an impression on those who live there and it’s up to you to confirm or dispel any preconceived notions of what Americans might be like. While there I never felt judged or dismissed for being an American, one honest waiter explained to us that in his experience New Zealand tourists were the kindest customers, Canadians a close second, and Americans third, if often a bit arrogant. So be courteous, learn at least some Spanish before you go, and treat people with respect. There’s no longer any reason why Americans and Cubans can’t nurture great friendships.</p><p>¡Viva La Revolución!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=954ca3aa8d2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One Year of DynamoDB at Timehop]]></title>
            <link>https://medium.com/timehop/one-year-of-dynamodb-at-timehop-f761d9fe5fa1?source=rss-9393dcfd6928------2</link>
            <guid isPermaLink="false">https://medium.com/p/f761d9fe5fa1</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[timehop]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Kevin Cantwell]]></dc:creator>
            <pubDate>Mon, 16 Mar 2015 17:18:08 GMT</pubDate>
            <atom:updated>2015-03-16T17:45:11.668Z</atom:updated>
            <content:encoded><![CDATA[<h2>One Year of DynamoDB</h2><h2>at Timehop</h2><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*9LxG1gA4j8rD3jTz4dk9fw.png" /></figure><h4>2,675,812,470</h4><p>That’s the number of rows in our largest database table. Or it was, one year ago today. Since then, it’s grown to over 60 billion rows. On average, that’s roughly 160mm inserts per day.</p><p>When I think about it, that seems like quite a lot. But because the database we use is Amazon’s <a href="http://aws.amazon.com/dynamodb/">DynamoDB</a>, I rarely have to think about it at all. In fact, when Timehop’s growth spiked from 5,000 users/day to more than 55,000 users/day in a span of eight weeks, it was DynamoDB that saved our butts.</p><p><strong>What is DynamoDB?</strong></p><p>I don’t intend to explain the ins and outs of what DynamoDB is or what it’s intended for, there’s plenty of <a href="http://aws.amazon.com/dynamodb/details/">documentation</a> online for that. But I will mention the most salient point: That DynamoDB is consistent<em>, </em>fast, and <em>scales without limit. </em>And when I say “scales without limit,” I literally mean there is no theoretical boundary to be made aware of. That isn’t to say that all of DynamoDB’s features behave identically at every scale, but in terms of consistency and speed it absolutely does. More on that below. First, some history.</p><p><strong>The Ex I Worry About Seeing in My Timehop is Mongo</strong></p><p>Timehop currently uses DynamoDB as it’s primary data store. Every historical tweet, photo, checkin, and status is persisted to DynamoDB as time-series data. It wasn’t always this way. Back in ye olden days, we used a combination of Postgres and Mongo. So why the switch?</p><p>Listen, Mongo is great. I mean, I’m sure it’s pretty good. I mean, there’s probably people out there who are pretty good with it. I mean, I don’t think my soul was prepared for using Mongo at scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKm0FVMuAQ9Q2ajMDPKcjw.jpeg" /></figure><p>When we were small, Mongo was a joy to use. We didn’t have to think too hard about the documents we were storing and adding an index wasn’t very painful. Once we hit the 2TB mark, however, we started to see severe and unpredictable spikes in query latency. Now, this might have been due to our hosting provider and had nothing to do with Mongo itself (We were using a managed service through Heroku at the time). Or, if we rolled our own we might have solved things with a sharded solution. But to be honest, none of us at Timehop are DBAs and a hosted database has always been a more attractive option (As long as it didn’t break the bank!). So we started to look at alternatives. Our friends at <a href="https://groupme.com/">GroupMe</a> had some nice things to say about using DynamoDB and it seemed <a href="http://aws.amazon.com/dynamodb/pricing/">pretty cost-effective</a> too, so we gave it a go.</p><p><strong>Early Mistakes with DynamoDB</strong></p><p>As is often the case with new technologies, DynamoDB first seemed unwieldy. The biggest hurdle for us right out of the gate was the lack of a mature client library written in Go, our primary language (<a href="https://github.com/goamz/goamz">Things have changed since then</a>). But once we nailed down the subset of API queries we actually needed to understand, things started to move along. That’s when we started making real mistakes.</p><h4>Mistake #1: Disrespecting Throughput Errors</h4><p>This one should have been obvious as the <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html">error handling docs</a> are quite clear. DynamoDB has two main types of http errors: retryable and non-retryable. The most common type of retryable error is a throughput exception. The way dynamo’s pricing model works is that you pay for query throughput, where reads and writes are configured independently. And the way Amazon enforces throughput capacity is to throttle any queries that bust it. It’s up to the client to handle the errors and retry requests with an exponential backoff. Our early implementations assumed this would be a rare occurrence, when in reality, you will likely incur <em>some</em> amount of throttling at any level of usage. Make sure you handle this frequent type of error.</p><h4>Mistake #2: Not Understanding How Partitions Affect Throughput</h4><p>All DynamoDB tables are partitioned under the covers and each partition gets a sliver of your provisioned (purchased) capacity. The equation is simple:</p><pre>Total Provisioned Throughput / Partitions = Throughput Per Partition</pre><p>What this means is that if your query patterns are not well distributed across hash keys, you may only achieve a fraction of your provisioned throughput. Not understanding this point can lead to serious headaches.</p><p>It’s also important to say that the number of partitions that exist are not directly exposed to you (However, there is now a <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForTables.html#GuidelinesForTables.Partitions">helpful guide</a> to help you estimate the number of partitions you are accruing). A single table may have 1 partition or 1000. That means it’s difficult to predict exactly how hot a key can become. And the larger your table grows the more partitions that will be allocated to it. Which means you may not even notice hot key issues until you are at scale. The best thing you can do is fully understand how to design and use a well distributed hash key.</p><h4>Mistake #3: Poorly Designed Hash Keys</h4><p>DynamoDB tables can be configured with just a hash key, or with a composite hash and range key. Timehop’s data is in time-series, so for us a range key is a necessity. But because hash keys always map to a single virtual node in a partition, a large set of range keys per hash key can lead to hot-key problems. I dug into my old emails and found a few write capacity graphs that illustrate this point:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R0d5Xdr8HmjczlRTGyztyA.png" /><figcaption>March, 2015</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PiwNmE7IOmbBAOctqaNdcA.png" /><figcaption>March, 2014</figcaption></figure><p>The red lines here indicate provisioned throughput, ie: the most you could ever use. The blue lines represent actual throughput achieved.</p><p>The top graph represents our current schema, which has a well-designed hash key based on a combination of user id and calendar date.</p><p>The bottom graph shows our first stab last March, where our hash key was just the user id. Notice the difference? Yeah, it was bad. It took us about 3 attempts at loading and destroying entire tables before we got it right.</p><p><strong>Advanced Lessons</strong></p><p>Once we stopped making the above mistakes we found further ways to optimize our DynamoDB usage patterns and reduce costs. These points are actually covered in the <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForTables.html">developer guidelines</a>, but we had to make our own mistakes to reach the same conclusions.</p><h4>Lesson #1: Partition Your Hash Keys</h4><p>Every hash key will consistently hit a single virtual node in DynamoDB. That means that every range key associated with a hash key also hits that same node. If a Timehop user has 5000 items of content (a rough average) and most of that content is written at around the same time, that can result in a very hot hash key. Anything you can do to split the data across multiple hash keys will improve this. The pros and cons of doing so are:</p><ul><li><strong>Pro</strong>: Hash key distribution increases linearly with each hash key partition; Throughput errors decrease.</li><li><strong>Con</strong>: The number of network queries required to write the same amount of data increases linearly with each hash key partition; the likelihood of i/o errors and poor network latency increases.</li></ul><p>For Timehop our hash key partition strategy was a natural function of our use case: We partition all user data by date. This gives us a significant increase in hash key distribution. As an example, a user with 5000 items of content across 7 years of social media activity sees about a 2.5k times increase in distribution:</p><p>Without partitioning (ie: hash key = “&lt;user_id&gt;”):</p><pre>5000 items per hash key on average</pre><p>With partitioning (ie: hash key = “&lt;date&gt;:&lt;user_id&gt;”):</p><pre>5000 / 365 days / 7 years = about 2 items per hash key on average</pre><h4>Lesson #2: <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForTables.html#GuidelinesForTables.DataUpload">Temporally Distribute Your Write Activity</a></h4><p>As I stated earlier, a table that uses a range key can expect at least <em>some</em> throttling to occur. How many errors you experience is directly tied to how well distributed your hash keys are. However, if you really want to maximize your throughput you should also consider temporally distributing the writes you make against a single hash key.</p><p>Our writes happen asynchronously when a user signs up and connects their social media accounts. At any given moment the write requests that occur are heavily skewed towards the subset of hash keys that represent the most recent new user. In order to encourage well-distributed writes, we built a simple write buffer that sits in front of DynamoDB (essentially a managed Redis set). A separate process drains random elements from the buffer and issues batch write requests to DynamoDB. The more users that sign up together, the more data that ends up in the buffer. The key benefit of this architecture pattern is the more data that’s in the buffer, the more randomization there is when draining it and therefore more distributed the hash keys are in our batch write requests. <em>So</em> <em>increasing scale actually improves</em> <em>our write performance</em>. Yay!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kAs2CfxDySbh70bXr5ju3w.png" /></figure><p><strong>Scaling Without Limit</strong></p><p>So now that we’ve got our usage patterns stabilized, what’s the real benefit? The most explicit win we saw from using DynamoDB was during our most significant period of user growth, which just happened to coincide with our final draft of a DynamoDB strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*WVk5MCi1LwNmsggI8RS_kw.png" /><figcaption>Dat growth doe</figcaption></figure><p>During the 8 week period between March and May of 2014 our user growth started to spike upwards from roughly 5k signups/day to more than 55k signups/day. As you can imagine we were hyper-focused on our infrastructure during this time.</p><p>There were many many fires. Each dip in the graph probably corresponds to some outage or backend service falling over due to load. But what the dips definitely <em>do not</em> represent, is an outage or performance problem with DynamoDB. In fact, for the last year, no matter how large our table grew or how many rows we’ve written to it (currently in the order of hundreds of millions per day) the query latency has <em>always</em> been single digit milliseconds, usually 4–6.</p><p>I can’t stress enough how nice it was not to have to think about DynamoDB during this time (aside from a few throughput increases here and there). This was a new experience for Timehop Engineering as in the past the database was always the choke point during periods of growth. The stability and performance of DynamoDB allowed us to focus our efforts on improving the rest of our infrastructure and gave us confidence that we can handle the next large spike in user signups.</p><p>AWS describes DynamoDB as a providing “single-digit millisecond latency <em>at any scale</em>” (emphasis mine). We’ve asked the DynamoDB team what the theoretical limits are and the answer is, barring the physical limitations of allocating enough servers, there are none. In evidence of this, our table is quite large now, about 100TB, and the performance is the same as on day one.</p><p>Thanks for reading! I hope you’ve gleaned something useful from this post. We will continue to optimize our DynamoDB usage patterns where we find opportunity and broadcast the lessons we learn along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/40/1*oZ151Oe4bwag9HzQwb-AbQ.png" /></figure><h4>by <a href="https://twitter.com/kevrone">Kevin Cantwell</a>, Lead Architect <a href="http://tales.timehop.com/">@Timehop</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f761d9fe5fa1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/timehop/one-year-of-dynamodb-at-timehop-f761d9fe5fa1">One Year of DynamoDB at Timehop</a> was originally published in <a href="https://medium.com/timehop">Timehop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>