Tag Archive: Programming

First Seven Languages

August 23, 2016 9:19 am Published by 1 Comment

My #FirstSevenLanguages:

  1. BASIC – I remember programming BASIC on my parents’ IBM PC around the age of 6. For a long time it was mostly copying simple code from books and writing tight for loops. Eventually I progressed to QBASIC and some simple graphics stuff.
  2. C – My dad taught me C when I was getting fed up with BASIC. The only thing I remember writing was a crappy RPG based on the places I hung out with friends.
  3. TI-BASIC – I wrote a bunch of small programs that automated some geometry/trig/calculus rules for my TI-82 in High School. I also wrote some games, tic-tac-toe and 2-player checkers among the ones I recall.
  4. Pascal – I learned Pascal in high school, as part of the AP Computer Science program. My proudest moment was Uno and Battleship, both with simple AI opponents.
  5. Perl 5 – I learned Perl in my free time my freshman year at college. I created a small community website (wsvw1u.com) using CGI.
  6. C++ – The Computer Science courses at RPI were primarily in C++ at the time I was there. For parts of courses, I also dabbled in MIPS assembly, Smalltalk, and Scheme.
  7. JavaScript/JScript – My first full-time job after graduation was writing tools for the 24-hour NOC at Priceline.com. We used a mix of Perl, server-side JScript, and JavaScript.

JavaScript Flickr carousel

December 19, 2014 9:03 am Published by Leave your thoughts

My wife and I made something a couple of weeks ago, and her name is Simone. Our families and some friends want to see lots of pictures, but most people don’t want us to flood their Facebook feeds with baby photos (nor do we want to). So we’ve been uploading them to Flickr mostly, but I wanted a slightly simpler page where people could just see a carousel slideshow of photos of our daughter. There was no good immediately-integrated-with-Flickr JavaScript carousel I could find, but I was pretty easily able to integrate it with Fotorama.

Here is the final product (and beautiful pictures of my girl). Here are the easy steps to do it yourself:

  1. Sign up for a Flickr API key. If this is a non-commercial site, it’s free and instant.
  2. Grab the download or copy the hotlink markup from the setup page in the Fotorama docs
  3. Add this markup to your page:
    <div class="carousel" data-auto="false"></div>

    There’s a lot of configuration options you can add besides that. Here’s the full list.

  4. And now the final step, the JavaScript that populates the carousel:
      <script type="text/javascript">
        $(function() {
          var AddPhotosToCarousel = function(data) {
          var imgs = [];
          $.each(data.photoset.photo, function(index, photo) {
            imgs.push({img: photo['url_m'],
                       thumb: photo['url_sq'],
                       caption: photo['title']});
            });
            $('.carousel').fotorama({ data: imgs });
          };
          $.getJSON('https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=XXXXXXXXXX&photoset_id=YYYYYYYYYY&format=json&extras=url_sq,url_m&jsoncallback=?', AddPhotosToCarousel);
        });
      </script>
    

You must put your API key and your photoset’s id into that big URL you pass to $.getJSON(). If you want the photos to show up in reverse order (as I did), change imgs.push() to imgs.unshift(). You can display things other than photosets (search results and such), but you’ll need to dig into the Flickr API docs to build those queries yourself.

A bunch of sort algorithms

August 31, 2012 8:10 am Published by Leave your thoughts

Whenever I’m trying to get back into the swing of building and optimizing and evaluating algorithms, my first step is always to write a whole bunch of sorting implementations. I’m also trying to improve my knowledge of the core syntax of python. So here are four sorts in python: insertion, merge, heap, and quick. (The insertion and heap sort implementations are both in-place. The other two are not.)

The second step is probably going to be to implement a data structure I’ve never done before. Last time, it was a min-max heap in PHP. I’m thinking maybe a B-tree?

Update 3 Sept: Here is my implementation of a splay tree. Far simpler than I remembered, so I challenged myself to do it without parent links in the node objects.

Choosing random keys

May 4, 2012 10:45 am Published by Leave your thoughts

Say you had code that generated random keys. These random keys were 6 letters long, all caps, with no duplicates. Here’s a few, as an example:

NTCYAR DHIEWM INBVTX IOELUC
RKNBJX GKRANB DRYVQU YIFKTS
VAUPSG ALWPOS CERSUY WAHJVM
MTXJSZ RNLFXZ VFIEXT VEOKIH

What are the chances that the key that you generate will be in alphabetical order? For instance, above, there’s only one in alphabetical order (CERSUY, in bold) And then, if you think you have that, generalize: For any string of length k distinct characters chosen from a set of n, what are the chances that they will be in order? My answer after the break.

(more…)

Watching every MLB team play a game

December 22, 2011 10:16 am Published by Leave your thoughts

Last April, to no one in particular, I asked the following question:

“What’s the shortest possible trip (in miles) to see every MLB team play at least one game this season?”

It became clear, after a brief discussion with some friends, that the shortest possible trip is somewhere on the order of a hundred miles. Citi Field in the Bronx and Yankee Stadium in Queens are only 6 miles apart. Since the Mets and the Yankees are in different leagues and each team plays one series at home against every other team in its own league, you could just spend the whole season going back and forth between the two stadiums. (In fact, I’d be surprised if at least one New Yorker baseball fan with time and money to burn hadn’t done exactly this.)

In order to avoid this “trivial” solution, a modification to the puzzle would have to be introduced. After throwing around a bunch of attempts, I hit upon the perfect goal: 15 games, 15 stadiums, 30 teams. You’d see no team play more than once, you’d be in no stadium more than once.

(more…)