O Language: First Router

The router socket structure was created with the intention of creating an API over the HTTP/S protocol and exchanging data through the socket. In web based projects it is possible to write web server quickly and easily. In addition, the API can be created in micro-services.

hello.olm (as hello module):

def hello = fn(name){
 return "Hello, "+name+"! Welcome to Olang"
}

router.ola (as router script):

load "hello.olm"

def config = {
 "GET" : {
 "/" : "Welcome to the O-Lang Router!"
 },
 "POST":{
 "/:name" : hello("{{.name}}")
 }
}

show("Listening 0.0.0.0:8080... Ctrl+C to exit.")
router("8080", config);

GET method test:

~> curl -X GET localhost:8080
Welcome to the O-Lang Router!

POST method test (oytun as parameter value for name [ :name => {{.name}} ]):

~> curl -X POST localhost:8080/oytun
Hello, oytun! Welcome to Olang

As you can see in the example, we wrote a web micro service using port 8080 via get and post methods.

O Language: HTTP Example Socket

The HTTP socket allows the HTTP protocol to be displayed on the web using any port. You can use the http(path, port, response) function to easily create an http socket.

hello.olm:

def hello = fn(name){
 return "Hello, "+name+"! Welcome to Olang"
}

httptest.ol:

load "hello.olm"
show("Listening 0.0.0.0:8080... Ctrl+C to exit.")
http("/", "8080", hello("Oytun"));

First we loaded our “hello” module with load. Later in the hello() function on the 8080 port to provide this output. When we enter port localhost:8080 from our browser or curl, the result will be;

~> curl localhost:8080
 Hello, Oytun! Welcome to Olang

Now we can display the socket by connecting to 8080 port via HTTP. In the following lessons we will learn how to create routers and render pages on them.

O Language: Functions and Literals

The only difference between functions and literatures is that one of the brackets can be operated without parentheses. In this way you can define your own definitions.

Functions

The system has function definition function. These functions can be used many times.

def main = fn(param){
    return param
};

main("Hello!"); 
# => main function result:"Hello!"

Literals

You benefit by creating static functions directly in the system literature.

literal example(param){
   println(param)
}

main "Hello!"
# => main literal result:"Hello!"

Now we can begin to learn scope definitions.

O Language: Getting Started (Part 1)

System Oriented Functional Programming Language (SOFPL)

SOFPL is a specific structure that interprets each line separately and outputs the result. Shorten the functions performed in normal programming languages. For example, you can do the functions you can do in 10 lines with a line. It is up to you to determine what you will do in 9 lines. 🙂

In addition, you can start the process on the system, you can open the port and start data transfer. Simple socket software and transaction management functions are available and developed.

Continue reading “O Language: Getting Started (Part 1)”

How to use system drive or path swap drive for linux/unix

I heard that it is possible to use a portion of hard disk as RAM in Windows. I wondered if this trick is available for Ubuntu, so I googled about it and couldn’t find anything related to it. But I found out an AskUbuntu answer of using USB sticks as RAM. I did the same trick on Hard Disk and it works !! This trick can be accomplished with the use of some small commands in Terminal. The RAM memory increase can’t be noted in the System Monitor application.So, Let’s begin. Create a file of 512 MB (The 512 indicates the RAM memory to be added):

dd if=/dev/zero of=~/swapfile bs=4096 count=131072

The yellow background text above shows the count of the file we are going to create. This count and bs determines the file size. This is how I got the count :

512 * 1024^2 / 4096 = 131072

The yellow background text above shows the file size we need to create in Mega Bytes (MB). If you need to create SWAP space with more than 512 MB change the yellow background text above to the MB you want and get the result of the calculation. The result is the count.

Example of 1 GB :

1024 * 1024^2 / 4096 = 262144

and the command will become :

dd if=/dev/zero of=~/swapfile bs=4096 count=262144

The command will create a file named subinsblog on your home directory.

Now let’s create the SWAP space on the file and enable the SWAP :

sudo mkswap ~/swapfile -f && sudo swapon -p 1000 ~/swapfile

You’re RAM Memory is now increased. To check whether if it is increased, do the following command :

free -m

Thats all.