CGI Programming using Tinypy

May 28, 2020

Just this afternoon, I tried how CGI works in Tinypy using my Microcore Linux. Unfornately, I did this manually 😦 I learned how CGI works internally without using a CGI module or any libraries. Since there’s no module related to CGI in Tinypy, the challenge is how will I get the values from the HTML form and parse it. Luckily, I’m using Linux 😀 I have nothing to say. Just observe and study the screenshots.

1. Entered the values for the 2 fields (name and age).

p1

2. Extracted the QUERY_STRING line from CGI environment variables.

p2

3. Removed the %20 from the string.

p3

4. Removed the “QUERY_STRING=” substring, for me to easily do the parsing process.

p4

5. Separated the 2 fields.

p5

6. Yes! Successfully parsed the 2 fields 🙂

p6

7. Here’s my code.

p7

I haven’t tested some possibilities. Anyway, through this I can still improve and discover more things about CGI programming using Tinypy by making functions and modules (from scratch). Hope you learn something. ‘Til next time! 🙂

Note:
Just ignore the value for the age field and the click text of the button (I’m using Elinks browser and a CLI environment OS) as seen on the screenshots. Thanks!


Learn by Example: Lists

May 28, 2020

a=["pedro","juan"]
for b in a:
  print(b)

print("\n")

a.append("maria")
for b in a:
  print(b)

print("\n")

a.extend(["kiko","totoy"])
for b in a:
  print(b)

print("\n")

a.sort()
for b in a:
  print(b)

print("\n")

for b in a[1:4]:
  print(b)

print("\n")

print(a.index("maria"))

print("\n")

a.pop()
for b in a:
  print(b)

print(len(a))
print(a.index("kiko"))

x=a
print(x[1])


Learn By Example : While and For Loops

May 21, 2020
print("WHILE LOOP")

a=1
while a<=5:
  print(a)
  a=a+1

print("\n")

a=10
while a>=2:
  print(a)
  a-=2

print("\n")

print("FOR LOOP")
for a in [1,2,3,4,5]:
  print(a)

print("\n")

for a in range(10,0,-2):
  print(a)

print("\n")

for a in "tinypy":
  print(a)

print("\n")

for a in ["tinypy","programming","language"]:
  print(a)

print("\n")

for a in range(1,6):
  if a==3:
    break
  print(a)

print("\n")

for a in range(1,6):
  if a==3:
    continue
  print(a)

Learn By Example : If Statement

May 21, 2020
a=5
if a<5:
      print("Yes! a is less than 5")
else:
      print("No! a is not less 5")

print("\n")

a=10
if a==5:
      print("Yes! a is equal to 5")
elif a==10:
      print("Yes! a is equal to 10")
else:
      print("Sorry! a is not equal to 5 and 10")

Learn By Example: Operators (Part II)

May 21, 2020
print("Logical Operators\n")
print(0 and 0)
print(0 and 1)
print(1 and 0)
print(1 and 1)

print("\n")

print(0 or 0)
print(0 or 1)
print(1 or 0)
print(1 or 1)

print("\n")

print(not 0)
print(not 1)

print("\n")

a=78
if a>50 and a<75:
    print("FAILED")
elif a>=75 and a<=100:
    print("PASSED")
else:
    print("OUT OF RANGE!")

 


Learn By Example: Operators (Part I)

May 21, 2020
a=5
b=2
print(" a = 5\n a = 2")
print("ARITHMETIC OPERATORS")
print("a + b =",a+b)
print("a - b =",a-b)
print("a * b =",a*b)
print("a / b =",a/2)
print("a ** b",a**b)
print("a % b =",a%b)
print("\n")
print("RELATIONAL OPERATORS")
print("a < b =",a<b)
print("a > b =",a>b)
print("a == b =",a==b)
print("a != b =",a!=b)
print("a <= b =",a<=b)
print("a >= b =",a>=b)

Tinypy’s Shortcomings (Part I)

May 21, 2020

While exploring the classic version of Tinypy, I discovered the following:

  1. No Math FunctionsFor me, this is very important. I always introduce Math functions when I’m teaching Programming subject. The latest version of Tinypy has already a Math support but I intended to choose the classic version. Since my purpose is just to play with this tiny programming language and challenge myself to find an alternative way if I encounter something which is not (yet) supported . Of course, Python is my basis of comparison.
  2. No Input Command – If you want a value to be taken from the user, you need an input command. The only way to have this command, let’s say a trick, is to execute system command in order to access the internal command of the host operating system (mine is Puppy Linux). But let’s see, what would it look like or is it possible ???
  3. A Different Way of File HandlingHandling files like reading and writing, is a different approach in Tinypy compared to Python. But I found it simple and easy to use. I’ll show this in my next post.

Let’s Get Started – tinypy Programming

May 15, 2020

1. Download the classic version (our journey of challenges will start here 🙂 ). In my case, I chose .tgz format because I’m using Linux (Puppy).

tinypyhome

2. Extract the files.

extr

3. Execute the build script using Python.

build

4. Compress the executable which is the interpreter – tinypy (optional). Make sure you have UPX package installed. Disregard tinypy-sdl and vm executables.

upx

5. Test the interpreter by executing a simple code. Don’t be confused with the commands  that you will encounter like echo and cat.

test

Note:

  • If you’re using Windows operating system, just download the .zip file and extract its contents to your desired folder and you are all set. Remember, you must know how to use DOS via Command Prompt.
  • For the editor, you are free to use your own. In Windows, you can use Notepad or Notepad++. In Linux, like my case, I’m just using vi editor. Sometimes Geany editor which is available by default in my system.

Learning Python via Tinypy

May 15, 2020

These past few days, I’ve been playing with Tinypy ( a lightweight implementation of Python programming language), and discovering its features and limitations. I downloaded its classic version and compiled it. I used UPX to reduce its filesize to become 64K. Actually, almost the said size 🙂

Note: I’m using Puppy Linux OS (Xenialpup64). I used GCC with Python ( already installed by default) to produce the executable (interpreter). I also downloaded UPX-UCL package.

Why not Python?

I love lightweight programs. There were times that I attempted to learn Python since mid 2000s. But I’m loosing interest. So when I discovered Tinypy in the late 2000s, still… no interest 😀 I just kept it in my hardrive. Because of this quarantine period, I decided to give it a try. While learning it, I discovered it’s not 100% Python compatible, and lot of missing features and lack of modules. Though the creator said… “batteries not included” This caused me to ask myself if I’m going to continue learning it. But out of curiosity, I challenged myself to use it just to learn Python programming language and make its limitations to exercise my brain… hahahaha! I hope this journey will be fun and didactic because I couldn’t find tutorials and nice documentation designed or for beginners who want to learn Python programming language and for those who love lightweight programs like me 🙂 Good luck to us.

P.S.: I’m hoping to make a tutorial and posting codes about Tinypy in the next few days. So please standby 🙂