i've noticed..

2011, May 25

So… here’s what I did tonight

http://instaplac.es - Instaplaces is a tool for finding cool things around you that you may have never knew existed. By using your phone’s GPS or your computer’s location, I’ve listed below the places near you where people are taking pictures most frequently using the popular Instagram app.

I was playing around with Instagram and noticed that there were locations for each picture, but seemingly no way to look at images taken at that location. So, instead of worrying about this missing feature… I built it.

I don’t know what got to me, I don’t really have free time, but I really wanted to get this done because I’ll be moving to a new city in the next few weeks and will be looking to do all kinds of exploring. With Instaplaces, I can figure out what places are fun just by looking how many pictures are taken there and of what.

There are a few issues - like a lot of pictures going un-tagged with a location and a limited amount of images, but Instamatic grows every day and hopefully this will encourage people to tag their photos with a location ;). I also noticed it didn’t work when I tested in Safari, but it works fine in Safari for iOS - so I’m just chalking that up to a gimmick for now.

Behind the scenes, Instaplaces is built with sintra and obviously powered by the Instagram API.


2011, Feb 28

Convert Time to a Fraction

If you come across the need to store time as a float in ruby (I won’t judge you), you can use this bit of code. It assumes that each subpart of the time string is 60 parts of the previous part. This works for hours, minutes and seconds, regardless of how it is entered, and will always use the first part as the base measurement.

j = 0

timer = 0

"12:40:30".split(':').each do |y|

timer += y.to_f / (60**j); j += 1;

end

In this example, the numbers 12, 0.66, and 0.008 are summed to give 12.6724 hours.

2011, Jan 09

A Very Brief Introduction to bing-location

Over the weekend, I finally published my Ruby Gem bing-location. There isn’t much to it yet, but it is easily forked from the github repository and I encourage contribution!

Here’s a bit from the documentation:

This class is a wrapper for the Bing Maps API that makes it easy to get more information about a location or create maps.

Currently the class is built for dealing with one object (point on a map/location).

2010, Aug 12

Multithreading in Ruby Like a Champ

Multithreading is a great tool when you know how to use it. For a recent project, I had to download hundreds of web pages. To speed the process up, I set the page download process up to start a new thread. The only problem with this is that opening hundreds of connections at the same time would cause server errors and I would get blank pages. My solution, which you’ll find below, was to only allow 10 threads to be created at once. This worked great, so I’m sharing it with you.

Here ya go

# Contains download_link(link,save_dir,save_name) to download and 
# save webpages locally (irrelevant)

require 'download_page'

# keep the threads in here
threads
= []

(1967..2010).each do |year|

 
# excluded irrelevant variable definitions :  
# link,save_dir,save_name ...


 
# Only open 10 threads at a time
 
if(Thread.list.count % 10 != 0)
    download_thread
= Thread.new do
      download_link
(link,save_dir,save_name)
   
end
    threads
<< download_thread
 
else
   
# Wait for open threads to finish executing 
# before starting new one

    threads
.each do |thread|
      thread
.join
   
end
   
# Start downloading again
    download_thread
= Thread.new do
      download_link
(link,save_dir,save_name)
   
end
    threads
<< download_thread
 
end
end

# Wait for threads to finish executing before exiting the program
threads
.each do |thread|
  thread
.join
end
2010, Jun 11

Check to see if a domain name is available (ruby)

# Check to see if a domain is available (unregistered)
def available?(domain_name)
  # Use Net::DNS library via ruby gems
  require 'rubygems'
  require 'net/dns/resolver'
  res = Net::DNS::Resolver.new
  # Use Google public DNS for speed
  res.nameservers = ["8.8.8.8","8.8.4.4"]
  res.udp_timeout=(60)
  packet = res.search(domain_name, Net::DNS::NS)
  # Check for domains packets with Answers
  # This means a domain returned a DNS record (registered)
  if(packet.header.anCount > 0)
    return false
  else
    return true
  end
end

2010, May 31

There must be an easier way..

.. to create multidimensional arrays in ruby.

Here’s the only solution I found that works the way I expected it to. This solution works but I have no clue as to how. So, I’m assuming there is an easier, more intuitive, way of doing it and I am asking you for your help.

hash_lambda = lambda { Hash.new {|h,k| h[k] = hash_lambda.call } }
teamOfficial = hash_lambda[]

teamOfficial[‘Minnesota’][‘ncaa’] = ‘Golden\ Gophers’

teamOfficial[‘Minnesota’][‘nfl’] = ‘Vikings’

teamOfficial[‘Minnesota’][‘nba’] = ‘Timberwolves’

My goal is to allow each element to have a unique combination of keys, even with redundant information and without brute forcing the data into one string for the key (i.e. ‘ncaaMinnesota’, ‘nbaMinnesota’). Storing an array inside of another is less than ideal for what I’m doing.