import random
secret_number = random.randint(1, 99)
import sys
print(
"""
+============================+
| Welcome to Robert's Hurkle.|
| Guess the Secret Number. |
+============================+
""")
print ("The Secret Number is " + str(secret_number))
MyGuess = 0
guesses = 0
while MyGuess != secret_number:
MyGuess = int(input("Enter your secret number guess: "))
if MyGuess > secret_number: hint="Lower"
else: hint= "Higher"
if MyGuess == secret_number:
print ("Congratulations. You guessed correctly.")
print ("The number is " + str(MyGuess))
print ("it took you " + str(guesses+1) + " guesses to get it right.")
print()
elif MyGuess == 0:
print ("The number was " + str(secret_number) + ".")
sys.exit()
else:
print ("Wrong. " + str(MyGuess) + " is not the number.")
print ("Enter ZERO to give up.")
guesses += 1
print ("So far, you guessed " + str(guesses) + " times.")
print ("The secret number is " + hint)
print()
Author: Britt
Python – Disposal Evaluation
# Disposal Evaluation Program
def get_input(prompt):
"""Utility function to get user input with validation."""
while True:
try:
value = input(prompt)
# Accepting numerical values for certain prompts
return float(value) if prompt.startswith(("How long", "cash value", "size", "emotional value")) else value
except ValueError:
print("Please enter a valid input.")
def evaluate_item(use_time, next_use_time, cash_value, size, emotional_value):
"""Evaluates the item's value based on the input factors."""
score = 0
# Evaluation Criteria
score = 25 - use_time
score += (25 - next_use_time)
score += int(cash_value / 100)
score += (25 - size)
score += emotional_value
return score
def main():
print("Disposal Evaluation Program")
while True:
# Gather information from the user
use_time = get_input("How long has it been (in months) since you have used this item? ")
next_use_time = get_input("How long (in months) until you think you will use this item? ")
cash_value = get_input("What is the cash value of the item? ")
size = get_input("How much size (in cubic feet) does the item take up? ")
emotional_value = get_input("Rate the emotional value of the item from 1 to 50. ")
# Convert relevant inputs to float
cash_value = float(cash_value)
size = float(size)
emotional_value = float(emotional_value)
# Evaluate the item
score = evaluate_item(use_time, next_use_time, cash_value, size, emotional_value)
# Display the score and results
print(f"\nFinal score for the item: {int(score)}")
# Display results
if score > 100:
print("\nRecommendation: Keep the item.")
elif score < 80:
print("\nRecommendation: Dispose of the item.")
else:
print("\nRecommendation: This is something you should think about.")
# Ask the user if they want to evaluate another item or quit
another_item = input("\nWould you like to evaluate another item? (Y/N): ").strip().lower()
if another_item != 'y':
print("Thank you for using the Disposal Evaluation Program. Goodbye!")
break
if __name__ == "__main__":
main()
Python – QR Code Generator
import qrcode
from PIL import Image
# This QR Code Generator was developed by Robert Andrews, Beatitudes Resident.
xx = input("Enter URL: ")
xName = input("Enter QR Code File Name: ")
# Website URL
website_url = xx
# ERROR TRAP URL
xTRAP = xx[0:4]
if xTRAP == "http":
website_url = xx
else:
website_url = "http://" + xx
# ERROR TRAP FILENAME
if xName.endswith(".JPG") or xName.endswith(".PNG"):
xName = xName
else:
xName = xName+".JPG"
# Create QR code instance
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# Add website URL to QR code
qr.add_data(website_url)
qr.make(fit=True)
# Create an image from the QR code with dark blue color
img = qr.make_image(fill_color="#295BB3", back_color="white") # Use hex code for dark blue
# Open the logo image
logo = Image.open("LOGO.png")
logo = logo.resize((59, 59)) # Resize the logo image if necessary
# Get the position to paste the logo in the center of the QR code image
position = ((img.size[0] - logo.size[0]) // 2, (img.size[1] - logo.size[1]) // 2)
# Paste the logo onto the QR code image
img.paste(logo, position)
# Save the QR code image with the logo
img.save(xName)
print ("QR Code is on the desktop under QR Code Generator.")
Python – Pong Game
Can't find it
Python – Temperature Converter
import sys
MyExit = "Exit"
while MyExit != "X":
MyTitle = "Temperature Conversion Program"
MyInstructions = "Enter C if convertion from C to F.\n"
MyInstructions = MyInstructions + "Enter F if converting from F to C\n"
MyInstructions = MyInstructions + "Enter X to Exit"
print ("\n",MyTitle,"\n")
print (MyInstructions+"\n")
MyPath=input("Enter C or F: ")
if MyPath == "C":
StartTemp=int(input("Enter temperature: "))
MyOutput = (StartTemp*1.8)+32
ResultPath="F"
elif MyPath == "F":
StartTemp=int(input("Enter temperature: "))
MyOutput = (StartTemp-32) * (5/9)
ResultPath="C"
else:
sys.exit()
print(StartTemp, MyPath, "is the same as",MyOutput,ResultPath)
Python – Stopwatch
import tkinter as tk
from tkinter import simpledialog
class TimerApp:
def __init__(self, root):
self.root = root
self.root.title("Timer")
self.count = 0.0 # Use float to accommodate tenths of a second
self.is_running = False
self.is_counting_up = True
self.label = tk.Label(root, text=str(self.count), font=("Helvetica", 48)) # Increased font size to 48
self.label.pack(pady=20)
self.up_button = tk.Button(root, text="Count Up", command=self.start_counting_up, font=("Helvetica", 18))
self.up_button.pack(side=tk.LEFT, padx=20)
self.down_button = tk.Button(root, text="Count Down", command=self.start_counting_down, font=("Helvetica", 18))
self.down_button.pack(side=tk.RIGHT, padx=20)
self.stop_button = tk.Button(root, text="Stop", command=self.stop_timer, font=("Helvetica", 18))
self.stop_button.pack(pady=20)
self.update_timer()
def start_counting_up(self):
self.is_counting_up = True
self.is_running = True
self.count = 0.0 # Reset count
self.label.config(text=str(self.count))
def start_counting_down(self):
self.is_counting_up = False
self.is_running = True
# Ask user for countdown time in seconds
countdown_time = simpledialog.askfloat("Input", "Set countdown time in seconds:", minvalue=0.1)
if countdown_time is not None:
self.count = countdown_time # Set countdown start
self.label.config(text=str(self.count))
def stop_timer(self):
self.is_running = False
def update_timer(self):
if self.is_running:
if self.is_counting_up:
self.count += 0.1 # Increment by tenths of a second
else:
self.count -= 0.1 # Decrement by tenths of a second
# Ensure count doesn't go below 0 for countdown
if not self.is_counting_up and self.count < 0:
self.count = 0
self.label.config(text=f"{self.count:.1f}") # Format to one decimal place
self.root.after(100, self.update_timer) # Update every 100 milliseconds
if __name__ == "__main__":
root = tk.Tk()
app = TimerApp(root)
root.mainloop()
Feb 2022 – Master Page
This page is just for me. Perhaps after I am gone, my wife will go there. This link was put here for her. Cynthia, CLICK HERE.
Domain Management – Web Host Management Page
- APPS
- Ariz.com :: Web page for What’s Near Here app – Redirects on NET and ORG
- EncryptaMail :: This will be the app sales page – route mail through internal mail server
- Mavira :: This will be my eMail encryption page.
- SALES PORTALS
- Essential Widgets :: This will be my sales portal for all apps
- Jessit :: This will be my sales portal for all books
- Meteors.net :: This will be Valley Web Services
- PRODUCTS FOR SALE
- Cooking 4 2 :: Cookbooks for couples and single parents
- Cook 20 :: Twenty Minute Meals
- GrandpaCooks.com :: Change from recipes to Cook Book Sales with examples
- BeatitudesCampus.net :: iPhone and Android interface for Beatitudes network products
- PERSONAL USE PAGES
- RobtAndr :: Currently HostGator main user
- r0b3rt.com
- Cielle.net
- RobertAndrews.net and RobertAndrews.org
- CharlesAndrews.org
- RobtCyn.com
- RobtAn ???
- XML3.com
- CUSTOMER SITES TO MAINTAIN
- Central Barber
- Cheese n Stuff Deli
- Hand Spinning Cotton
- Phx Blue Fin
- Uncle Tonys NY Pizza (going out ?)
- Peoria Greekfest – simple redirect
- ACTIVITIES TO CONTINUE AT BEATITUDES
- Playing LIVE music in the Bistro on (select a day)
- Produce video “Specials” – Maybe one per month
Consider letting these lapse:
- Tutavo.com
- DigitHall.com
- DuneChronicles.com
- BCResident.net
- BCBulletinBoard.com and .net
- Britt Reid
- UCC SW
- AZ Class
- Recipe Box
- SciFaction
- VidHist and VidHistory
Drive Maps
Terminal: Sudo rm -r [ DRAG HERE ] – – – – PW: 7844aa
| Drive | LIVE Contents Summary | BACKUP Summary |
| Dropbox | Live and Very Active | C |
| A – 5 TB | Live < 5 years | C |
| B – 8 TB | Live 5-10 years | D |
| F – 1 TB | Live Audio Files E did not power up |
P – curr other – 1 TB |
| √ G – 2 TB H? | Live Memorabilia | √ K – 2 TB |
| √ J Marshall | All Archives over 10 years old | none – S ? Thumb ? |
| S | Perhaps Archives over 20 years old – see cooking | none – ? Thumb ? |
| M N G-Raid | Both are FAILING | X |
| √ N Marshall |
|
• T Back • U Back • V Back •W Video A-E • X Video F-L • Y Video M-R • Z Video S-Z |
| R – 500 GB | Installation Files | none ?!?! H or K (2)? |
| S | Cooking Pics, AV, Books, etc | none ?!? |
| Evaluate Drive E for old non-critical non-memorabilia backups | ||
| x | x | x |
Directory Structure within most directories
- Keep very active files in Dropbox ACTIVE folder
- Directories
- ACTIVE
- Business
- Jessit
- VidHist
- Valley Web – Non web files
- Cooking
- Finances
- Health
- House and Home
- 7844
- Vacation
- WORKING – Currently being edited
- Business
- FAIRLY STATIC
- Memorabilia
- Vacation
- Family
- Library
- Entertainment
- Valley Web Snapshots
- Memorabilia
- RBA ACTIVE
- Valley Web Services – Backups and Images
- ACTIVE
-
- YEARLY GROUPS and SUB GROUPS
- 1900s (As many as 20 sub directories)
- 2000 – 2008 (9 sub directories)
- 2009 – 2014 (6 sub directories)
- 2015 – 2017 (3 sub directories)
- 2018 – 2019 (2 sub directories)
- YEARLY GROUPS and SUB GROUPS
ACTIONS CURRENTLY IN OPERATION
| Drive | Action | Notes about Action | Done |
| Recipe Box | Dropbox Public | ||
| Health Records | Drop/Active/HH/Health | ||
| Vault – Entertainment | Standardize | ||
| Rovey Applications and Appeals | Standardize | ||
| Prepare Financial Summary for Meeting | Standardize | ||
| B LIVE – Cooking | Standardize | ||
| B Mirror – Dropbox | Standardize | ||
|
Combine Dupe Directories |
|||
|
® Finish Dropbox organization |
|||
How it works
When you click on a link like that, an HTTP request is send to their server with the full URL, like http://bit.ly/duSk8wK (links to this question). They read the path part (here duSk8wK), which maps to their database. In the database, they find a description (sometimes), your name (sometimes) and the real URL. Then they issue a redirect, which is a HTTP 302 response and the target URL in the header.
This direct redirect is important. If you were to use files or first load HTML and then redirect, the browser would add TinyUrl to the history, which is not what you want. Also, the site that is redirected to will see the referrer (the site that you originally come from) as being the site the TinyUrl link is on (i.e., twitter.com, your own site, wherever the link is). This is just as important, so that site owners can see where people are coming from. This too, would not work if a page gets loaded that redirects.
PS: there are more types of redirect. HTTP 301 means: redirect permanent. If that would happen, the browser will not request the bit.ly or TinyUrl site anymore and those sites want to count the hits. That’s why HTTP 302 is used, which is a temporary redirect. The browser will ask TinyUrl.com or bit.ly each time again, which makes it possible to count the hits for you (some tiny url services offer this).
COMMENTS:
Actually I think, Bit.ly uses HTTP 301 instead of 302 (the last I heard)
Since bit.ly won’t let you change where one of their URLs points to, 301 makes sense. No need to remember the bit.ly version and recheck it.
it is indeed HTTP 301 that is used, however, with a timestamp. This turns it into a Moved not Moved Permanently. This is a subtle difference. By adding the timestamp, the browser considers it should check whether the resource is changed or not when this timeout it reached. Others, like is.gd, use a normal 301 Moved Permanently and the browser doesn’t need to re-check (but often will). Finally, services like url4.eu do not redirect at all, but show you an advertisement first. With the 301 the services can still count unique visitors, but not all hits.
URL How-to
Others have answered how the redirects work but you should also know how they generate their tiny urls. You’ll mistakenly hear that they create a hash of the URL in order to generate that unique code for the shortened URL. This is incorrect in most cases, they aren’t using a hashing algorithm (where you could potentially have collisions).
Most of the popular URL shortening services simply take the ID in the database of the URL and then convert it to either Base 36 [a-z0-9] (case insensitive) or Base 62 (case sensitive).
A simplified example of a TinyURL Database Table:
ID URL VisitCount
1 www.google.com 26
2 www.stackoverflow.com 2048
3 www.reddit.com 64
...
20103 www.digg.com 201
20104 www.4chan.com 20
Web Frameworks that allow flexible routing make handling the incoming URL’s really easy (Ruby, ASP.NET MVC, etc).
So, on your webserver you might have a route action that looks like (pseudo code):
Route: www.mytinyurl.com/{UrlID}
Route Action: RouteURL(UrlID);
Which routes any incoming request to your server that has any text after your domain www.mytinyurl.com to your associated method, RouteURL. It supplies the text that is passed in after the forward slash in your URL to that method.
So, lets say you requested: www.mytinyurl.com/fif
“fif” would then be passed to your method, RouteURL(String UrlID). RouteURL would then convert “fif” to its base10 equivalent, 20103, and a database request will be made to redirect to whatever URL is stored under the ID 20103 (in this case, www.digg.com). You would also increase the visit count for Digg by one before redirecting to the correct URL.
This is a really simplified example but you should be able to get the general idea.
-
Good additions, esp. the part on the encoding. – Abel Oct 13 ’09 at 21:00
-
1really its that easy. I hate when I don’t think of the simple things. – Nathan Feger Dec 19 ’09 at 0:48
-
1
-
10Thanks for the nice explanation. So what happens when someone tries to create a short URL for an already existing long URL? Do they perform a full text search on the database? I do not think so as it will be too much time consuming. Hash or message digest based approach looks more practical. – Piyush Kansal Oct 2 ’13 at 7:13
-
-
@PiyushKansal you could use the hash internally to do a
O(1)lookup to find duplicates; and then route the existing tiny URL for that, or could choose to generate a new one. As far as I can tell,goo.glreuses the tiny urls for the same URL; try this on your end for this page: Do you get this >>goo.gl/8gVb8X? – Kingz Jun 4 ’18 at 16:29 -
As an extension to @A Salcedo answer:
Some url shortening services (Tinyarro.ws) go to extreme by using Unicode (UTF-8) to encode characters in shortened url – which allows higher amount of websites before having to add additional symbol. Since most of UTF-8 is accepted for use ((IRI) RFC 3987 handled by most browsers) that bumps from
62sites per symbol to ~1,112,064.To put in perspective one can encode 1.2366863e+12 sites with 2 symbols (
1,112,064*1,112,064) – in November 2009, shortened links onbit.lywere accessed2.1billion times (Around that time, bit.ly and TinyURL were the most widely used URL-shortening services.) which is ~600 times less than you can fit in just 2 symbols, so for full duration of existence of all url shortening services it should last another 20 years minimum till adding third symbol.