Thursday, April 27, 2023

 Simple Python Calculator


This script will allows your to calculate the integers given with the chosen operation. You can add, substract, multiply and divide the numbers.

class kalkulator:
    def __init__(self,no1,no2):
        self.no1 = int(no1)
        self.no2 = int(no2)
    #formula
    def tambah(self):
        return self.no1 + self.no2
    def tolak(self):
        return self.no1 - self.no2
    def darab(self):
        return self.no1 * self.no2
    def bahagi(self):
        if self.no2 <= 0:
            print("Nombor kurang atau sama dengan sifar. Tidak boleh dibahagi")
        else:
            return self.no1 / self.no2

def main():
    print("Kalkulator\nTekan q untuk keluar")
    chkNo1 = input("Masukkan nombor pertama : ")

    #semak sama ada integer atau q untuk exit program
    if chkNo1 == "q":
        print("Tamat!","\n")
        exit
    else:
        chkNo2 = input("Masukkan nombor kedua : ")
        if bool(int(chkNo1)) == False:
            print("Masukkan integer sahaja")
            main()
        elif bool(int(chkNo2)) == False:
            print("Masukkan integer sahaja")
            main()
        else:
            no1 = chkNo1
            no2 = chkNo2
            kira = kalkulator(no1,no2)

            operasi = int(input("Pilih operasi : tambah(1), tolak(2), darab(3), bahagi(4) : "))
            if operasi == 1:
                print("Jawapannya adalah : ", kira.tambah())
            elif operasi == 2:
                print("Jawapannya adalah : ", kira.tolak())
            elif operasi == 3:
                print("Jawapannya adalah : ", kira.darab())
            elif operasi == 4:
                print("Jawapannya adalah : ", kira.bahagi())
            else:
                print("\n","RALAT: Sila masukkan pilihan operasi yang betul")
            print("=="*14,"\n")
               
        main() #akan loop pada main selagi tidak stop script

main() #default akan run main

Wednesday, April 26, 2023

 Getting ip address using python

Script to get the ip address from domain name. Here's the code

import socket

# fungsi untuk semak dns
def check_dns(hostname):
    try:
        # menyemak dns
        ip = socket.gethostbyname(hostname)
        print(hostname, " IP ditemui:", ip)
        print("Address Info: ", trace)
    except socket.gaierror:
        # jika dns tidak ditemui
        print("DNS tidak ditemui")

# menjalankan fungsi
check_dns("www.google.com")
check_dns("www.example.com")
check_dns("www.mynic.my")

Simple OpenAi Python Script

 Make your own OpenAi chat


I am totally new comer in Python trying to learn this language from scratch. Knowing a basic of python language is a quite easy for me as it is not a big different from JavaScript (if not mistaken). As the OpenAi are become popular today i take a chance to learn on how to make a simple OpenAi script using Python. 

I usually use Microsoft Visual Studio Code to scripting. We have to install OpenAi extension first by typing this command to the terminal:

pip install openai

then after that, create a new python file named ai.py and put in this codes. Save it and run it using debugger or type python3 ai.py:

Hope this helps

import openai

openai.api_key='get-your-own-key' #generate it from openai.com

while True:
    model_engine ="text-davinci-003" #model 3 openai
    prompt = input("[AI] Apa yang anda ingin tahu? : ")
    if prompt == "exit" or prompt == "quit":
        break

    completion = openai.Completion.create(
        engine = model_engine,
        prompt = prompt,
        max_tokens = 4000, #jumlah maksimum teks,
        n = 1, #tetap hanya sekali respon,
        stop = None,
        temperature = 0 #semakin tinggi akan memberi kesan tidak accurate
    )
    response = completion.choices[0].text

    print(response + "\n")
    print("=="*40)
    print("\n")


Tuesday, August 7, 2012

No More Connection on Windows XP - Huh!


Solutions #1
1. Click Start, click Run, type regedit, and then click OK.
2. Locate and then click to select the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Lanmanserver\Parameters
3. On the Edit menu, point to New, and then click DWORD Value.
4. Type MaxMpxCt, and then press ENTER.
5. Right-click MaxMpxCt, and then click Modify.
6. In the Value data box, type the desired value, and then click OK.
Note You can set the number of concurrent SMB commands to a value that is between 10 and 255. The default value is 10. In Microsoft Windows Server 2003, you can set the number of concurrent SMB commands to a maximum value of 65,535.
7. Close Registry Editor.
Default XP Professional conncurrent connection is 15.

Solution #2
1. Click start, run, type cmd and then click OK
2. Type net config server /autodisconnect:1 and press ENTER ( this will instruct to auto disconnect idle connection for 1 minute rather than default 15 minutes)
3. Useful command to explore
net config server
net config workstation
net statistics server
net statistics workstation 

Solution #3
Get tcpip.sys patcher from http://www.lvllord.de/

Friday, March 2, 2012

Game Server : Getting Started

Srcds allows you to to serve an online game in a virtual environment. If you have a good connection and computer available, you can simply install the software and prepare your virtual battlefield to be entered. srcds will serve all Half-Life 2 ("Game of the year 2004") based games, including Counter-Strike Source, Day of Defeat Source and alot more modifications!

If you run your own Source Dedicated Server, you have control over most of the settings.
For instance, you have control over the amount of gravity, the current map and the mapcycle and alot more.
You also have full control over the players. When a player misbehaves, you can simply permanently or temporary remove the weak link and continue the game. 

Source from http://www.srcds.com/

Friday, February 3, 2012

Easy way to install antivirus for Linux ( Console )

OS : Debian platform
Sources : http://download.bitdefender.com/repos/

wget http://download.bitdefender.com/repos/deb/bd.key.asc
apt-key add bd.key.asc ( must be root )

pico /etc/apt/sources.list

deb http://download.bitdefender.com/repos/deb/ bitdefender non-free

apt-get update
apt-get install bitdefender-mail

Friday, January 27, 2012

Aptitude GPG Error Simple Solution

Always getting some gpg error while trying to do aptitude update on older version of debian platform such as etch or lenny. The message looks like this :

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA

what should we do?
1st of all you have to be a root and check the key first with pgp.net server : the command is :
#gpg --keyserver wwwkeys.us.pgp.net --recv-keys AED4B06F473041FA


then it should return like this :

gpg: requesting key 473041FA from hkp server wwwkeys.us.pgp.net
gpg: key 473041FA: public key "Debian Archive Automatic Signing Key (6.0/squeeze " imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)




what's next?


#gpg --armor --export | apt-key add -


then do aptitude update again and it should work

 Simple Python Calculator This script will allows your to calculate the integers given with the chosen operation. You can add, substract, mu...