Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 60c5b506d2f8ab2fc4a81cfebea706a7f774427a 0 parents
@veganstraightedge authored
23 .autotest
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
6 History.txt
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2010-06-11
+
+* 1 major enhancement
+
+ * Birthday!
+
8 Manifest.txt
@@ -0,0 +1,8 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/newbase60
+lib/newbase60.rb
+test/test_newbase60.rb
37 README.txt
@@ -0,0 +1,37 @@
+= newbase60
+
+* http://github.com/veganstraightedge/NewBase60
+
+== DESCRIPTION:
+
+Handy Conversion Sexagesimal (base 60) for Short URLs
+Cuts out ambiguous characters like:
+l : lowercase l (looks like a 1 : one)
+I : capital I (looks like a 1 : one)
+O : capital O (looks like a 0 : zero)
+
+== FEATURES/PROBLEMS:
+
+* Converts Base10 (like 147124) to Base60 (like fs4)
+* Converts Base60 (like fs4) to Base60 (like 147124)
+* Converts Base60 (like fs4) to a Time object (Mon Oct 23 23:00:00 -0800 2372)
+
+== SYNOPSIS:
+
+n = Newbase60.new("3x0")
+puts n.to_i # => 14220
+puts n.to_i.to_sxg # => "3x0"
+puts n.to_time # => Sat Jan 03 23:00:00 -0800 1970
+puts n.to_time.to_sxg # => 3
+
+* Note: I know I'm losing some resolution in the time conversion. I'm working on it.
+
+== INSTALL:
+
+* sudo gem install newbase60
+
+== LICENSE:
+
+PUBLIC DOMAIN.
+Your heart is as free as the air you breathe.
+The ground you stand on is liberated territory.
6 Rakefile
@@ -0,0 +1,6 @@
+require 'rubygems'
+require 'hoe'
+
+Hoe.spec 'newbase60' do
+ developer('Shane Becker', 'veganstraightedge@example.com')
+end
1  bin/newbase60
@@ -0,0 +1 @@
+#!/usr/bin/env ruby
97 lib/newbase60.rb
@@ -0,0 +1,97 @@
+class Newbase60
+ require "time"
+ VERSION = '0.0.1'
+
+ def initialize(str)
+ @base_60 = str
+ end
+
+ # converts NewBase60 into base10 integer
+ def to_i
+ num = 0
+
+ @base_60.length.times do |index| # iterate over each letter
+ char = @base_60[index] # grab the ascii value of the current letter
+
+ if (48..57).include?(char)
+ char -= 48
+ elsif (65..72).include?(char)
+ char -= 55
+ elsif (char == 73 || char == 108) # typo capital I, lowercase l to 1
+ char = 1
+ elsif (74..78).include?(char)
+ char -= 56
+ elsif (char == 79) # error correct typo capital O to 0
+ char = 0
+ elsif (80..90).include?(char)
+ char -= 57
+ elsif (char==95) # underscore
+ char = 34
+ elsif (97..107).include?(char)
+ char -= 62
+ elsif (109..122).include?(char)
+ char -= 63
+ else
+ char = 0 # treat all other noise as 0
+ end
+
+ num = 60 * num + char
+ end
+
+ num
+
+ end
+
+ # converts NewBase60 characters into a Time object
+ def to_time
+ # days since epoch * seconds * minutes * hours + timezone
+ Time.at(@base_60.to_i * 60 * 60 * 24 + Time.now.gmtoff.abs)
+ end
+end
+
+
+class Integer
+ # converts base10 integers into NewBase60
+ def to_sxg
+ num = self
+
+ sxg = ""
+ vocabulary = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"
+
+ return 0 if num.nil? || num.zero?
+
+ while num > 0 do
+ mod = num % 60
+ sxg = "#{vocabulary[mod,1]}#{sxg}"
+ num = (num - mod) / 60
+ end
+
+ sxg
+ end
+
+ # converts base10 integers into NewBase60 padding with leading zeroes
+ def to_sxgf(padding)
+ num = self
+
+ str = num.to_sxg
+
+ padding = 1 if padding.nil?
+ padding -= str.length
+
+ while padding > 0
+ str = "0#{str}"
+ padding -= 1
+ end
+
+ str
+ end
+end
+
+# converts Time object into NewBase60
+class Time
+ def to_sxg
+ the_when = self + Time.now.gmtoff.abs
+ epoch_days = the_when.to_i / 60 / 60 / 24
+ epoch_days.to_sxg
+ end
+end
8 test/test_newbase60.rb
@@ -0,0 +1,8 @@
+require "test/unit"
+require "newbase60"
+
+class TestNewbase60 < Test::Unit::TestCase
+ def test_sanity
+ flunk "write tests or I will kneecap you"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.