Jumat, 24 April 2020

SQL: statements

select * Customers: select or get every colomn from Customers table


Support 5 major command (S,U,D,I,W): Select, Update, Delete, Insert and Where.



select:
1. select column1, column2
from testing_table;

Rabu, 22 April 2020

CPP: Structure

Hi, CPP Programmer, welcome.

Structure vs array

Structure are different types value. Array are the same type value.

Structure consist of:
1. Structure variable
2. Structure tag
3. Structure member

Defining structure tag is optional.
Defining member is just like the defining variable.

Basic structure use are below:
#include <iostream>
#include <cstring>

using namespace std;

//1.Create the structure
struct Books{
char title[50];
char author[50];
char subject[50];
int book_id;
};



int main()
{
//2. Declare Book1 of type Books
struct Books Book1;
struct Books Book2;


//3. Define book Book1 specification
strcpy( Book1.title, "Learn C++ Programming");
strcpy( Book1.author, "Chand Miyan");
strcpy( Book1.subject, "C++ Programming");
Book1.book_id = 6495407;

//4. Define book Book2 specification
strcpy( Book1.title, "Telecom Billing");
strcpy( Book2.author, "Yakit Singha");
strcpy( Book2.subject, "Telecom");
Book2.book_id = 6495700;

//5. Print out Book1 info
cout << "Book 1 title: " << Book1.title << endl;
cout << "Book 1 author: " << Book1.author << endl;
cout << "Book 1 subject: " << Book1.subject << endl;
cout << "Book 1 book id: " << Book1.book_id << endl;

//6. Print
cout << "Book 1 title: " << Book1.title << endl;
cout << "Book 1 author: " << Book1.author << endl;
cout << "Book 1 subject: " << Book1.subject << endl;
cout << "Book 1 book id: " << Book1.book_id << endl;

}


Sending structure variable pointer to a function is almost the same as sending the struct variable to the function, the difference is: if you use structure variable pointer you use asterix and you need to declare a structure variable pointer.

Senin, 20 April 2020

SMALL BASIC: Printing stars

Hi, SMALL BASIC programmer, welcome.

In this tutorial, we will discus about variety of printing stars or asteriks.
1. Incremented stars
num_of_row = 10
For i = 0 To num_of_row
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor

Output:



2. Reversed incremented (decremented stars)
num_of_row = 10
For i = num_of_row To 0 Step -1
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor


 


Or, you can combine step 1 and step 2 into one program, like below:

num_of_row = 10
For round = 0 To 100
For i = 0 To num_of_row
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor
'TextWindow.WriteLine("Ok, sukses atas")

Program.delay(1000)
TextWindow.Clear()
For i = num_of_row To 0 Step -1
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor
Program.Delay(1000)
TextWindow.Clear()
EndFor


3. The decremented space
num_of_row = 10

For i = 1 To num_of_row
  For j = 1 To num_of_row - i 
    TextWindow.Write("  ")
  EndFor
  For k = 1 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor

Output:



4. The last the increment space
num_of_row = 10

For i = 1 To num_of_row 
  For j = 1 To i
    TextWindow.Write("  ")
  EndFor
  For k = 1 To num_of_row - i 'the rest of colomn
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor

Output:


5. The last, I don't know what to call this, but I call this cool stars
num_of_row = 10

For i = 1 To num_of_row
  For j = 1 To num_of_row - i 
    TextWindow.Write("  ")
  EndFor
  For k = 1 To num_of_row - 1
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor


6. I don't know what to call this, but I call this smooky stars
num_of_row = 10

For i = 1 To num_of_row
  For j = 1 To num_of_row - i 
    TextWindow.Write("  ")
  EndFor
  For k = 1 To j
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor

Minggu, 19 April 2020

SMALL BASIC: Algorithm to download webpage from the internet

Hello, SMALL Basic programmer, welcome.

You know that you can download webpage from the internet using SMALL basic?

This is the algorithm:
1. Ask user about the link of the web page.
2. Download the webpage.
3. Print out the result of the step 2 to the screen, or
4. Ask the user about the folder to save the file to (optionally).
5. Save it to a file on local directory (optionally).

This is the code:
'Ask
TextWindow.WriteLine("1. What page do you like to traverse? Use https:// or http:// ")
wp = TextWindow.Read()

'Get the webpage (wp)
'gwp = Network.GetWebPageContents("www.facebook.com/katakatalelucondanlucu")
'gwp = Network.GetWebPageContents("https://corona.jakarta.go.id/id")

gwp = Network.GetWebPageContents(wp)
TextWindow.Write(gwp)

TextWindow.WriteLine("2. (Optional) Tell me, what is the folder you want the web page saved to, for instance C:\Users\Totzfreelance\mywebpage.html:")
folder = TextWindow.Read()

File.WriteContents(folder,gwp)



   
  

SMALL BASIC: Printing out String a letter by a letter

a = "AAAAAA"
For i = 1 To Text.GetLength(a)
  TextWindow.WriteLine(text.GetSubText(a,i,1))
EndFor
  

Journey to find Gog and Magog

Fact
1. Gog and magog mentioned twice in the bible:



and will go out to deceive the nations in the four corners of the earth—Gog and Magogand to gather them for battle. In number they are like the sand on the seashore.







2. Ezekiel prophet was born 621 BC. Live in the ancient Israel.
3. Babylonian Kingdom exist in the time Ezekiel mentioned Gog and Magog

Jumat, 17 April 2020

IPv4 Activity

Basic:
1. Binary to decimal conversion activity
For example:
Enter the decimal of this binary: 00110111
Decimal is: 55

2. Decimal to binary conversion activity
For example:
Enter the binary of this decimal: 241
The binary is: 11110001

3. Given address/prefix 144.97.144.28/23
Determine:
1. Network address,
1.1. Last octet in binary
1.2 Last octet in decimal
1.3 Enter full address in decimal

2. Broadcast address
2.1 Last octet in binary
2.2 Last octet in decimal
2.3 Enter full address in decimal

3. First usable host address
3.1 Enter last octet in binary
3.2 Enter last octet in decimal
3.3 Enter the full address in decimal

4. Last Usable Host Address
4.1 Enter Last octet in binary
4.2 Enter Last octet in decimal
4.3 Enter full address in decimal





To remember this: NAHAMA.

NA = Network address
HA = Host Address
FHA = First host address
LHA = Last host address
HBA = Host Broadcast Address
SMA = Subnet Mask Address


1. Determining network address in decimal and in binary of a pair host address and mask address.

For example:
Host address: 10.158.30.81
Subnet Mask: 255.255.224.0


Solution: Anding both each host octet and respective subnetmask octet.

You can watch how the solution is in this video:




2. Determining the number of host

The solution is: (2 ^ number of bit 0 in the subnetmask in binary form) - 2.

You can watch how to solve it easily in this video:




3. Determining First Usable Host (FUH), Last Usable Host (LUH), Broadcast address in Decimal (BAD), and Next Network in decimal (NND)

First Usable Host (FUH)
1. Get all bit 0 in subnetmask in binary
2. Increment 1 to last octet.

Last Usable Host (LUH)
1. Get all the 0 bits of subnetmask in binary.
2. Make 1 all except the Less Significant bit (LSB).
3. Divide the bits of step 2 per octet.
4. Increment each octet value to each octet of network address in decimal.

Broadcast address in Decimal
1. Get all the 0 bits subnetmask in binary
2. Make 1 all
3. Divide the bits of step 2 per octet
4. Increment each octet value to each octet of network address in decimal.

Next Network in decimal (NND)
1.
2.
3.






Kamis, 16 April 2020

SMALL BASIC: File database searcher

Hi, SMALL BASIC programmer, welcome.

In this tutorial we will learned about how we can search multiple occurance of a keyword from a txt database.

'So the solution is read line per line
i = 1
TextWindow.WriteLine("Enter the file that you like to traverse? : ")
'file = TextWindow.Read()
file = "C:\Users\Totardo\Geneacology based on revelation.txt"
contain = File.ReadLine("C:\Users\Totardo\Geneacology based on revelation.txt",i)

While contain <> ""
  'TextWindow.WriteLine(contain)
  get_result = Text.GetIndexOf(contain,"Henokh")

  If get_result <> 0 Then
    TextWindow.WriteLine(contain)
  EndIf
  i = i + 1
  contain = File.ReadLine(file,i)

EndWhile

  

FFMPEG: extract video

We will use:
- to
- t
- ss

Three of them are can be used as input and output parameter.
All of them use time duration specification https://ffmpeg.org/ffmpeg-utils.html#time-duration-syntax

Extract only 1 minute:
ffmpeg -t 00:01:00 -i 2020-04-16 04-36-06.mkv output1.mkv

Extracting only 1 minute and 30 seconds:
ffmpeg -i 2020-04-16 04-36-06.mkv -t 00:01:30 output2.mkv

Extracting using -ss and -t (if you know the start time and stop time that you like):
ffmpeg -i 2020-04-16 04-36-06.mkv -to 00:01:30 output3.mkv

Extracting using -ss and -t



Senin, 13 April 2020

SMALL BASIC: Factorial Calculator

Hi, SMALL Basic programmer, welcome.

Did you know, we can also make factorial calculator using SMALL BASIC?

We will divide the code as:
1. Code with wrong result of  0!
2. Code that with correct result of 0!
So, you can see the difference.

Below is the code:

1. Code with wrong result of 0!
TextWindow.WriteLine("Welcome to factorial calculator")
TextWindow.WriteLine("Enter the n: " )
n = TextWindow.Read()
res = n
For i = n-1 To 1 Step -1
  res = res * i
EndFor

TextWindow.WriteLine(res)


2. Code with correct result of 0!
This below is completed program:

TextWindow.WriteLine("Welcome to factorial calculator.")
TextWindow.WriteLine("Enter the n: " )
n = TextWindow.Read()
res = n

If n = 0 Then
  res = 1
Else
 
For i = n-1 To 1 Step -1
  res = res * i
EndFor
EndIf

TextWindow.WriteLine("The result of permutation is: " + res)

SMALL BASIC: Programming quiz #3

1. What will be the result or the output of these lines of code?
For i = 0 To 10
  g[Array.getitemcount(g)+i] = i
EndFor
  TextWindow.WriteLine(g)

2. What will the output of these lines below, do you think its working?
start = 100

For i = (start - 1) To 1
  TextWindow.WriteLine(i)
  Program.Delay(1000)
EndFor

Selasa, 07 April 2020

SMALL BASIC: For determined start row and col

Hi, SMALL BASIC programmer, welcome.

Did you know that small basic for can be started not only from the beginning or a.k.a line 0 or row 0 and col 0?

Below is the example:

traversed_row = 3
traversed_col = 4

For i = traversed_row To 5
    If i = traversed_row Then
      For j = traversed_col To 5
        TextWindow.WriteLine("i : " + i + ", j: " + j)
      EndFor
    else
    For j = 0 To 5
      TextWindow.WriteLine("i : " + i + ", j: "+ j)
    EndFor
  endif
EndFor

   
    

SMALL BASIC: File

File take the information match as the Windows file.

There are cases, for instance:
1. Folder can't be accessed or forbidden.
2.
3.

Minggu, 05 April 2020

FFMPEG: Extracting ce

SMALL BASIC: Folder and subfolder 2

Hi, SMALL BASIC programmer, welcome.

TextWindow.WriteLine("Please enter the start folder: ")
start[0] = TextWindow.Read()

'1. Take the 1st door
'Make start as an array
loop_start = 0
start:
TextWindow.Clear()
loop_start = loop_start + 1
TextWindow.WriteLine("This is start: " + start)
TextWindow.Pause()
TextWindow.WriteLine("This is the level depth: " + loop_start)
TextWindow.pause()
'TextWindow.WriteLine("This is start: " + start)
s_l = Array.GetItemCount(start) - 1
TextWindow.WriteLine("This is start length:" + s_l)

'Take all the 1st doors
'Remember that getdirectories start from 1
nbr_iterator = 0
For i = 0 To s_l
  'TextWindow.WriteLine("This is i for s_l: " + i)
  'TextWindow.Pause()
  fgd = File.GetDirectories(start[i])
  If fgd <> "" Or fgd <> "FAILED" Then
  ''Get fgd length
    f_l = Array.GetItemCount(fgd)
    'n_l = Array.GetItemCount(nbr) - 1
    TextWindow.WriteLine("This is the mother door: " + start[i])
    TextWindow.WriteLine("========================")
  For j = 1 To f_l
    nbr[nbr_iterator] = fgd[j]
    TextWindow.WriteLine("this is nbr index: " + nbr_iterator + "this is the son: " + nbr[nbr_iterator])
    'Program.Delay(1000)
    nbr_iterator = nbr_iterator + 1
    'TextWindow.WriteLine("this is nbr_iterator: " + nbr_iterator)
    'TextWindow.WriteLine("This is the value of index " + nbr_iterator + ": " + nbr[nbr_iterator])
    'Program.Delay(1000)
   EndFor
  Else
   
  EndIf
 
EndFor

TextWindow.WriteLine(nbr)
TextWindow.Pause()

'4. Count the length of nbr and route based on the length wether it goes up again or end of program
n_l = Array.GetItemCount(nbr) - 1
If n_l <= 0 Then
  TextWindow.WriteLine("End of the program")
  Goto eop
Else
  'Fill the total array with nbr element so later nbr element will be cleared
  'Get the last element of the total array
  t_l = Array.GetItemCount(total)
 
  For i = 0 To n_l
    total[t_l + i] = nbr[i]
   TextWindow.writeline(total[t_l+i])
  EndFor
 
  start = nbr
  nbr = ""
  Goto start
EndIf
eop:
TextWindow.WriteLine(nbr)

 
 






SMALL BASIC: Permutation calculator

Hi, SMALL BASIC programmer, welcome.

Before we dive in, we need to learn what permutation are.

Permutations are:
1. Different elements.
2. Minus one each range from the number of elements.
3. The same as factorial, if n are r.

So, this is the code:

TextWindow.WriteLine("Welcome to permutation calculator!")
TextWindow.WriteLine("Created by: Jesus Christ, lord and the Messiah!")
TextWindow.WriteLine("Hello enter the n: ")
start = TextWindow.Read()

k = start - 1
'TextWindow.WriteLine("This is k : " + k)
res = start


For i = k To  Step -1
  res = res * (i)
  'TextWindow.WriteLine("This is i: " + i)
  'TextWindow.Writeline("This is result: " + res)
  'j = j + 1
EndFor

'get the length of result array
'r_l = Array.GetItemCount(result) - 1

TextWindow.WriteLine("The result is: " + res)

Jumat, 03 April 2020

SMALL BASIC: Drag-n-drop version 1

Hi, SMALL BASIC programmer, welcome.

Did you know that SMALL BASIC can also make a draag-n-drop program?

Here is the code:

'1. Preparing the graphics windows
GraphicsWindow.Show()
GraphicsWindow.Width = Desktop.Width
GraphicsWindow.Height = Desktop.Height
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0

'2. Define the program header introduction
TextWindow.WriteLine("Hello Welcome to drag and drop program")
TextWindow.WriteLine("Created by Jesus Christ, the Lord and Messiah")
TextWindow.WriteLine("==============================================")


'2. Interactive session with user

TextWindow.WriteLine("1. Enter the url of the background that you like: ")
u_bground = TextWindow.Read()
'u_bground = "C:\Users\Totardo\Downloads\download (6).jpg"

TextWindow.WriteLine("2. Enter the url of the icon to drag-and-drop that you like: ")
u_icon = TextWindow.Read()
'u_icon = "C:\Users\Totardo\Downloads\download.jpg"

TextWindow.WriteLine("3. Enter the the x position of the icon to drag and drop (itdad_x): ")
itdad_x = TextWindow.read()
'itdad_x = 100

TextWindow.WriteLine("4. Enter the y position of the icon to drag and drop (itdad_y): ")
itdad_y = TextWindow.Read()
'itdad_y = 100

TextWindow.WriteLine("5. Enter the width of the itdad (w_itdad): ")
w_itdad = TextWindow.Read()
'w_itdad = 396

TextWindow.WriteLine("6. Enter the height of the itdad (h_itdad): ")
h_itdad = TextWindow.Read()
'h_itdad = 100


'3. Drawing background and icon and place the icon
GraphicsWindow.DrawImage(u_bground,0,0)
s_icon = Shapes.AddImage(u_icon)
Shapes.Move(s_icon,itdad_x,itdad_y)

'4. Define the event handler
GraphicsWindow.MouseDown = md
i = 0
follow_mouse = 0

'5. Define the main loop
loopz:

while follow_mouse <> 0
  Shapes.Move(s_icon,GraphicsWindow.mousex,GraphicsWindow.mousey)
  TextWindow.WriteLine("This is follow mouse from the main program: " + follow_mouse)
  'Program.Delay(1000)
endwhile

Goto loopz


'6. Define the sub procedure md for mouse down
Sub md
  '6.1 Toggle the keydown switch on and off
  If keydown = 1 Then
    keydown = 0
  Else
    keydown = 1
  EndIf
 
  'TextWindow.WriteLine("Key is: " + keydown)
 
  '6.2 do something based on the switch on or off
  If keydown = 1 Then
  TextWindow.WriteLine("Its down")
  'TextWindow.WriteLine("This is follow mouse: "+ follow_mouse)
  'mx = Mouse.MouseX
  mx = GraphicsWindow.MouseX
  my = GraphicsWindow.mousey
  'TextWindow.WriteLine("This is mouse x: " + mx)
  'TextWindow.WriteLine("This is mouse y: " + my)
  'TextWindow.WriteLine("This is total width: " + (itdad_x + w_itdad))
  'TextWindow.WriteLine("This is total height: " + (itdad_y + h_itdad))
  'TextWindow.WriteLine(GraphicsWindow.width/2+","+GraphicsWindow.Height/2)
 
  'GraphicsWindow.DrawLine(itdad_x,0,itdad_x,GraphicsWindow.Height)
  'GraphicsWindow.DrawLine(itdad_x+w_itdad,0,itdad_x+w_itdad, GraphicsWindow.Height)
  'GraphicsWindow.DrawLine(0,itdad_y,GraphicsWindow.width,itdad_y)
  'GraphicsWindow.DrawLine(0,itdad_y+h_itdad,GraphicsWindow.width,itdad_y+h_itdad)
 
 
 
  'If mx lebih besar pojok dan lebih kecil sama dengan w_itdad
  itdad_x = Shapes.GetLeft(s_icon)
  itdad_y = Shapes.GetTop(s_icon)
  If mx >= itdad_x And mx <= itdad_x + w_itdad Then
   'TextWindow.WriteLine("Inside the width")
  if my >= itdad_y And my <= (itdad_y + h_itdad) Then
   'TextWindow.WriteLine("Inside the height")
   'TextWindow.WriteLine("Its connect!")
 
   If follow_mouse = 0 Then
     follow_mouse = 1
     EndIf
   EndIf
   EndIf
 
   Else
   If follow_mouse = 1 Then
     follow_mouse = 0
     EndIf
     EndIf
   'TextWindow.WriteLine("This is follow mouse on a sub: " + follow_mouse)
    'Shapes.HideShape(s_icon)
    'Shapes.ShowShape(s_icon)
   

EndSub

   
   

 
 

SMALL BASIC: Controlling main program loop from sub

Hi, SMALL BASIC programmer, welcome.

In this tutorial, we will discussed how to control main program's loop from sub.

At first, the loop will be triggered with the click mouse and the stop it with click mouse, on and on.

The code example is below:

GraphicsWindow.Show()
GraphicsWindow.MouseDown = md
x = 0

loopz:

While x <> 0
TextWindow.WriteLine(x)
endwhile

Goto loopz


Sub md
  If x = 0 Then
    x = 1
  Else
    x = 0
  EndIf
  TextWindow.WriteLine(x)
EndSub
  

Kamis, 02 April 2020

SMALL BASIC: Programming question session 2

1. If you have an array like below, what is the length of the array, notice the index 0 of the array is empty or "", i.e. What is the output of textwindow window?

myarr[0] = ""
myarr[1] = "A"
myarr[2] = "B"
TextWindow.WriteLine(Array.GetItemCount(myarr))

A). 1 B). 2 C). 3

2. Still with code from number  1


3. Logic question: Mr. Bono told to record all the room number that are not empty and handed that record to Mr. Bing, because Mr. Bing wants to knock every door's room, meet and invite every room user to have a tea while talk with him/her about the rise of the rent.

But,

4). Look for the code below, I want to add fgd array's element to nbr array's element. Do you think the nbr array elements grows or appended with fgd elements forever?

fgd[0] = "Added"
fgd[1] = "Added"
nbr[0] = 0
nbr[1] = 1

start:

nbr_l = array.GetItemCount(nbr)
TextWindow.WriteLine(nbr_l)
TextWindow.Pause()
For i= 0 To 1
  nbr[i+nbr_l] = fgd[i]
EndFor
TextWindow.writeline(nbr)
Program.delay(1000)
Goto start


5). Multi dimension array question. Look at for the code below, do you think the code will generated y as a multi dimension array? or not?

x[0] = 10
x[1] = 11

For i = 0 To 1
  y[i] = x
EndFor


TextWindow.WriteLine(y)
 

6). Still based on question 5, how many lines or rows, array y have?

SMALL BASIC: Interrelation of arrays

Hello, SMALL BASIC programmer, welcome.

In this tutorial we will learned about interrelation of arrays. There are two, three or even more arrays that are interelated during the programming session.

What interrelation of arrays. Interrelation of arrays, I mean what

Use this the value of each of the element's of this array (Array A) to get


1. Get the index of this value
2. Get the value of this index

1. Save as the value of this index
2. Save as the index of this value

So for example, get the index of this value and save it as the value

Get the value of the these indexes and use it as index of to access another array and save it as the value of this index.

SMALL BASIC: Adding or appending elements to array

Hello, SMALL BASIC programmer, welcome.

In this tutorial we will learn how to adding or appending elements to an array. These are few tips or few methods:

1. Adding or appending elements one by one
2. Adding or appending elements one array by one array whole

So, lets discuss this one by one:

1. Adding or appending elements one by one

object_1[0] = "A"
object_1[1] = "B"
object_2[0] = 1
object_2[1] = 2

'Appending one element after one element to an array
'1st. Find the length adder and the length of addee, but
'except the object_1 don't substract it with 1
object_2_l = Array.GetItemCount(object_2) - 1
object_1_l = Array.GetItemCount(object_1)

For i = 0 To object_2_l
  object_1[object_1_l+i] = object_2[i]
EndFor


'2. Get the length of the new object
object_1_l = Array.GetItemCount(object_1)
For i = 0 To object_1_l - 1
  TextWindow.WriteLine(object_1[i])
EndFor
  



Rabu, 01 April 2020

SMALL BASIC: Programming questions session 1

Hello, SMALL BASIC programmer, welcome.

In this page we will learned programming question session 1 (amid corona virus outbreak).

So, what is the answers of the questions below:

1. Look at program below, what is the value of i, each time i is printed to the textwindow window?

Up:
TextWindow.WriteLine(i)
For i = 0 To 10
  Goto up
  Program.Delay(1000)
EndFor

2. Still using above program, but with slight modification. How many time the program will runs or a.k.a the program printed "Hello World!" to the textwindow window?

Up:
TextWindow.WriteLine("Hello World!")
For i = 0 To 10
  Goto up
  Program.Delay(1000)
EndFor

3. Still using program number 1, but with slight modification. Is it i incremented each time i is printed out to the textwindow window?

Up:
i = i + 1
TextWindow.WriteLine(i)
For i = 0 To 10
  Goto up
  Program.Delay(1000)
EndFor

4. Still using program number 1, but with slight modification. Is it "Hello World" string printed out to the screen?

Up:
i = i + 1
TextWindow.WriteLine(i)
For i = 0 To 10
  Goto up
  TextWindow.WriteLine("Hello World")
EndFor

Ok, thats it. I hope you enjoy the questions.

SMALL BASIC: Folder-subfolder iteration

Hello, SMALL BASIC programmer, welcome.

In this tutorial, we will learn about how to get all folders and all sub folders started from our first folder or first door.

This tutorial implements tree diagram traversing algorithm.

There are two types of how to draw a tree diagram:
1. Using vertex,vertex label, link, and link label.
2. Using hierarchy

You can train a lot with tree diagram with folder-subfolder iteration. Yeah, you can learn a lot with folder-subfolder.

You can also implement this to full mesh topology, where full mesh topology is a type of tree diagram topology each of the descendat connects to other descendent.


So, okay, now how to solve the tree diagram traversing algorithm?
It essentially, opening first door and write the next door, recursively; loop back from the beginning again.



SMALL BASIC: Removing unwanted element

Hi, SMALL BASIC programmer, welcome.

In this tutorial, we will learned about removing unwanted element from an array, in this case from a single line multi colomn (SLMC) array not multi line multi colomn (MLMC). So, watch it.

For example, we want to remove element that have value FAILED from an SLMC array.

There are couples method that you can do to this, but I prefer this. If you do this differently, you will get different experience.

x[0] = "SUCCESS"
x[1] = "FAILED"
x[2] = "SUCCESS"
x[3] = "SUCCESS"

k = 0
m = 0
For i = 0 To 3
  If x[i] = "FAILED" Then
    x_l = Array.GetItemCount(x) - 1
    'Move the front and the back
    For j = i + 1 to x_l
      y[k] = x[j]
      k = k + 1
    EndFor
    For l = i - 1 To 0
      z[m] = x[l]
      m = m + 1
    EndFor
    'Merge y and z, merge y to the back of z
    '1st. Search the length of z
    z_l = Array.GetItemCount(z) - 1
    '2nd. And then transfer one by one
    For transfer_index = 0 To z_l
      y[Array.GetItemCount(y)] = z[transfer_index]
    EndFor
  EndIf
EndFor

TextWindow.WriteLine(y)
 
   
   

SMALL BASIC: Checking elements are same value or not

Hi, Small Basic programmer, welcome.

In this tutorial we will learned about a program that check whether values of colomn of the same row of an array are same or not same using SMALL Basic.

This is useful sometimes when you program and few situations.

So here is the program:
y[0] = "Failed"
y[1] = "Success"
y[2] = "Failed"

y_l = Array.GetItemCount(y) - 1
For i = 0 To y_l
  If y[i] = "Success" Then
    TextWindow.WriteLine("Not all failed")
    Goto quitloop
  Else
    If i = y_l then
      TextWindow.WriteLine("All failed")
      EndIf
      EndIf
EndFor
  quitloop:




Selasa, 31 Maret 2020

SMALL Basic: Learn to read array and multi array

Hello Small Basic programmer, welcome.

In this tutorial we will learned about reading single row multi colomn array and multi row and multi colomn array small basic.

We will read this not line per line, but as a whole array.

This is useful to know when you need to do more deep about your work. Especially when you work with folder and array.

So, in this tutorial we will learned about:
1. Reading single row multi colomn (SRMC) array
2. Reading multi row and multi colomn (MRMC) array

You know both of them is different. So, lets go.

1. Reading single row and multi colomn (SRMC) array
This is the code:
i[0] = "s"
i[1] = "a"
i[2] = "y"
i[3] = "b"
TextWindow.WriteLine(i)

The output will be:
Figure 1


2. Reading multi row and multi colomn (MRMC) array
This is the code:
i[0][0] = "s"
i[0][1] = "a"
i[1][0] = "y"
i[1][1] = "b"
TextWindow.WriteLine(i)

The output will be:
Figure 2

So, you can see, both of the output are different.

The ';' sign is for seperating colomn (like figure 1 explained) and also seperating row (like figure 2 explained).

So, the ';' sign is used both as in single row multi colomn (SRMC) array and multi row multi colomn (MRMC) array.

And, 'index\=<value>\' is used only for multi row multi colomn (MRMC) array and used only for seperating index colomn and value.

Ok, thats it. Thanks for reading.

DOTA 2: Guide

There are 4 ways of earn money:
1. Killing line creeps
2. Killing jungle creeps
3. Killing enemy heroes
4. Killing Roshan

You need to learn survability technique here:


1. Killing line creeps

2. Killing jungle creeps
2.1 Killing jungle creeps low level ally's jungle
2.2 Killing jungle creeps low level enemy's jungle
2.3 Killing jungle creeps medium level ally's jungle
2.4 Killing jungle creeps medium level enemy's jungle

SMALL Basic: Nested-loop and non-nested loop

Hi, SMALL Basic programmer, welcome.

In this tutorial, we will learned something, that is nested loop and non-nested loop.

You know there are 3 components to build loop:
1. For..
2. While..
3. If.. Goto..

And there are 2 types of loops based on mechanics:
1. Nested-loop
2. Non-nested loop

So, in this tutorial we will discussed nested-loop and non-nested loop.

Nested loop we will be with 2 level loops (a.k.a 1 inner loop and 1 outer loop).

Non-nested loop we will be using 1 level loop.

1. Nested-loop
1.1 Nested-loop with For.. Loop
Making or creating nested loop with For.. Loop is very easy.

You only need to define number of loops for the inner loops, and for the outer loops.

For example:
For i = 0 To 1
  For j = 0 To 10
    TextWindow.WriteLine(i + " ," + j)
  EndFor
EndFor


1.2 Nested-loop with While.. Loop
Making or creating nested loop is at first looks medium difficulty. But not, when you are an expert.

While i < 100
  While j < 100
    TextWindow.WriteLine(i +", " + j)
    j = j + 1
  EndWhile
  i = i + 1
  j = 0
EndWhile

1.3 Nested-loop with If.. Goto.. Loop
Creating nested-loop with If.. Goto.. and creating non-nested loop with If.. Goto.. is different.

Creating nested-loop with If.. Goto.. loop is a little harder., because we need to iterator variable that need to be incremented.

For example below:

i = 0
j = 0
Goto start
up_i:
i = i + 1

up_j:
start:
If j < 10 Then
  TextWindow.WriteLine(i + ", " + j)
  j = j + 1
  If j < 10 Then
    Goto up_j
  Else
    Goto up_i
  EndIf
  Program.Delay(1000)
EndIf
 

2. Non-nested loop
2.1 Non-nested loop with For.. Loop


2.2 Non-nested loop with While.. Loop

2.3 Non-nested loop If.. Goto.. Loop

Senin, 30 Maret 2020

SMALL BASIC: Forever and not-forever Loop

Hello, SMALL Basic programmer, welcome.

Beside, nested loop and not-nested loop, loop can also be defined into forever loop and not-forever loop.

So, based on the mechanic, loops can also divided into:
1. Nested loop
2. Not-nested loop

And,  types of loop based on lifetime:
1. Forever
2. Not-forever or limited

So, in this tutorial we will learned with not-nested loop, forever loop and not-nested loop, not-forever loop.

You know, there are 2 types of loop based on lifetime. Forever loop and not-forever loop. And, there are 3 types of loop maker: For, while and if.. goto..

3 Loop maker:
1. For
2. While
3. If.. Goto..

2 Types of loop based on lifetime:
1. Forever
2. Not-forever or limited

Both can be made with loop maker.

For example:
1. Forever
1.1 Forever loop with For loop
You can make forever loop using for by using a very,very big number. So it looks like forever because of length of the number, but it is not.

for i = 0 To 9999999999999999999999999
  TextWindow.WriteLine(i)
EndFor

1.2. Forever loop with While loop
You can also make forever loop by using while loop by using a very, very big number, so it also looks like forever because of length of the number, but it is not.

While i < 999999999999999999999999999
  TextWindow.WriteLine(i)
  i = i + 1
EndWhile

1.3. Forever loop with If.. Goto.. Loop
This the last type and actually it is the best kind of making forever loop.

up:
TextWindow.WriteLine(i)
i = i + 1
Goto up

2. Not-forever
2.1 Not-forever loop with For loop
Creating not-forever loop with for loop is easy, you just need to define the number not big enough as the limit.
Example:

For i = 0 To 100
  TextWindow.WriteLine(i)
EndFor

2.2 Not-forever loop with While loop
Creating not-forever loop with While loop is easy, the same as For loop, you just need to define the number that is not big enough as the limit.

For example like below:
while i < 100
  TextWindow.WriteLine(i)
  i = i + 1
EndWhile

2.3 Not-forever with If.. Goto.. Loop
Okay, to make not-forever loop or limited loop with If.. Goto.. Loop is quite difficult. But it is okay, you will got it.

In this, if.. goto.. loop type you will need the help of iterator variable (in this case i variable), same as with While loop example and off course, you need the help of a label to jump to.

So, iterator variable, the increments expression for iterator, goto expression and a label.

For example

up:
TextWindow.WriteLine(i)
If i < 100 Then
  i = i + 1
  Goto up
EndIf

SMALL BASIC: Shifting partly array's element

Hi, welcome, Small Basic Programmer, welcome.

In this tutorial we will learn about shifting partly array's element and remove the trail. This often needed in some cases of programming.

For instance, we have array:
ourarray[10]

For i = 0 To 10
  ourarray[i] = i
EndFor

TextWindow.WriteLine("Enter the start of shifted components of the main array: ")
start = textwindow.Read()
For i = start  To 10
  ourarray[i-1] = ourarray[i]
EndFor


oa_l = Array.GetItemCount(ourarray)
For i = 0 To oa_l - 1
  TextWindow.Write(ourarray[i])
  TextWindow.Write(",")
  Program.Delay(1000)
EndFor


  

Computer Security

1. Non-socket program
2. Socket program

1. Days before firewall
Everyone can easily create socket user program then the user program contacted someone else on the internet to say:
1. status of the program; alive or not alive.
2. Give or send the contain of a file.


SMALL Basic: Type of code's execution speed

Hello, SMALL Basic programmer, welcome.

In this tutorial, I will show you how two types of code's execution speed based on my experience.
1. Fast execution time, hard to write code, compact code, short code.
2. Slower execution time, easier to write code, divided or non-compact code, long code.

You can combine compact code and non-compact code on your programs.

Thanks for reading.

Minggu, 29 Maret 2020

SMALL BASIC: Dynamic looping types

Hello, SMALL Basic programmer, welcome.

In every programming, there are case when you need dynamic looping.

There are two types of dynamic looping
1. Dynamic nested looping
2. Dynamic non-nested loop

'This is also why OSPF is limit its neighbors. I'm just guess so.

Dynamic nested loop is used when you want to generate password for password cracker program, for instance 8 digits password, 9 digits password, and 10 digits password.

And for folder iteration program, like dir /S command on cmd windows.

You can create loop:
1. For.. For..
2. For.. While..
3. For.. If.. Goto..
4. While.. For..
5. While.. While..
6. While.. If.. Goto..
7. If.. Goto.. For..
8. If.. Goto.. While..
9. If.. Goto.. If.. Goto..


For dynamic non-nested loop
You can do this:
1. Using for.. for..
2. Using while.. for..
3. Using if.. goto..


how_many = 3

For i = 0 To how_many - 1
  For j = 0 To 10
    TextWindow.WriteLine(j) 
  EndFor
EndFor

Or use while:
While i <= how_many
  For j = 0 To 10
    TextWindow.WriteLine(j)
  EndFor
  i = i + 1
EndWhile

For instance:
for i = 0 to
for j = 0 to
for k = 0 to

For instance you want to create code

myarray[0] = 8
myarray[1] = 9
myarray[2] = 10

for i = 0 to array.getitemcount(myarray) - 1
for j = 0 to myarray[0]
textwindow.writeline("

Jumat, 27 Maret 2020

SMALL BASIC: How to debug SMALL BASIC code

Hello, SMALL BASIC Programmer, in this tutorial, I will share about how to debug SMALL Basic code:

You know there are no step up or step down debugging feature in SMALL BASIC editor. So, you basically need traditional way to do code debugging:

If I can define, the types of error are userinput error, and program error.

Userinput error

User input error are program hang or program error or program halt or program crash or program  that because generated by wrong or invalid user input.

For example, this is when I asked user what is the fontsize and then the user just press enter without entering value.

For example code are below:
textwindow.writeline("What is the fontsize? :")
fs = textwindow.read()

The rest of the code; the codes after this is just postponed, because of this error.

The solution to this is: Just use if to make sure

2) Example:
textwindow.writeline("What is the divisor? :")
divisor = textwindow.

graphicswindow.fontsize =

There are two errors:
1. Run time error
2.



1. Using GOTO and GOTO label
2. Using textwindow.writeline()
3. Using smallbasic

SMALL BASIC: Making video intro like matrix

Hello, SMALL Basic Programmer.

In this tutorial, we will learn about how to make video intro like matrix. You can watch the video below to see. You can also uses this program as a video therapy when you want to sleep (I found out that this program can be a video therapy when I stared the code running too long; it kinda give me some calm effect to my brain) or you can use it as video banner of your youtube video.


The program is dividing the width of the graphics window with the area the determined by the user, the result is x.

This is kinda confusing but the point is x, and the loop start from 0 to x - 1.


There are problems that arise:
1. You need to be continuous between the cloters number
2. How to make the Text always in front position not in the back position.
3. Etc,.

You can watch the movie here:



In this program, we devide it in two:
1. The first version
2. The last completed version



This is the 1st style program:

GraphicsWindow.Show()
GraphicsWindow.Width = Desktop.Width
GraphicsWindow.Height = Desktop.Height
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0

TextWindow.WriteLine("Hello, welcome to the matrix board created with Small Basic.")
TextWindow.WriteLine("Created by: Jesus Christ, the Lord and Messiah.")
TextWindow.WriteLine("1. Enter what background color that you want to use: ")
bc = TextWindow.Read()
TextWindow.WriteLine("2. Enter what font color that you want to use: ")
fc = TextWindow.Read()
TextWindow.WriteLine("3. Enter the font size that you want to use (default is 12): ")
fs = TextWindow.Read()
TextWindow.WriteLine("4. Enter the font name that you wan to use (for ex. Times New Roman)")
fn = TextWindow.Read()
TextWindow.WriteLine("5. Enter the font space : ")
fsp = TextWindow.Read()
TextWindow.WriteLine("6. Enter the text that you want to enter: ")
tte = TextWindow.Read()
TextWindow.WriteLine("7. Enter the size of the text that you want to use: ")
sott = TextWindow.Read()
TextWindow.WriteLine("8. Enter the x position of the text that you want to use: ")
xpt = TextWindow.Read()
TextWindow.WriteLine("9. Enter the y position of the text that you want to enter: ")
ypt = TextWindow.Read()

'Set the graphics settings based on the input from the user
GraphicsWindow.BackgroundColor = bc
GraphicsWindow.BrushColor = fc
GraphicsWindow.FontSize = fs
GraphicsWindow.FontName = fn

GraphicsWindow.FontSize = sott
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawText(GraphicsWindow.Width/2,GraphicsWindow.Height/2,tte)

GraphicsWindow.BrushColor = fc
GraphicsWindow.FontSize = fs
ics = fsp + fs
nocpw = GraphicsWindow.Width / ics


continue = 1

  For i = 0 to nocpw
    td = Text.GetCharacter(Math.GetRandomNumber(100))
    TextWindow.WriteLine(td)
    ts[i] = Shapes.AddText(td)
    Shapes.Move(ts[i],i*ics,0)
    'group = group + 1
    'Program.Delay(100)
  EndFor
  maks = i

While continue = 1
  For i = 0 To Array.GetItemCount(ts) - 1
    x = Shapes.GetLeft(ts[i])
    y = Shapes.GetTop(ts[i])
    'TextWindow.WriteLine(x)
    'TextWindow.WriteLine(y)
    Shapes.Move(ts[i],x,y+fs)
    'Program.Delay(100)
    EndFor
 
 
  'This part is for adding new sprites
  For j = 0 to nocpw
    'maks = maks + 1
    i = maks + j
    td = Text.GetCharacter(Math.GetRandomNumber(100))
    'TextWindow.WriteLine(td)
    ts[i] = Shapes.AddText(td)
    Shapes.Move(ts[i],j*ics,0)
    'TextWindow.WriteLine("Testing")
    'Program.Delay(100)
  EndFor

  maks = i
  endwhile

  sub nantiajalah
    For i = 0 To Array.GetItemCount(ts) - 1
      Shapes.Move(ts[i],Shapes.GetTop(ts[i]),shapes.GetLeft(ts[i])+ fs)
      'Program.Delay(1000)
      'gt = Shapes.gettop(ts[i])
      'gl = Shapes.GetLeft(ts[i])
      'TextWindow.WriteLine("gt : " + gt + ", gl : " + gl)
      EndFor
  endsub
   




This is the completed version:
GraphicsWindow.Show()
GraphicsWindow.Width = Desktop.Width
GraphicsWindow.Height = Desktop.Height
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.Title = "Jesus Christ the Lord and Messiah - Graphicswindow"
TextWindow.Title = "Jesus Christ the Lord and Messiah - Textwindow"
'TextWindow.WriteLine("")

TextWindow.WriteLine("Hello, welcome to the matrix board created with Small Basic.")
TextWindow.WriteLine("Created by: Jesus Christ, the Lord and Messiah.")
TextWindow.WriteLine("Year: 2020, amid of Coronavirus outbreak.")
TextWindow.WriteLine("Ok, lets begin...")
TextWindow.WriteLine("=============================================================")
TextWindow.WriteLine("")
TextWindow.WriteLine("1. Enter what background color that you want to use (default is orange): ")
bc = TextWindow.Read()
TextWindow.WriteLine("2. Enter what font color that you want to use (default is yellow): ")
fc = TextWindow.Read()
TextWindow.WriteLine("3. Enter the font size that you want to use (default is 12): ")
fs = TextWindow.Read()
TextWindow.WriteLine("4. Enter the font name that you want to use (default is Times New Roman): ")
fn = TextWindow.Read()
TextWindow.WriteLine("5. Enter the area width of each character (default is 5): ")
wec = TextWindow.Read()
TextWindow.WriteLine("6. Enter the text that you want to enter (default Jesus Christ is the Lord and Messiah!): ")
tte = TextWindow.Read()
TextWindow.WriteLine("7. Enter the size of the text that you want to use (default is 12): ")
sott = TextWindow.Read()
TextWindow.WriteLine("8. Enter the x position of the text that you want to use (default is 0): ")
xpt = TextWindow.Read()
TextWindow.WriteLine("9. Enter the y position of the text that you want to enter (default is 0): ")
ypt = TextWindow.Read()


TextWindow.Write("Ok, Lets draw")
For i = 0 To 2
  TextWindow.write(".")
  Program.Delay(1000)
EndFor


'This part is for Userinput validation
If bc = "" Then
  bc = "Orange"
Else
EndIf

If  fc = "" Then
  fc = "Yellow"
Else
EndIf

If fn = "" Then
  fn = "Times New Roman"
Else
EndIf

If wec = "" Then
  wec = 5
Else
EndIf

If tte = "" Then
  tte = "Jesus Christ is the Lord and Messiah!"
Else
EndIf

If xpt = "" Then
  xpt = 0
Else
EndIf


If ypt = "" Then
  ypt = 0
Else
EndIf


If sott = "" Then
  sott = 36
  GraphicsWindow.FontSize = 36
Else
  GraphicsWindow.FontSize = sott
EndIf

If fs = "" Then
  fs = 12
  GraphicsWindow.FontSize = 12
Else
  GraphicsWindow.FontSize = fs
EndIf

'TextWindow.WriteLine("sott is this: " + sott)
'TextWindow.WriteLine("fs is this: " + fs)

GraphicsWindow.BackgroundColor = bc
GraphicsWindow.FontName = fn

'Program.Delay(5000)
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
gbc = GraphicsWindow.BrushColor


'GraphicsWindow.DrawText(GraphicsWindow.Width/2,GraphicsWindow.Height/2,tte)
wec = wec + fs 'area width
'TextWindow.WriteLine("ini wec: " + wec)
'Program.Delay(6000)
myt = Shapes.AddText(tte)

'TextWindow.WriteLine("OK")
shapes.Move(myt,xpt,ypt)


GraphicsWindow.BrushColor = fc


spot = GraphicsWindow.Width / wec

'TextWindow.WriteLine("ini spot: " + spot)
'Program.Delay(5000)

continue = 1


'This creating the 1st cloter
  For i = 0 to spot - 1
    'td = Text.GetCharacter(Math.GetRandomNumber(100))
    td = Math.GetRandomNumber(99)
 
    'TextWindow.WriteLine(td)
    ts[i] = Shapes.AddText(td)
    Shapes.Move(ts[i],i*wec,0)
    'TextWindow.WriteLine(i + "dengan nilai: "+ td)
    'group = group + 1
    'Program.Delay(1000)
 
  EndFor

  'TextWindow.WriteLine("ini i : " + i - 1)
  'Program.Delay(5000)
  'Goto eof
  'TextWindow.WriteLine(i)
  'maks = i
  'TextWindow.WriteLine("maks : " + maks)

While continue = 1
  'This part is for moving all sprite down one fontsize to the bottom

  For i = 0 To Array.GetItemCount(ts) - 1
    'TextWindow.WriteLine(ts)
    'Program.Delay(5000)
    'TextWindow.WriteLine("Ini nilai panjang ts: "+ Array.GetItemCount(ts))
    'Goto eof
    'Program.Delay(100)
    x = Shapes.GetLeft(ts[i])
    y = Shapes.GetTop(ts[i])
    Shapes.Move(ts[i],x,y+wec)
    'TextWindow.WriteLine("Total elemen adalah: " + array.GetItemCount(ts) - 1)
    'TextWindow.WriteLine("ini adalah i penurunan: " + i)
    'TextWindow.WriteLine("Ini adalah elemennya nilai: " + ts[i])
    'Program.Delay(500)
  EndFor

    'TextWindow.WriteLine(ts)
    'TextWindow.WriteLine("jumlah yang telah diturunkan : " + i - 1)
    'TextWindow.WriteLine("###############################")
    'Program.Delay(5000)
 
    'This part is for creating new sprites for total nocpw
 
    start = Array.GetItemCount(ts)
   For i = 0 to spot - 1
 
    'TextWindow.WriteLine(ts)
    'Program.Delay(5000)
    'td = Text.GetCharacter(Math.GetRandomNumber(100))
    td = Math.GetRandomNumber(99)
    'TextWindow.WriteLine("dibawah: " + i +", td : " + td)
    'TextWindow.WriteLine("nilai: "+ td)
    GraphicsWindow.BrushColor = fc
    GraphicsWindow.FontSize = fs
    ts[i+start] = Shapes.AddText(td)
    Shapes.Move(ts[i+start],i*wec,0)
    'Program.Delay(5000)
  EndFor
  'TextWindow.WriteLine("Total element hingga sekarang: " + Array.GetItemCount(ts)-1)
  'TextWindow.WriteLine("###############################")
  'Program.Delay(5000)
  maks = i

  'This part is for recreating the text, so it can't get behind the rainning characters
  'A.k.a this is for the shape get in front of the rainning character


  Shapes.Remove(myt)
  GraphicsWindow.FontSize = sott
  GraphicsWindow.BrushColor = gbc
  myt = Shapes.AddText(tte)
  shapes.Move(myt,xpt,ypt)
  GraphicsWindow.FontSize = fs
  GraphicsWindow.BrushColor = gbc
  endwhile


   

eof:

Kamis, 26 Maret 2020

Python: Making DNS server

FACT
1. DNS server program can be tested locally and interlocally using local program like cmd or using other host on the LAN network.
2. This the result of the local testing, using command:
nslookup www.google.com 127.0.0.1
in command prompt window or cmd.

(b'\x00\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x011\x010\x010\x03127\x07in-addr\x04arpa\x00\x00\x0c\x00\x01', ('127.0.0.1', 56921))
(b'\x00\x02\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01', ('127.0.0.1', 56922))
(b'\x00\x03\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x1c\x00\x01', ('127.0.0.1', 56923))
(b'\x00\x04\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01', ('127.0.0.1', 56924))
(b'\x00\x05\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x1c\x00\x01', ('127.0.0.1', 56926))

3. You can't use wireshark to capture local traffic. So, you need to rely on the output of the python:
4. The \x is define that the next 2 characters are hex characters. For example \x00
5. \x03 is end of text.
6. When someone asks, you need to answer.
7. UDP Header is always 8 byte.
8. The DNS query length is = UDP length - 8 byte - (2 byte * 8)

SMALL BASIC: Create Matrix Diagonal zero with Loop For

Hi, SMALL Basic programmer, welcome.

In this tutorial we will create a diagonal matrix with random number values. The program is like below:

TextWindow.WriteLine("Enter the matrix size that you like to enter: ")
ms = TextWindow.Read()

For i = 0 To ms
  For j = 0 To ms
    if array[i][j] <> 0 Then
      If i <> j then
      array[i][j] = Math.GetRandomNumber(10)
      array[j][i] = array[i][j]
      ElseIf i = j then
      array[i][j] = 0
      EndIf
    EndIf
  EndFor
EndFor

Creating diagonal zero matrix is essentially give value to both (i,j) and (j,i) if (i,j) is still empty or still not initialized yet for how many rows and colomns that you like.

Fact about mesh

Every line is neighbor list of that line or a.k.a of that element. So for instance you want to make a program like this: print all the neighbor and the neighbor

Print all the neighbor of the first first neighbor of node 1
textwindow.writeline("Enter the node: ")
node = textwindow.read()
textwindow.writeline("Enter the neighbor you want to print its neighbor:")
neighbor = textwindow.read()

or this can be said like this:
textwindow.writeline("Enter the node: ")
node = textwindow.read()
textwindow.writeline("Enter the index of the neighbor that you want us to print its neighbor: ")
firstneighborindex = textwindow.read()

'And then read the relationship_array


Every step kedalam, will reduce 2 * i neighbor.


SMALL Basic - Picture to punctuation convertion

You know you can make

I want to make a black and white image to have punctuation or other characters in the black pixels.

'GraphicsWindow.FontSize = 10
'GraphicsWindow.FontName =
wide = 5
GraphicsWindow.FontSize = wide
GraphicsWindow.DrawImage("C:\Users\Totardo\Downloads\flower-black-a-white-pattern-vector-224732.jpg",0,0)
For i = 0 To 1080 Step wide
  For j = 0 To 823 Step wide
    black_count = 0
    For k = 0 To wide
      For l = 0 To wide
        'GraphicsWindow.FillEllipse(i+k,j+l,1,1)
        test[i+k][j+l]=GraphicsWindow.GetPixel(i+k,j+l)
        pc = GraphicsWindow.GetPixel(i+k,j+l)
        TextWindow.WriteLine(i+k+","+j+l+","+pc)
        If pc <> "#FFFFFF" Then
          'TextWindow.WriteLine("Not pure white")
          black_count = black_count + 1
          'TextWindow.WriteLine("black_count is:" + black_count)
          'Program.Delay(1000)
        EndIf
     
      EndFor
    EndFor
    If black_count >= (wide/2*wide/2) Then
      TextWindow.WriteLine("black count: " + black_count)
      'Program.Delay(1000)
      'GraphicsWindow.DrawRectangle(i,j,20,20)
      paint_new[i+k][j+l]="?"
      'ts = Shapes.AddText("?")
      'Shapes.Move(ts,i,j)
    Else
      paint_new[i+k][j+l]=" "
      EndIf
  EndFor
EndFor

Sub aloha
For i = 0 To array.GetItemCount(test[i])
  For j = 0 To Array.GetItemCount(test[j])
    GraphicsWindow.BrushColor = test[i][j]
    GraphicsWindow.FillEllipse(i,j,1,1)
  EndFor
EndFor
EndSub

GraphicsWindow.Clear()

For i = 0 To 200
  For j = 0 To 200
    GraphicsWindow.DrawText(i,j,paint_new[i][j])
  EndFor
EndFor

  

Rabu, 25 Maret 2020

SMALL BASIC: Make Histogram program

Hello, welcome SMALL Basic programmer.

In this tutorial we will learn how to make histogram program; that is program that count how many pixel a pixel color are in an image.

So the program like this:
TextWindow.WriteLine("1. Enter the file path of the image: ")
ifp = TextWindow.Read()
TextWindow.WriteLine("2. Enter the width information image: ")
wii = TextWindow.Read()
TextWindow.WriteLine("3. Enter the height information image: ")
hii = TextWindow.Read()

'1. Load or draw the image
GraphicsWindow.DrawImage(ifp,0,0)
'2. Get all the pixel's color information from pixel index 0,0 to 200,200
For i = 0 To hii
  For j = 0 To wii
    'get all the pixel's color information
    pc = GraphicsWindow.GetPixel(i,j)
    If i = 0 And j = 0 Then
      col_arr[0][0] = pc
      col_arr[0][1] = 1
      Goto quit
    EndIf
    'Checking with col_arr array (col_arr stands for color array)
    For k = 0 To array.GetItemCount(col_arr) - 1
      If pc = col_arr[k][0] Then
        col_arr[k][1] = col_arr[k][1] + 1
        max = 1 'to trace the length of the row of the col_array
    Goto quitloopk
      Else
        If k = Array.GetItemCount(col_arr) - 1 Then
          col_arr[max][0] = pc
          col_array[max][1] = 1
          max = max + 1
        EndIf
      EndIf
        quit:
        EndFor
        quitloopk:
  EndFor
EndFor
TextWindow.WriteLine("No."+"Color"+"Number of pixels")
      For i = 0 To Array.GetItemCount(col_arr) - 1
        TextWindow.WriteLine(i +","+col_arr[i][0]+":"+col_arr[i][1]+" Pixels")
      EndFor
     
 


SMALL BASIC: Determining color of a pixel is it white or not

Hi, Welcome Small Basic Programmer.

In this tutorial we will learn about how to determine color of a pixel is it white or not using small basic.

The image will be traveled or traced up and down not to the right.

This code is the simplest way, you can use hex to decimal converter if you want.


GraphicsWindow.DrawImage("C:\Users\Totardo\testing.png",0,0)
For i = 0 To 200
  For j = 0 To 200
    TextWindow.WriteLine("i : " + i + ", j : " + j)
    pc = GraphicsWindow.GetPixel(i,j)
    GraphicsWindow.FillEllipse(i,j,10,10)
    If pc <> "#000000" Then
      TextWindow.WriteLine("It's not black i.e. it is white")
    Else
      TextWindow.WriteLine("It is black")
    EndIf
    Program.Delay(1000)
  EndFor
EndFor
  

Senin, 23 Maret 2020

SMALL BASIC: Playing with multi-array

Hello, welcome SMALL Basic programmer.

In this tutorial, we will played with multi-array in SMALL basic, and doing stuff like:
1. Printing all element forward; from the first element to the last element.
2. Printing all elements backward; from the last element to the first element.
3. Printing range of elements of a row or line
4. Printing range of elements of a colomn
5. Printing few of elements of a line.
6. Printing few of elements of a colomn.
7. Printing all element of a row
8. Printing all element of a colomn
9. Printing all element of two rows
10. Printing cyclic row
10.
6. Printing a specific or an element of a row
7. Printing a specific or an element of a colomn
8. Diagonal left
9. Diagonal right

Pre-requisite
So, to be able to work this material, you need to learn:
1. How to create multi-array in SMALL Basic
2. Nested for in SMALL Basic

So, welcome to the journey of multi-dimension array! It is fun journey!
FACT
1. Notice that we use an example that consist of square matrix, it means the length for the column is the same for all the row.
2. So, we can use array.getitemcount(ourarray) operation to get the length of each for row and for colomn of our array - ourarray.
3. It is often good to think multi array as m-floor building with n-room in each floor.

But we devide this tutorial as:
1. Just printing the element matrix
2. Playing arithmatic with matrix like add, substract, divide, or multiply.

First, off course, we need to build a multi array; a 3 dimension array; a 3 row times 3 colomn array, how? like below:

But first, you know, you can make matrix 2 row times 2 colomns like below:
ourarray[0][0] = 1
ourarray[0][1] = 1
ourarray[1][0] = 0
ourarray[1][1] = 0

But it to small for us to play. So, we will make a matrix with 3 row times 3 colomn instead. Like below:
ourarray[0][0] = 1
ourarray[0][1] = 1
ourarray[0][2] = 0
ourarray[1][0] = 0
ourarray[1][1] = 0
ourarray[1][2] = 1
ourarray[2][0] = 1
ourarray[2][1] = 1
ourarray[2][2] = 0

And then printing out
1. Printing all element forward

  For i = 0 To Array.GetItemCount(ourarray) - 1
    For j = 0 To Array.GetItemCount(ourarray) - 1
      TextWindow.WriteLine(ourarray[i][j])
    EndFor
  EndFor

2. Printing out backward

You will notice that both of the loop variable are minus
For i = Array.GetItemCount(ourarray) - 1 to 0 step -1
  For j = Array.GetItemCount(ourarray) - 1 To 0 Step -1
    TextWindow.WriteLine("This is our array [" +i+"]["+j+"]: "+ ourarray[i][j])
    EndFor
  EndFor



3. Printing range of elements of a row
For instance, I want to print element column range from colomn 0 to element colomn 1 of a row, for instance row 1.

The range itself, I put into an array called range. So the program is below:

row = 1
range_col[0] = 0
range_col[1] = 1

For i = row To row
      For j = range_col[0] To range_col[1]
        TextWindow.WriteLine("This is our array [" + i + "]["+ j +"] : " + ourarray[i][j])
      EndFor
    EndFor

Notice that the row loop variable, i.e. i is stick to the number of the row that you want to retrieve.

4. Printing range of elements of a colomn
Printing range of elements of a colomn is printing start from and end with.

The range itself as example 3, I put into an array called. So the program is below:
col = 1
range_row[0] = 1
range_row[1] = 2

For i = range_row[0] to range_row[1]
      For j = col To col
        TextWindow.WriteLine("This is our array [" + i + "][" + j + "] :" + ourarray[i][j])
      EndFor
    EndFor

5. Printing few elements of a colomn
The difference this printing few of elements of a colomn and printing range of element (example 4) is this will print uncontinuos elements. While printing range of element prints continous elements start from start point, end from end point.

In this example, we will print element's value of elemen 0 and elemen 2.

For i = row to row
      For j = 0 To Array.GetItemCount(ourarray) - 1
        For k = 0 To Array.GetItemCount(fewcol) - 1
          If j = fewcol[k] then
            TextWindow.WriteLine("This is our array [" + i + "][" + j + "]: " + ourarray[i][j])
          EndIf
        EndFor
        EndFor
        endfor

As you notice, here we use three loops, that are loop i, lo

6. Printing few elements of a row
The difference this printing few of elements of a row and printing few element


7. Printing few elements of a col

For i = 0 to Array.GetItemCount(ourarray) - 1
      For j = col To col
        For k = 0 To Array.GetItemCount(fewrow) - 1
          If i = fewrow[k] then
            TextWindow.WriteLine("This is our array [" + i + "][" + j + "]: " + ourarray[i][j])
          EndIf
        EndFor
        EndFor
        endfor
7. Printing all element of a row
The clue when printing all element of a line is: the line loop variable is stick to the number of the line that you like to print, but the colomn loop variable is changing.

For example:

5. Printing all element of a colomn
The clue when printing all element of a colomn is: the colomn loop variable is stick to the number of the colomn that you like to print, but the line loop variable is changing.

For example below we want to print all the element's value of colomn 2:
For i = 0 to 2
For j = 1 to 1
textwindow.writeline(ourarray[i][j])
endfor
endfor


6. Printing



8. Printing diagonal left or decline diagonal (if we look or start from the left side of the matrix)
Printing diagonal left using loop is unique; it only uses 1 loop not two as like other examples. So like this:

For i = 0 to Array.GetItemCount(ourarray) - 1
j = i
textwindow.writeline(ourarray[i][j])
endfor

If you use two loops it would produce "printing all elements" program.

9. Printing diagonal right or incline diagonal (if we look or start from the left side of the matrix)
Printing diagonal right or incline diagonal is uniqe, because one of the loop is counting backward that is the colomn

For i = 0 to array.getitemcount(ourarray)
for j = array.getitemcount(ourarray) - 1 to 0 step -1
textwindow.writeline(ourarray[i][j])
endfor
endfor

Notice

10. Printing cyclic row

This is when you want to print from different row other than row 0 and then back to behind your start or desired row.

For instance, I started printing all colomns start from row 1 to row 2 and then back to row 0.

textwindow.writeline("Enter the source or the start: ")
source = textwindow.read()

For i = source To array.GetItemCount(ourarray) - 1
  For j = 0 To Array.GetItemCount(ourarray[i]) - 1
    TextWindow.WriteLine(ourarray[i][j])
  EndFor
EndFor

If source > 0 Then
  For i = 0 To source
    For j = 0 to Array.GetItemCount(ourarray[i]) - 1
    TextWindow.WriteLine(ourarray[i][j])
    endfor
    EndFor
EndIf

i
This is the first journey


Source_node = 0
Destination_node = 1

matrix[0][0] = 0
matrix[0][1] = 1
matrix[0][2] = 1
matrix[0][3] = 1
matrix[1][0] = 1
matrix[1][1] = 0
matrix[1][2] = 0
matrix[1][3] = 1
matrix[2][0] = 1
matrix[2][1] = 0
matrix[2][2] = 1
matrix[2][3] = 1

j = 0

'1. Check or list the neighbor of the source_node
TextWindow.WriteLine("Enter the center node: ")
the_center = TextWindow.Read()

'1. Get the count of center's neighbor
TextWindow.WriteLine("")
cn = Array.GetItemCount(matrix[the_center])
TextWindow.WriteLine(cn)

'2. Get the list of center's neighbor (index that have value 1)
j = 0
for i = 0 To cn - 1
  If matrix[the_center][i] = 1 Then
    neighbor_1[j]=i
    j = j + 1
  EndIf
EndFor

'3. display the neighbor_1 list
For i = 0 To array.GetItemCount(neighbor_1) - 1
  TextWindow.WriteLine("This is neighbor " + i + " element :" + neighbor_1[i])
EndFor