Ramblings of a software tester…developer…tester…

Ramblings of a tester who is a programmer who is a tester who is a developer…

Small Python GUI to Calculate Lever Distance

Hi folks.

Just a small script which calculates your distance from a lever focal point if you know your weight, the object’s weight and the object’s and the distance the object has from the focal point of the lever.

Like this:

slide0001_image007

This script will give you D1. And this is how it will look like in doing so:

Screen Shot 2015-04-10 at 15.03.02

So, in order for me (77kg) to lift an object of 80kg which is on a, by default, 1 meter long lever, I have to stand back ~1.03meters. Which is totally cool, right?

Here is the code:

from Tkinter import *
import ttk
 
def calculate(*args):
    try:
        your_weight_value = float(your_weight.get())
        object_weight_value = float(object_weight.get())
        object_distance_value = float(object_distance.get())
        your_distance.set((object_weight_value * object_distance_value) / your_weight_value)
    except ValueError:
        pass
 
root = Tk()
root.title("Lever distance counter")
 
mainframe = ttk.Frame(root, padding="4 4 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
 
your_weight = StringVar()
object_weight = StringVar()
object_distance = StringVar()
your_distance = StringVar()
 
object_distance.set("1")
 
your_weight_entry = ttk.Entry(mainframe, width=7, textvariable=your_weight)
your_weight_entry.grid(column=2, row=1, sticky=(W, E))
object_weight_entry = ttk.Entry(mainframe, width=7, textvariable=object_weight)
object_weight_entry.grid(column=2, row=2, sticky=(W, E))
object_distance_entry = ttk.Entry(mainframe, width=7, textvariable=object_distance)
object_distance_entry.grid(column=2, row=4, sticky=(W, E))
 
 
ttk.Label(mainframe, textvariable=your_distance).grid(column=2, row=3, sticky=(W, E))
ttk.Label(mainframe, text="Your weight").grid(column=1, row=1, sticky=W)
ttk.Label(mainframe, text="Object weight").grid(column=1, row=2, sticky=W)
ttk.Label(mainframe, text="Object Distance").grid(column=1, row=3, sticky=W)
ttk.Label(mainframe, text="Your Distance").grid(column=1, row=4, sticky=W)
 
ttk.Label(mainframe, text="kg").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="kg").grid(column=3, row=2, sticky=W)
ttk.Label(mainframe, text="m").grid(column=3, row=3, sticky=W)
ttk.Label(mainframe, text="m").grid(column=3, row=4, sticky=W)
 
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=5, sticky=W)
 
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
 
your_weight_entry.focus()
root.bind('', calculate)
 
root.mainloop()

Please enjoy, and feel free to alter in any way. I’m using Tkinter and a grid layout which I find very easy to work with.

Thanks for reading,
Gergely.

Python and my Math commitment

Let’s talk about plans. It’s good to have one. For example, I have a plan for this year.

I kind of like math. So, I have this book:

matek

It’s 1400 pages long and basically, has everything in it. It’s a rather exhaustive book. Hence, my plan is to finish the book by the end of 2015 and write a couple of python scripts that calculate something interesting.

For example, Newton’s law of cooling how I learned it is:

Where k => a material’s surface based constant. Tzero => initial temperature. T => target temperature. K => Environment’s temperature.

A simple python script for this:

# Calculating Newton's law of Cooling
from __future__ import division
import sys
from math import log
 
def calculation(k, Tz, T, K):
	res = (Tz - K)/(T - K)
	return k * (log(res, 2.5))
 
k = sys.argv[1]
Tz = sys.argv[2]
T = sys.argv[3]
K = sys.argv[4]
 
print("Calculating aproximate temperature for given parameters: k=%s, Tz=%sC, T=%sC, K=%sC" % (k, Tz, T, K))
 
print(calculation(float(k), float(Tz), float(T), float(K)))

Enjoy.

And as always,
Thanks for reading!

Why Lock Picking is like Testing

 

Not a great many people know that I’m actually into Lock Picking as a hobby. This will not be a tutorial on how to do it, or I won’t really talk about how I do it; I would like to write about something completely different. So if you came here for that, here are a few very good resources:

http://www.lockpicking101.com/ - Tutorials
http://www.ukbumpkeys.com/collections/lock-picking – Tools ( UK )
http://www.reddit.com/r/lockpicking/ – Reddit

For my post, click on…

Continue reading →

Building an RPG App with Meteor – Part One – The struggle

In my previous post, I was getting ready to enjoy some time with the JavaScript web framework Meteor.

This time I would like to bring it to a bit of overdrive. See, how re-factoring works on a larger scale model with multiple pages. And how it can organize assets, such as, images, multiple CSS, some plugins, you know, ordinary web stuff.

Let’s dive in.

Continue reading →