URL Shortener Algorithm - Remove Duplicates - algorithm

I've read multiple posts of SO regarding the topic.
How to code a URL shortener?
How do URL shortener calculate the URL key? How do they work?
PHP URL Shortening Algorithm
Every posts recommends to store the url in the database. It will return you the id, pass the id to a hash function, returning a tiny id.
My question is what will happen if the same url is requested to shorten it again? Bitly.com returns the same tiny url again for the same url.
What exactly should be the best way to go forward in order to ensure non-duplicate urls??

Related

Laravel route query get email address from query value instead of key

I have encountered an issue regarding Laravel 8 routes.
And I am unable to find a solution to this problem.
For example, I have this route format in Laravel:
$domain/password_reset?$email
Where it will look like this:
http://test-website.com/password_reset?test#gmail.com
I am aware that query parameters have ?key=value format. However in my case, the provided route format is what is expected (by client). Not the conventional key=value way. Also, the url link is clicked from an email. Wherein the link in the email uses the exact route format given (not url-encoded).
The sample request query that is fetched in the controller is as follows:
If you would notice, the email became a key (which is expected). And since it is a key, . has been changed to _. Instead of gmail.com it became gmail_com.
Would there be a better solution to get the exact email address from the url (not url-encoded) in this route format? Hopefully someone can help me with this. Thank you very much in advanced!
You should get the request query and parse it yourself:
[$path, $query] = explode('?',$request->fullUrl())
In the exemple above $query should hold everything after ? on the URL.
Alternativelly you can just get the key of the array you already have:
$email = array_keys($request->all())[0]

How to get share count of an url in Google Plus by passing only url

I want to get share count for a particular url from Google Plus.I tried by passing activity id in Activities: get to get share count. It is working fine but I want the same by passing only url alone.
In Facebook I passed only the Url as input in query url with input url and i got share counts for an url.Is there any ways available in Google Plus to get the share count by passing only url.
Referred site:
jonathanmoore/gist:2640302
Welcome to the world of Google APIs. The method in question
Activites.get
GET https://www.googleapis.com/plus/v1/activities/activityId
Takes a single parameter
activityId string The ID of the activity to get.
This is how this method works you must pass an activityId to it you can not pass a url. I can suggest running an Activies.list first in order to find the activity you seek.
You're best option is to use the Search API. Use the URL as the search term and page through all of the results until no more are found. You then have a number for how many times the URL has been shared publicly on Google+.

How to do Partial Response with Google URL Shortener API

Looking at the documentation on this API there is a page on performance to cut back the number of keys in the JSON dictionary returned. URL Shortener Performance Tips
Of the three dictionary keys returned in the insert request of this API, I am only interested in the shortened URL. The id key. Looking at the above documentation I would have expected this to work:
The POST request https://www.googleapis.com/urlshortener/v1/url?fields=id?key=YOUR-API-KEY
But with the fields=id added the request comes back invalid.
How do you set only a partial response for this API to only return the id key?
Turns out the comment from abraham steered me in the right direction on this problem. I was able to find the Try it tool option without OAuth and it worked also to my surprise. Looking at the request it generated I found that it was a syntax error on my part looking at the url given in my original question. It should be:
?fields=id&
not
?fields=id?

Pass encrypted email in url in nop commerece

I want to pass encrypted email in url,but its not working on server,
while it is working on localhost.
I check the encrypted email- It contains some specific character like + , =
all those url which contains + sign are not working on server. but it working on localhost.
for example-
url format - {controllername}/{methodname}/{encrypted email}/{bool}
working url-
www.test.com/home/index/IZoc1QJlukTro7XN4kTaRDoy7mPNS-14YjKeZsXeyt3XsL4tXbLUPQ==/false
not working url-
www.test.com/home/index/KV6UWqy5fN7FY+lZuMAQ5nvA0+X4f8sQyB0la+-bSawUPEY1TIHK-C2bUdZUBRA6/false
not working url gives error like
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Thoughts ?
You should pass it as an url encoded query string parameter and not as part of the route:
http://www.test.com/home/index?email=IZoc1QJlukTro7XN4kTaRDoy7mPNS-14YjKeZsXeyt3XsL4tXbLUPQ%3D%3D%2Ffalse
If you want to pass some string as part of the route you should ensure that it doesn't contain dangerous characters which is your case. Scott Hanselman wrote a nice and detailed blog post on the difficulties that you might encounter if you attempt to pass such strings as part of the route here: http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx
I will quote his conclusion if you don't want to go through the entire post:
After ALL this effort to get crazy stuff in the Request Path, it's
worth mentioning that simply keeping the values as a part of the Query
String (remember WAY back at the beginning of this post?) is easier,
cleaner, more flexible, and more secure.

Ajax results filtering and URL parameters

I am building a results filtering page using AJAX requests. I would like to reflect the filters in the URL. For example: for price_from I want to add ?price_from=VAL to the URL.
I have a backend that is capable of rendering the page with URL parameters.
After some googling I would a Backbone.router solution which has a hash fallback for the IE that does not support HTML5 history API.
I have a problem with setting a good philosophy of routes. I have a set of filtering parameters (price_from, price_to, color, ...) and I would like to attach each parameter to one route.
Is that possible to chain the routes to match for example: ?price_from=0&price_to=1&color=red? (the item order can change)
It means: call all the routes at the same time and keep the ie backwards compatibility?
Your best bet would be to have a query portion of the URL rather than using GET parameters to denote the search criteria. For example:
Push state: /search/query/price_from=0&price_to=1&color=red
Hash based: #search/query/price_from=0&price_to=1&color=red
Your backend would of course need to change a bit to be able to parse the new URL structure.

Resources