Categories
Python

Python: Encoding and Decoding Strings as Bytes

It’s simple!

Python IDE Entries:

It’s quite interesting. Last night, when I was using urlopen to access the TinyURL API, I found that the data was being returned as bytes. I had to decode it.

Categories
Python

Python Program To Generate TinyURLs

In a previous post of mine, I have published a php class to generate short urls using the TinyURL API. Here is a simple Python program to generate tiny URLs directly from your desktop.

The File: (Python 3)

How To use?
Save the file as “tinyurl.py”.
You have to pass a target URL as the only argument to the program. The short url will be printed out on your screen.
Type the following command on your cmd or shell to execute the program.

tinyurl.py https://masnun.com

The short url will be printed out on the screen (shell or cmd).

If you don’t know or like the idea of copying text from the command line interface, simply redirect the output of the program to a text file:

tinyurl.py https://masnun.com > url.txt

The above code will fetch the short URL and put it into the file named “url.txt” 🙂 I use this method.

To Do: I am thinking of adding the functionality to create multiple short url from a single execution.

Categories
PHP

php 6.0.0-dev: cURL doesn’t work

I was using php 6.0.0-dev for CLI uses. Today while experimenting with a class that makes extensive use of the famous cURL, I found a wierd situation. cURL was not functioning properly. Then I switched to php 5.2.6 and cURL was fine once again !!

Is it a bug in the cURL functionality of php6 or just a bug with the specific installation I was using ? I don’t know 🙁