Code Monkey home page Code Monkey logo

tinwhistle's Introduction

TinWhistle

TinWhistle is a simple URL shortener that uses the NewBase60 code as an essential part of the shortening algorithm. This blog post explains the algorithm in detail.

Usage

use TinWhistle;

my $short = make_short_from_url ("2010/05/26/t2"); # t45v2

# or, Tantek ordinal-days style:

my $short = make_short_from_url ("2010/146/t2"); # t45v2

# now expand to format of your choice

my $long_as_ord = short_to_long_as_ord ($short); # 2010/146/t2

my $long_as_ymd = short_to_long_as_ymd ($short); $ 2010/05/26/t2

NewBase60.pm

NewBase60.pm is a perl implementation Tantek Celik's new base 60, a "a base 60 numbering system using only ASCII numbers and letters", part of his cassis project. From the wiki page:

"I needed a way to compress numbers for a URL shortener I am building so I looked at existing work, decided I could do better with a better design methodology, and ended up deriving a base 60 numbering system from ASCII characters."

(How this technique is used in Tantek's URL shortener is described in this blog post).

Usage

use TinWhistle::NewBase60;

my $date = '1971-06-29';
my ( $y, $m, $d ) = split /-/, $date;

my $test_date = DateTime->new(
    year  => $y,
    month => $m,
    day   => $d,
);

# days *since* the epoch (1970-01-01)
my $epoch_days = date_to_num ($date); # 544

# that value encoded as sexagesimal
my $sxg_days = num_to_sxg ($epoch_days); # 94

# ordinal date per ISO8601 - YYYY-DDD
my $ord_date = date_to_ord ($date); # 2010-146

tinwhistle's People

Stargazers

Johannes Konst avatar Philipp Hanes avatar retornam avatar Th. Ma. avatar Robert Hall avatar Steve Ivy avatar

Watchers

Steve Ivy avatar  avatar

Forkers

wallrazer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.