• Stars
    star
    224
  • Rank 177,155 (Top 4 %)
  • Language
    Go
  • License
    Other
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create Youtube-Like IDs in Golang

basex

GoDoc Build Status

A native golang implementation for basex encoding which produces youtube like video id. There are only 10 digits to work with, so if you have a lot of records to maintain in the application, IDs tend to get very lengthy. uuidgen gives a very lengthy value. We can use characters from the alphabet as have them pose as additional numbers.

Or how to create IDs similar to YouTube e.g. yzNjIBEdyww

The alphabet has 26 characters. That's a lot more than 10 digits. If we also distinguish upper- and lowercase, and add digits to the bunch for the heck of it, we already have (26 x 2 + 10) 62 options we can use per position in the ID. Please note that this package only takes numeric inputs.

Note:

11/14/2015 version 0.1.0 has a breaking change which has new 'error' return type.
06/17/2016 version 0.1.1 has new functions EncodeInt and DecodeInt for processing big integers directly.

Usage

package main

import (
        "fmt"
        "math/big"
        "github.com/dineshappavoo/basex"
)

func main() {
        input := "123456789012345678901234567890"
        inputBigInt := big.NewInt(0)
        inputBigInt.SetString(input, 10)

        fmt.Println("Input : ", input)

        // encode and decode functions
        encoded, err := basex.Encode(input)
        if err != nil {
                fmt.Println(err)
        }
        fmt.Println("Encoded : ", encoded)

        decoded, err := basex.Decode(encoded)
        if err != nil {
                fmt.Println(err)
        }
        fmt.Println("Decoded : ", decoded)

        if input == decoded {
                fmt.Println("Passed! decoded value is the same as the original.")
        } else {
                fmt.Println("FAILED! decoded value is NOT the same as the original!!")
        }

        // encode int and decode int functions
        encodedInt, err := basex.EncodeInt(inputBigInt)
        if err != nil {
                fmt.Println(err)
        }
        fmt.Println("Encoded using big int: ", encodedInt)

        decodedInt, err := basex.DecodeInt(encodedInt)
        if err != nil {
                fmt.Println(err)
        }
        fmt.Println("Decoded using big int: ", decodedInt)

        if inputBigInt.Cmp(decodedInt) == 0 {
                fmt.Println("Passed! decoded int value is the same as the intput big int.")
        } else {
                fmt.Println("FAILED! decoded int value is NOT the same as the original!!")
        }
}

output looks like,

Input :  123456789012345678901234567890

Encoded :  2aYls9bkamJJSwhr0
Decoded :  123456789012345678901234567890
Passed! decoded value is the same as the original.

Encoded using big int:  2aYls9bkamJJSwhr0
Decoded using big int:  123456789012345678901234567890
Passed! decoded int value is the same as the intput big int.

Install

go get github.com/dineshappavoo/basex

Referrence

Project Contributor(s)

More Repositories

1

IMDBMovieBigData

A big data project to apply Hadoop map- reduce to derive some statistics from IMDB movie data.
Java
25
star
2

ctgi

Cracking The Google Interview
Java
19
star
3

bfs-shortestpath

Shortest path using BFS for unweighted graph
Java
10
star
4

Codility

Codility programming puzzles implementation in java
Java
7
star
5

CrimeDataAnalysis

Crime Data Analysis using apache Hadoop for UK police data
Java
6
star
6

ctci-go

Implementation of Cracking The Coding Interview in Go lang
Go
5
star
7

TopologicalSorting

Topological Sorting implementation for graphs in java
Java
3
star
8

maximum-clique

Maximum clique subgraph
Java
3
star
9

BellmanFordShortestPath

BellmanFord Shortest Path algorithm implementation in java
Java
2
star
10

RSSFeedsToMHPTelevisionFromStatServer

Interface to retrieve genesys stat server statistics as RSS feeds and display in MHP television
Java
2
star
11

virtdc

Statically place and schedule and dynamically scale and migrate Vitual Machines (VMs) to optimize resource utilization by using efficient VM algorithms while meeting the SLAs of users in cloud
Python
2
star
12

GraphMinimumSpanningTree

Implementation of graph minimum spanning tree algorithms
Java
1
star
13

BinarySearchTree

Implementation of Binary Search Tree without recursion in java
Java
1
star
14

monitoring-graph

Java api to monitor live data through graphs using jFrame
Java
1
star
15

MaximumFlow

Implementation of maximum flow algorithms in java
Java
1
star
16

UVAOnlineJudge

UVAOnlineJudge programming contest solutions
Java
1
star
17

SkipList

Implementation of SkipList data structure in java
Java
1
star