short-url

how to implement a short url like urls in twitter?

左心房为你撑大大i 提交于 2019-11-27 06:38:09
If there is a long url, i want to generate a short url like those in twitter, is there some way to implement in ruby? Thank you in advance. The easiest way is to: keep a database of all URLs when you insert a new URL into the database, find out the id of the auto-incrementing integer primary key. encode that integer into base 36 or 62 (digits + lowercase alpha or digits + mixed-case alpha). Voila! You have a short url! Encoding to base 36/decoding from base 36 is simple in Ruby: 12341235.to_s(36) #=> "7cik3" "7cik3".to_i(36) #=> 12341235 Encoding to base 62 is a bit tricker. Here's one way to

How to make unique short URL with Python?

青春壹個敷衍的年華 提交于 2019-11-27 05:05:47
问题 How can I make unique URL in Python a la http://imgur.com/gM19g or http://tumblr.com/xzh3bi25y When using uuid from python I get a very large one. I want something shorter for URLs. 回答1: Edit : Here, I wrote a module for you. Use it. http://code.activestate.com/recipes/576918/ Counting up from 1 will guarantee short, unique URLS. /1, /2, /3 ... etc. Adding uppercase and lowercase letters to your alphabet will give URLs like those in your question. And you're just counting in base-62 instead

PHP random URL names (short URL)

徘徊边缘 提交于 2019-11-26 19:39:01
问题 After using sites like JSFiddle I noticed that they auto generate a random and unique URL made up of various upper and lower case characters. We could benefit from this for our booking pages. How is it done? 回答1: This is not random, there based of the ID of your database record. How it works: basically you have a string that is unique but it can be decrypted to represent a number, you should look at it as a short encryption / decryption. You have a function that would take an unique ID and

What's the best way to create a short hash, similar to what tiny Url does?

喜欢而已 提交于 2019-11-26 18:58:15
问题 I'm currently using MD5 hashes but I would like to find something that will create a shorter hash that uses just [a-z][A-Z][0-9] . It only needs to be around 5-10 characters long. Is there something out there that already does this? Update 1: I like the CRC32 hash. Is there a clean way of calculating it in .NET ? Update 2: I'm using the CRC32 function from the link Joe provided. How can I convert the uInt into the characters defined above? 回答1: .NET string object has a GetHashCode() function.

How do short URLs services work?

风流意气都作罢 提交于 2019-11-26 14:59:21
问题 How do services like TinyURL or Metamark work? Do they simply associate the tiny URL key with a [virtual?] web page which merely provide an "HTTP redirect" to the original URL? or is there more "magic" to it ? [original wording] I often use URL shortening services like TinyURL, Metamark, and others, but every time I do, I wonder how these services work. Do they create a new file that will redirect to another page or do they use subdomains? 回答1: No, they don't use files. When you click on a

how to implement a short url like urls in twitter?

淺唱寂寞╮ 提交于 2019-11-26 12:07:30
问题 If there is a long url, i want to generate a short url like those in twitter, is there some way to implement in ruby? Thank you in advance. 回答1: The easiest way is to: keep a database of all URLs when you insert a new URL into the database, find out the id of the auto-incrementing integer primary key. encode that integer into base 36 or 62 (digits + lowercase alpha or digits + mixed-case alpha). Voila! You have a short url! Encoding to base 36/decoding from base 36 is simple in Ruby: 12341235