My first impression of “Keynote Steve” was him berating the poor stage hands over “This Home Depot shit” that was rolling out the display stand with the new Mac, very much not to his satisfaction. His complaints had a valid point, and he improved the quality of the presentation by caring about details, but I wouldn’t have wanted to work for him in that capacity.
One time, my wife, then fiancée, and I were meeting with Steve at Apple, and he wanted me to do a keynote that happened to be scheduled on the same day as our wedding. With a big smile and full of charm, he suggested that we postpone it. We declined, but he kept pressing. Eventually my wife countered with a suggestion that if he really wanted “her” John so much, he should loan John Lassiter to her media company for a day of consulting. Steve went from full charm to ice cold really damn quick. I didn’t do that keynote.
Its always striking how much of a jerk Steve Jobs was. Sure he founded Apple and helped create all the gadgets we love, but is being a jerk really necessary trait for success?
One important thing to note is, the long URL should also be uniquely identifiable from short URLs. So we need a Bijective Function.
One Simple Solution could be Hashing. Use a hash function to convert long string to short string. In hashing, that may be collisions (2 long URLs map to same short URL) and we need a unique short URL for every long URL so that we can access long URL back.
A Better Solution is to use the integer id stored in database and convert the integer to character string that is at most 6 characters long. This problem can basically seen as a base conversion problem where we have a 10 digit input number and we want to convert it into a 6 character long string.
Below is one important observation about possible characters in URL.
A URL character can be one of the following:
A lower case alphabet [‘a’ to ‘z’], total 26 characters
An upper case alphabet [‘A’ to ‘Z’], total 26 characters
A digit [‘0’ to ‘9’], total 10 characters
There are total 26 + 26 + 10 = 62 possible characters.
So the task is to convert a decimal number to base 62 number.
To get the original long URL, we need to get URL id in database. The id can be obtained using base 62 to decimal conversion.
Here is some code in ruby that implements a Base62 encoder and decoder:
I recently had to calculate the distance between a large number of co-ordinates. I could have used one of the many Ruby Gems that are available but due to business limitations had to develop the code myself. After some research I came across the haversine formula.
The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical triangles.
You can read the full details on the maths here. For those who just want the code here is the implemenation I came up with:
moduleGPSclassDistanceRAD_PER_DEG=Math::PI/180GREAT_CIRCLE_RADIUS_MILES=3956GREAT_CIRCLE_RADIUS_KILOMETERS=6371# some algorithms use 6367GREAT_CIRCLE_RADIUS_FEET=GREAT_CIRCLE_RADIUS_MILES*5280GREAT_CIRCLE_RADIUS_METERS=GREAT_CIRCLE_RADIUS_KILOMETERS*1000GREAT_CIRCLE_RADIUS_NAUTICAL_MILES=GREAT_CIRCLE_RADIUS_MILES/1.15078attr_accessor:great_circle_distanceattr_accessor:point1attr_accessor:point2definitialize(great_circle_distance=0)@great_circle_distance=great_circle_distance@point1=[0,0]@point2=[0,0]enddefto_milescalculate@great_circle_distance*GREAT_CIRCLE_RADIUS_MILESendalias_method:to_mi,:to_milesdefto_kilometerscalculate@great_circle_distance*GREAT_CIRCLE_RADIUS_KILOMETERSendalias_method:to_km,:to_kilometersdefto_meterscalculate@great_circle_distance*GREAT_CIRCLE_RADIUS_METERSendalias_method:to_m,:to_metersdefto_feetcalculate@great_circle_distance*GREAT_CIRCLE_RADIUS_FEETendalias_method:to_ft,:to_feetdefto_nautical_milescalculate@great_circle_distance*GREAT_CIRCLE_RADIUS_NAUTICAL_MILESendalias_method:to_nm,:to_nautical_milesprivate# Radians per degreedefrpd(num)num*RAD_PER_DEGenddefcalculate# Accept two arrays of points in addition to four coordinatesifpoint1.is_a?(Array)&&point2.is_a?(Array)lat2,lon2=point2lat1,lon1=point1elsifraiseArgumentErrorenddlon=lon2-lon1dlat=lat2-lat1a=(Math.sin(rpd(dlat)/2))**2+Math.cos(rpd(lat1))*Math.cos((rpd(lat2)))*(Math.sin(rpd(dlon)/2))**2@great_circle_distance=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))endendend
U.S. senators want people to hack the Department of Homeland Security. On Thursday, Senators Maggie Hassan, a Democrat and Republican Rob Portman introduced the Hack DHS Act to establish a federal bug bounty program in the DHS... It would be modeled off the Department of Defense efforts, including Hack the Pentagon, the first program of its kind in the federal government. Launched a year ago, Hack the Pentagon paved the way for more recent bug bounty events including Hack the Army and Hack the Air Force...
The Hack the DHS Act establishes a framework for bug bounties, including establishing "mission-critical" systems that aren't allowed to be hacked, and making sure researchers who find bugs in DHS don't get prosecuted under the Computer Fraud and Abuse Act. "It's better to find vulnerabilities through someone you have engaged with and vetted," said Jeff Greene, the director of government affairs and policy at security firm Symantec. "In an era of constrained budgets, it's a cost-effective way of identifying vulnerabilities"... If passed, it would be among the first non-military bug bounty programs in the public sector.