Tuesday, February 28, 2023

GTK4 Tutorial Pt. 1

Viewpoint may be largely unrelated to its usefulness. Many if not most of the software we use is probably obsolete according to the latest design criteria. Most users could probably care less if the internals of the operating system they use is obsolete. They are rightly more interested in its performance and capabilities at the user level. Ken Thompson, The Tanenbaum-Torvalds Debate

Before you follow this series, you need Vala on your computer. Refer the Installation Guide on HOWTO install Vala on different platforms and distros.

This note or tutorial is written as part of the learning process. So, obviously it will have errors in terms of grammar, typo, code, explanation and so on. You are welcome to suggest a correction. The note is concise and contains numerous reference (archive) links for detail/better explanation. Enjoy!

---

Create a new file with name hello.vala. Here, hello is the name of the file and .vala is the extension of the Vala programming language.

touch hello.vala

(Of course, you can create this new file in many different ways. I wrote command to make instruction clear!)

Open the created hello.vala in text-editor of your choice and write the text hello, world as that's what we're interested to print.

hello, world

This hello, world text is string in Vala. String in Vala must be enclosed within double quotes only (single quotes are for characters).

"hello, world"

The string hello, world is not going to be printed in terminal by default. We need to invoke printf() method from stdout object to print the string in terminal. Don't worry about this stdout object for now. It is default available in any project to use.

stdout.printf("hello, world")

Vala is one of those programming language that requires semicolon or ; to terminate the statement.

stdout.printf("hello, world");

Vala, being compiled programming language requires main() method to start the execution.

int main() {
  stdout.printf("hello, world");
}

We need to return 0 from the main() method at the end as we have already mentioned int as return type of this method.

int main() {
  stdout.printf("hello, world");

  return 0;
}

Finally, let's add \n after hello, world text to print it nicely in terminal.

int main() {
  stdout.printf("hello, world\n");

  return 0;
}

That's it! This is our hello, world program in Vala!

To run this program, we need to invoke Vala compiler or valac on this file using following command.

valac hello.vala

After successful compilation, you'll get hello (after the name of the file) as an executable. You can simply run this executable using following command.

./hello
hello, world

In other words, you need to run two command to see the final output in Vala.

valac hello.vala
./hello
hello, world

Or you can use && operator to run both commands in single command line.

valac hello.vala && ./hello
hello, world

In future, we'll going to accept the command-line arguments while running the program/application. To make that works, I'm updating the prototype of the main() method to access the command-line arguments.

int main(string[] args) {
  stdout.printf("hello, world\n");

  return 0;
}

You wouldn't see any difference while running this program again in terms of output. But, this modification is good to have.

valac hello.vala && ./hello
hello, world

---

Let's do some modifications in this hello.vala program while on the same time printing the hello, world text in the terminal. How about creating a new method with name greet() that prints the same hello, world text?

void greet() {
  stdout.printf("hello, world\n");
}

int main(string[] args) {
  stdout.printf("hello, world\n");

  return 0;
}

This greet() method returns nothing hence I mentioned void as return type of this method. We can call this method from main() method at the place of printf() statement.

void greet() {
  stdout.printf("hello, world\n");
}

int main(string[] args) {
  greet();

  return 0;
}

Even after doing these changes, we'll see the same output in the terminal as it was previously - hello, world text.

valac hello.vala && ./hello
hello, world

Let's even go further and print the text world from the name variable define inside the main() method as follows.

void greet(string name) {
  stdout.printf("hello %s\n", name);
}

int main(string[] args) {
  string name = "world";
  greet(name);

  return 0;
}

In main() method, we defined the name variable with world as the initial value. Then in next line, we passed this defined variable to greet() method as an argument. We also modifies the greet() method to accept one string parameter. Finally, we used %s placeholder to print the value of name at the place of text world.

Again, running this program prints the same output.

valac hello.vala && ./hello
hello, world

This is still hello, world program in Vala but with variable and supporting method.

Let's take a break and meet again to write the hello, world program but this time in object-oriented manner.

Sunday, February 26, 2023

ગિરની વાતો

ગિરનારનાં પગથિયાં પાર ઢબ ઢબ લાકડીઓ ટેકા લેતી આવતી હતી. નાનાં છોકરાંને તેડીને બે મજૂરણો ચડી આવતી હતી. એમના બોલ મોતી જેવા વીણી શકાતાં હતાં. એક ડોસીનો બોલ પકડાયો: "શું કરું બાઈ? ગાંડી થઇ જાઉં તો મલક ઠેકડી કરશે કે હારીને ગાંડી થઇ ગઈ. એટલે જ રોજ ડુંગરા ચડવા-ઊતરવા રિયા."

જુવાનજોધ દીકરાઓના અકાળ મોત પછી સંસારમાં એકલી થઇ પડેલી શ્રમજીવી મા ઉપહાસ ન થાય તે સારું ઉદ્યમમાં મસ્ત છે; છતાં આપણા વાર્તાકારો એ પાત્રોને ગાંડપણ અને આત્મહત્યા સુધી લઇ જવામાં જ શોભા સમજે છે.

*

ત્રણ ડોળીવાળા ગિરનારની પહેલી ટૂક પર ચોથાની રાહ જોતા હતા.

'આવ્યા, આવ્યા. બાપુ આ આવ્યા.' બોકાનીદાર એક ખડતલ મરદ આવી પહોંચ્યો. 'આહીં ધૂણે આવો. જરા તાપી લ્યો. ચા પી લ્યો.'

મૂંગા મરદે તાપ્યું. ચા પતાવી ડોળી લઈને ચાર મરદો પગથિયાં ઊતરવા લાગ્યાં. અરધો રસ્તો કપાયો તેટલામાં જ 'બાપુ'નો જીવન-ઇતિહાસ જડી ગયો. ચાર દીકરા, દીકરાના પણ જુવાન પરણાવેલા દીકરા, ચાલી નીકળ્યા. દીકરાની ને દીકરાના દીકરાની વહુઓ જુદાં ઘર માંડીને મજૂરીએ ચડી ગઈ હતી. બાપુ એંશી વર્ષની અવસ્થાએ ડોળીઓ ચડાવતા-ઉતારતા રહ્યા છે. એમનો જીવનસંતોષ એક જ હતો: સાઠ વર્ષથી જાત્રાળુ બાયું-બેન્યુંને ગરનાર ચડાવ્યો-ઉતરાવ્યો છે, કોઈની સામે કે'દી ય નજર માંડી નથી, કોઈને કે'દી કષ્ટ દીધું નથી, આઘુંપાછું વેણ કહ્યું નથી.

ડોળી ઊંચકનાર પચાસ-સો મજૂરોનો નૈતિક આદર્શ આ ઇસ્માઇલ-બાપુ છે. એમની આપવીતી એ શ્રમજીઓની મહાગાથા છે. મૂંગું રહેવામાં જ માનવતાનું ગૌરવ સમજનાર એ ડુંગર જેવડું દુખ પચીસ-પચાસ સાથીઓની મૂંગી દિલસોજીથી મધુર બની ટાંટિયામાં જીવન-વાટ ખેંચવાનું જોર મૂકે છે.

આપણે [લેખક] ચીતરીએ છીએ જુદ્ધિ પાત્રસૃષ્ટ્રિ, પલેપલ દયાની યાચનાઓ પુકારતી, દુખ અને અન્યાનના બબડાટા કરતી. આપણને સ્વાનુભવ નથી.

- ઝવેરચંદ મેઘાણી

Monday, February 20, 2023

Learning Rust Pt. 6

Writing a condition is quite easy in Rust and follow simple and intuitive syntax and rule.

  1. No need to write the condition within bracket.
fn main() {
  let x = 4;
  
  if x % 2 == 0 {
    println!("{} is even.", x);
  }
}
  1. The expression must be evaluated to boolean value, otherwise, Rust will complain.
fn main() {
  let x = 4;
  
  if x {
    println!("{} is even.", x);
  }
}

As usual, we've the else with if.

fn main() {
  let x = 4;
  
  if x % 2 == 0 {
    println!("{} is even.", x);
  } else {
    println!("{} is odd.", x);
  }
}

Or you can even use else if in some specific scenario.

fn main() {
  let x = 4;
  
  if x > 0 {
    println!("{} is positive.", x);
  } else if x < 0 {
    println!("{} is negative.", x);
  } else {
    println!("{} must be zero.", x);
  }
}

Saturday, February 18, 2023

Learning Rust Pt. 5

Rust is static typed language and we need to define data with the types. The above program works due to a concept called the type inference which is supported by Rust nicely.

When you assign an initial value to a variable, Rust will infer the initial value and based on it, it'll auto assign the default type good type. In following example, the type of x will be i32 as an integer.

fn main() {
  let x: i32 = 12;
  println!("{}", x);
}

We've few integer data types in Rust such as i8, i16, i32, i64, and i128 as signed integer and u8, u16, u32, u64 and u128 as unsigned integer.

fn main() {
  let x: u8 = 12;
  println!("{}", x);
}

If the assigned value contains decimal point in it, it'll be treated as floating-point number and the default value will be f64. For the float, we've f32 and f64 and f64 being the default one.

fn main() {
  let x = 13.3;
  println!("{}", x);
}

As usual, we've more primitive data types as we have found in other programming language such as char for character with single character. The main difference in Rust that you'll notice is, you can have the UTF-8 character. The default and the only type for the character is char.

fn main() {
  let x = '🥳';
  println!("{}", x);
}

Finally, the bool or boolean is yet another primitive data type that has true and false as one of the possible values.

fn main() {
  let x: bool = true;
  println!("{}", x);
}

We've seen the string in double quotes. But, string is not the primitive data type in Rust. We'll talk about string in future.

Wednesday, February 15, 2023

Learning Rust Pt. 4

let keyword is used to define a variable in Rust.

fn main() {
  let name = "Bruce";
  println!("Hello, {}", name);
}

We can define as many variables as we want using let. But, we need to use them once defined. Otherwise, compiler will throw a warning (not error) as unused variables.

fn main() {
  let name = "Bruce";
  let age = 29;
  println!("Hello, {}", name);
}

Even further, compiler also suggests the variable to prefix with _ if variable is defined in this way (defined but no plan to use for now) to remove the warning.


let actually create an immutable variable. In other words, you can't change the value of it once defined. You'll get an error about assigning the value to immutable variable.

fn main() {
  let x = 12;
  x = 13;
  println!("{}", x);
}

If we're intentionally plan to change the value as suggested above, we need to mut the variable.

fn main() {
  let mut x = 12;
  x = 13;
  println!("{}", x);
}

But, this again throw a warning about unused assignment as value 12 that is assigned in above program is re-assigned again before it actually used. So, assigning 12 is useless.

Monday, February 13, 2023

Learning Rust Pt. 3

We can print as many text on the terminal as we want using println!() macro. These text are known as string in Rust and must be written enclosed in double quotes only.

fn main() {
  println!("hello, world");
  println!("how are you?");
}

{} within println!() macro is used to substitute the values from associated arguments.

fn main() {
  println!("hello, {}", "world");
  println!("how are {}?", "you");
}

You can have more than one upto as many as you want substitution in println!() macro. The order is important in argument. See the second println!() as an example.

fn main() {
  println!("{}, {}", "hello" "world");
  println!("{} {} {}?", "how", "you", "are");
}

Friday, February 10, 2023

એ સાદ કોઈ સાંભળે છે કે?

સોળ વર્ષ પહેલાં બાબુ રવીન્દ્રનાથ ઠાકુરે અવાજ ઉઠાવેલો કે રાજદ્વારી રમતો ને પ્રપંચો મૂકી દો. દેશનાયકો, ગામડાં સજીવન કરો, ઠેર ઠેર મેળા ભરો, ઉજાણીઓ કરો,રામાયણ-મહાભારતનો રસ પાવા માંડો. જન્મભૂમિ આજે નાની નાની નદીઓને કિનારે ઊભી ઊભી ગારાનાં ઝૂંપડામાં જૂથની અંદરથી ડોકિયાં કરતી કરતી નાસેલાં સંતાનોને બોલાવે છે. એ સાદ કોઈ સાંભળે છે કે?

- ઝવેરચંદ મેઘાણી

Thursday, February 9, 2023

Learning Nest Pt. 3 (Hello World!)

The obvious next step is to create the hello, world application in Nest. Run the following command to create the hello, world application using Nest CLI.

$ nest new hello-world

Nest will ask you to choose the package manager from the options. Go with the default npm (or you can choose yarn if you like) and wait for the Nest CLI to scaffold the application and also install the dependencies of the application.

Once the process is finished, go inside the created hello-world application.

$ cd hello-world

Then run the following command to start and run the application (as they mentioned in logs).

$ npm run start

Then open the http://localhost:3000 in the browser and you should see the "Hello World!". If that is the case, you just created the hello, world application in Nest. Congratulations 🎉!

Monday, February 6, 2023

Learning Nest Pt. 2 (Install Nest CLI)

Following command will install the Nest CLI. This CLI will help us to scaffold the Nest application and provide the toolchain to do many other important things with Nest application. We'll cover most of the toolchain functionalities in future.

$ npm i -g @nestjs/cli

You might need to wait for a couple of minutes to finish the installation. Once the installation is done, you have the nest command in your terminal. Run the following command to confirm the installation of Nest CLI or nest.

$ nest --version
9.1.8

If you see some version as output, you've correctly installed the Nest CLI or nest on your computer.

Thursday, February 2, 2023

MERN: Workshop - Session 1a - Introduction

Welcome to the first session of the MARN Workshop and in specific 1a of the today's session. This is a day long session where we'll talk/learn about the following topics.

  • Introduction
  • JavaScript
  • ES6
  • Node
  • NPM
  • Basics of Express

You can consider these topics as the sub-sections of today's session. We'll talk about the particular topic and then will give you some space to do the practice or ask questions in form of discussion.


This is an introductory session. We're going to touch these mentioned topics in introductory way, without going more details. The plan with this introductory session is to get you started with MERN and more specifically with Node. Learning each and everything at one go make this session boring and distracting! We're going to learn/talk MERN like child learn natural language, just start to use without knowing the exact details of pronunciations and grammar! Don't worry, we have enough sessions in this workshop to cover the details to make you expert programmer.

Ready? Let's get started with Introduction.


Introduction

In this sub-session, we're going to welcome you and give you a brief introduction on what MERN stack is and why it is popular while confirming the prerequisites for the workshop.

Welcome to the MERN Workshop. I'm Kiran and I'm your instructor for this workshop. In this sub-session, we're going talk about MERN as acronym, what it is popular, and why you should consider MERN as serious option for your career as web developer.

Before we start, following are the assumption we already made about all of you.

  • You have installed the all needed software mentioned previously.
  • You're web developer.
  • You know JavaScript.

Okay! So, M-E-R-N or MERN, what is it and what it stands for? Anybody know? Yeah, right -

  • MongoDB
  • Express
  • React
  • Node

But not in this particular order! I mean we're not going to learn these technologies in this mentioned order.

Let me ask you another question after knowing what MERN stands for - Why MERN only, what not P (of PHP) or D (of DotNet)? I mean one can easily create an application using PHP and React or DotNet and MongoDB. But, still these options are less popular (like acronym) than compare to MERN. You'll not hear PRM (PHP, REACT, MySQL) or DRM (DotNet, React, MonogoDB). Why? Anybody know?

The reason is JavaScript. Take a section look at the stack.

  • MongoDB
  • Express
  • React
  • Node

You see the common thing between all these four technologies? Yes, all these mentioned technologies use JavaScript as the language to write the code (directly or indirectly).

If you take a look at the agenda of this session then you'll find that we'll start with JavaScript even though we have made assumption about you that you know JavaScript! Because, we think JavaScript is essential for this workshop and covering a little bit JavaScript in the first session wouldn't hurt!

With this we just mark the end of first sub-session "Introduction" of today's session. After a small break we'll start second sub-session "JavaScript". Question?

Monday, January 30, 2023

A Normal Git Process

Chances are high that the Git is already installed and configured on your computer (or the computer given to you). First two sections in this post confirm the installation and configuration. These two sections also walk you through installation and configuration if you have new computer.

Installation

You can confirm the Git installation by running following command in Terminal or Git Bash.

$ git --version

Note: Every command, here and in the future, starting with the character $ is typed into a Terminal or Git Bash. The character $ is not to be typed out because it represents the prompt.

If you get some version number as output, then that means Git is installed on your computer. If not then you need to install Git from its official download page. If you're Ubuntu user, run the following command in Terminal.

$ sudo apt-get install git

This will install Git on your computer and then you can again type the version command to confirm the installation.

Configuration

Once Git is installed on your computer, you need do some configuration in order to properly use Git. This includes setup the identity and add SSH key.

The identity is required. In this way, your name should display next to commit/changes you do in project. Again, chances are high that identity is already configured on your computer. You can check it by running following command in Terminal or Git Bash.

$ git config --global user.name
Kiran Chauhan

If identity is set on your computer, you'll see the name (such as "Kiran Chauhan" in my case) as output. If not then you can set the identity with your name using following command.

$ git config --global user.name "Kiran Chauhan"

This will set the name identity. You can confirm this setup by running following command.

$ git config --global user.name
Kiran Chauhan

The name identity is now set.

You also need to set email. First let's confirm if the email is set or not by running following command.

$ git config --global user.email
kiran@example.io

In case, if you don't get the email as output, you can set it using following command.

$ git config --global user.email "kiran@example.io"

This will set the email for you. You can confirm this setup by running following command.

$ git config --global user.email
kiran@example.io

SSH Key Configuration

You need SSH key to work with local instance of the project (and this is recommended way, if you ask us). Again, chances are high that SSH key is already generated on your computer (in this case, you can skip the generation step). You can confirm it by going to one of the following path.

  1. Windows user - C:/Users/YourUser/.ssh folder - If this .ssh folder exists, then key is already generated.
  2. Ubuntu user - Look for hidden .ssh folder in you $HOME folder. If this .ssh folder exists, then key is already generated.

If this folder is not exist at the mentioned location, that means you need to generate SSH key. Please follow these steps to generate SSH key.

  1. Open Git Bash or Terminal.
  2. Paste this command by replacing with your email.
    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. This command will create new SSH key (You need to press 'Enter' couple of times) at the one of the above mentioned location.

Once SSH key is generated, you need to add this key to Git instance. Following are the steps you need to follow.

  1. Login with your account.
  2. Click on Profile.
  3. Choose SSH Keys.
  4. Click on Add New.
  5. Paste the key from .ssh/id_rsa.pub (be sure about this)
  6. Save with some name.

You are now ready to work with SSH Git URL. You can now clone the Git project with SSH URL.

Workflow

You'll always have the project in Git before you start your task (if project is not there, don't work). with some default configuration and few branches. These branches are development, RC, and master. If you're not seeing one of these branches, ask admin to create first.

You'll have tasks in system (if not create one) with unique project task number. The task mainly divided into two parts - enhancements(feature) or bugfix (there are others but those are specific ones and you'll to confirm with your team for different category).

Following are the steps, you need to always follow while working with project task and until task completes and moved to production.

  1. Check if the assigned ticket is bug or enhancement. If assigned ticket is enhancement, mark it as feature and if assigned ticket is bug then mark it as bugfix.
  2. Check out the RC branch and create a new branch with name in following pattern.
    1. If feature then - feature + / + project task # + at max three words description separated by dash. e.g. feature/5603-speed-problem.
    2. If bugfix then - bugfix + / + project task # + at max three words description separated by dash e.g. bugfix/5707-send-mail-log.
    3. All characters used in branch name must be in lowercase.
  3. By following step #3, you just created a local branch. This branch is local and you'll not see at Git instance, if you search for it online.
  4. You need to register(push) the branch online via push -> origin.
  5. You can now check out (or already checked in) the created branch and start working on it.
  6. Once your changes are done, you need to commit your changes by following these steps -
    1. Stage your changed files.
    2. Commit the changes by writing an appropriate commit message. Commit messages such as issues fixed or done are not acceptable.
    3. Push the changes to your branch.
  7. Now, your changes are up and residing inside your branch (both locally and online). You need to add or merge your branch in development so that you can test your changes in development server.
  8. To merge your changes into development, you need to check out the development branch.
  9. After checkout the development branch, you can merge your branch into development. This will move your changes into development branch/server.
  10. In order to move the changes into RC branch, you need to create a pull request. This require a code review. So, the code review can be also done.
  11. After code review confirmed, you can merge your changes into RC from Git instance.
  12. Finally, your team leader or senior developer will move changes from RC to master based on your project deployment cycle.

The process is straight forward but might looks difficult for couple of days because you might not used to be with it. Once you get familiar with it, you'll be happy Git user.

Useful Git GUI

  1. Sourcetree (for Windows and Mac)
  2. GitHub Desktop (for Windows and Mac). For Linux try this.

Sunday, January 29, 2023

Thursday, January 26, 2023

Learning Rust Pt. 2

Rust files are normally identifies via .rs extension. A journey with programming language should always starts with hello, world program and here is the Rust's one in hello.rs.

fn main() {
  println!("hello, world");
}

Being a compiled programming language, we need to invoke a Rust compiler or rustc on this program.

rustc hello.rs

Compile will create an executable (if error not found) usually named after the program file without extension that is easily run!

./hello
hello, world

And there you have the hello, world!


  1. fn is used to define a function in Rust.
  2. main() function is an important one from where the execution starts from.
  3. println!() is a macro that will print hello, world in terminal with newline at the end.
  4. ! after println!() means it is a macro and not a function.
  5. You don't have to worry about the difference between macro and function for now (If you're still insisting, here is one answer from StackOverflow might helpful for you).
  6. Semicolon is required to terminate the statement.

Tuesday, January 24, 2023

Learning Rust Pt. 1

Rust is the system programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. In other words, Rust is designed for speed, safety, and concurrently. You can use Rust to build the system level software. But, nowadays developers are crazy and use language other than it was intended like JavaScript.

Rustup is the recommended way to install the Rust on the computer. The installation steps are quite easy. Because of that, I do not plan to re-write steps again here. Go ahead and visit Install page to install the Rust on the computer.

After the installation is done, we'll get rustc or Rust compiler, cargo as package manager and build system, and rustup to manage Rust and related toolchain.

rustc --version
rustc 1.66.0 (69f9c33d7 2022-12-12)
cargo --version
cargo 1.66.0 (d65d197ad 2022-11-15)
rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.66.0 (69f9c33d7 2022-12-12)`

Click here for the Next in the series.

Sunday, January 22, 2023

TIL: typedef is not recommanded with struct in C

Today, I learn that typedef with struct trick give you a way to use structure tag like normal type. But, it is not suggested like mentioned in Linux kernel coding style document except few scenarios.

You can read more on this from stack overflow question and some of its answers such as this or this.

In general, do NOT write this.

typedef struct point {
    int x;
    int y;
} point;

point p;

Be explicit and write this.

struct point {
    int x;
    int y;
}

struct point p;

Friday, January 20, 2023

Learning Nest Pt. 1

Nest is the Node back-end framework. You can build Microservices, REST APIs, GraphQL APIs, real-time apps and more. The official website is https://nestjs.com. The documentation is available at https://docs.nestjs.com. I strongly suggest you to read the documentation as much as possible when learning or searching something in Nest. To initiate the reading, you can start with Philosophy section in documentation. The framework is written in TypeScript and the apps that you're going to be build will also be in TypeScript.

It is expected to have the recent version of Node (>= 16) and npm installed on the computer.

In next article, we'll install the Nest CLI, a required tool to work smoothly with Nest framework.

Tuesday, January 17, 2023

TIL: Recommended Way to Define Pointer Variables in C

Today, I learn that we should use int* x to define a pointer variable than int *x. Why?

Following is the way, we can define a variable in C.

int x = 3;
printf("%d\n", x); // prints "3".

If we prefix this x variable with & as &x, it'll returns the address of given variable. The type of this return address is int* meaning address of integer and * as pointer to that address.

int* address = &x;

To print the address, we can use %p as placeholder.

printf("%p\n", address);

Notice, here I wrote address and not *address. Because, * is not part of address variable name than part of type.

Monday, January 16, 2023

Fun SQL Pt. 1

I'd like to meet a woman with varied interests, curious about the world, comfortable expressing her likes and dislikes (I hate struggling to guess), delighting in her ability to fascinate a man and in being loved tenderly, who values joy, truth, beauty and justice more than "success"--so we can share bouts of intense, passionately kind awareness of each other, alternating with tolerant warmth while we're absorbed in other aspects of life.

Richard M. Stallman, My former Personal Ad

Hi! I am Jack and I am nerd. I maintain one irc channel #bmachine where around 200 hackers can talk and share their ideas on machine programming and binary instructions. Nobody except me know all these hackers. So, I decided to make an environment where they know each other and if they like (in case) they can date each others or be a friend (or co-founder of startup if their interests are same). I was thinking about what to do and the I decided to make a cmd-db for them where they can search each other and communicate.

Basically this cmd-db contains basic information about each user and users can find against this basic info. This basic information includes username, first name, last name and interest. But, I don't know anything about database and how to make this cmd-db. So I decided to take help from my friend Joe. He is web developer so I think he know about database.

I met him and talk about this cmd-db environment and he suggest to use SQLite software. Based on my search, I found that SQLite is database management software used by millions of developers and its free. So, I have decided that I will going to use this software to store all information.

In order to follow this post you need to install SQLite. You can download SQLite from Official Website and can use from terminal.

I get one copy of SQLite and install in such a way so that users can access it from specific URL. But, now the main question comes: How can I put all information here and how can other access it? I asked same to Joe:

Hi Joe, I have installed SQLite as per your instruction and make it accessible to all users. But, I don't know how to place the data on it.

You have to create a database in SQLite and then table. Inside of this table you can store your data.

But why?

Because, SQLite is a relational database and it stores all information in form of tables. You can not directly create a table. A table is part of one particular database. So, you first have to create one database and then table and then you have to insert all this information.

Oh! I see. But how?

With the use of SQL language. You need to write query in SQL for each things that you want to do with database. If you need to insert something inside of table you have to write INSERT query, if you need to update something you need to write UPDATE query.

Wait. How many queries are there?

Infinite. But... The fundamentals on which these queries are created is simple, If you know the fundamentals then you can easily work with any databases. I mean with any such as Oracle, MySQL, MS SQL Server.

Oh! That's good news I say...But, things are not done here. I also have to tell users to how they can use this cmd-db.

In that case what you have to do is - publish a little note on how to use cmd-db. I mean it will be the easy for them then you maintaining cmd-db. They just need to write couple of queries in-order to access information.

Okay, I hope this will be easy for them.

Don't worry. It will be easy for them.

Now from where I have to start?

First you need to create one database or db, then one table inside of that newly created db and then you can insert all your information. Basically this information will be stored in format of table, where each row contains information about one particular user and each column contains information about particular entity such as firstname. What information do you want to store?

I want to store - username, first name, last name and interest.

That means four. So you have create one table with four columns. One column for each entity. It will look something like this:

userid username firstname lastname interest
1 uname F Name L Name Hacking
2 uname2 F Name1 L Name1 Coooking

Wait Joe. Why userid here?

To uniquely identify each user over a table. I mean it might possible that two users has same username or first name or last name or interest. So, using something call id will make sure you can identify each user uniquely.

No, each user have unique username.

I know. But, we still need this userid. There are many significant uses of it, which I will tell you later but for now, please use userid.

Okay Joe. I am going home and will do search on how to make database and table. I will call you in case of difficulties.

Sure, Bye.

And then on same day I publish a note on #bmachine:

Hi everybody. I am going to create one database which includes details such as
username, fname, lname and interest of all users of this channel so you can 
better communicate with each other and share thoughts personally (if needed).
Please send your username, fname, lname and interest in personal.  
  
Thanks  
Jack

Thursday, January 12, 2023

One to One Meeting

Sharing with you some meeting advice that I find useful and learn from others.

  1. Don't spam, be genuine: If you want to meet person, don't spam by sending continuous emails or DM on various social platforms. That doesn't work, instead send message with proper details including who you are, why you want to meet and so on.
  2. Ask for Introduction: If you want to meet a person and your friend or friend's friend know him, ask for your introduction. Ask your friend or friend's friend that you want to meet him. Again if you are genuine, it will work in most of cases.
  3. Be Human: If you setup meeting with person, be human! Don't be selfish and don't talk only about you. Make conversation happen and listen him.
  4. Have a couple of topics in mind: If you are meeting with person, have a couple of topics in mind. That will help with those odd silence moments.
  5. Do your research: Do a possible research on the person you are going to meet including his general interest, what things he like and what he particularly don't like. For example, instead of talking only about technical aspects, you might take conversation happen on other interested topics including cricket or football or politics or whatever that make person friendly to talk.
  6. Make them easy to meet: Finally, make them easy to meet. Don't tell, please meet me at cafe which is 10KM away from your office. Instead, tell him, I know you are working in this area and there is nice cafe which is just walking distance away from your office. Can we meet there?

I found this advice quite helpful. So, I thought why not share?

Monday, January 9, 2023

Introduction to C Programming Language Pt. 1

Welcome to An Introduction to C Programming Language course. This is a mini yet compulsory course for undergraduate computer science students. In this course, you are going to learn C programming language and do some low-level programming. There are numerous benefits of taking this course but one of them is - this course is a prerequisite of almost all the advance courses you are going to take as undergraduate computer science student.

This is a pass/fail course. You need to pass this course in order to get hacker badge on your student’s profile. If you don't get this badge on your profile then professor will know that you don’t know C programming and it might possible that you don't get enrollment in class where more students has applied than seats available and professor has to choose.

But, don't worry! This course is not challenging course. With more practice, hard work, and patience you can easily pass this course. This course has high passing ratio than any other courses within university!

Prerequisites

As you already have completed your first semester in computer science, you know some programming and that's the prerequisites of this course. You should know the basic concepts of programming such as variables, conditionals, loops, functions, standard libraries, how to write and execute the program and so on. These basic concepts are not going to explain in this course, they are assumed - you know these concepts.

Software

You need two software on your GNU/Linux system - text-editor and compiler. You are free to use any text-editor you like but for the compiler, you must have to use GCC or GNU Compiler Collection. Because, that is the compiler on which the course is depends on.

You can communicate with your seniors for the installation of these software.

Grade

Total grade for this course is 10(+2). You need at least 7 out of 10(+2) to get badge. The grade is divided into three categories.

  1. Projects ( 3 in-course projects with weightage of 2 for each ) - 6
  2. Capstone ( capstone project, you are going to build at the end of this course ) - 2
  3. Contribution ( the contribution you need to do in open source project, will get more information in future email, when needed ) - 2
  4. Bonus ( a reserved task that we will release after second in-course project ) - 2

Finally, you will not get grade in terms of numbers. You will only get either pass or fail based on score. But, if you do an incredible job at projects, we have many things for you and that will help to build your career.

Ref. Books

This course does not depend on any book. The course notes are going to serve with each lecture. But, for the reference purpose you should purchase the K&R book. You also need some reference to standards such as C11 and C18. That is available online at devdocs.io and gcc reference manual.

Contact

This is the little introduction of this course. You might have questions regarding - anything. Feel free to ask me in personal or via email at - email. Please don’t ask or send email for installation.

Let’s Get Started

After covering this administriva stuff, we still have half an hour. In this half an hour, I’ll going to quickly cover what is C and why you should consider to use and after that we’ll write hello, world program in C.

C is the programming language that is twice older than you! and yet its been in top programming languages chart since last few decades. How? There are many reasons but some of them are:

  1. blazingly fast,
  2. provides no/little abstraction to hardware,
  3. has huge code base and experts,
  4. is small programming language and
  5. continuously evolves with backward compatibility!

C is de facto language in terms of speed. Many other languages have claim to achieve the speed near to C but none of them able to replace it! The reason of such a speediness is, an absence of abstraction to the hardware. In C, you are directly talking to hardware! That has numerous benefits when you are doing low-level programming. And that’s the reason why more than 40 operating systems are written in C. Yet the language is so small that it completely explain within 272 pages. Finally, C continuously evolves in terms of standard and make it more modern while maintaining backward compatibility. The current standard is C18.

That’s enough for introduction we will talk a lot about C in future sessions with great open discussion sections and via guest panels. Let’s quickly jump into text-editor and write our very first hello, world program.

Hello, world Program

I’ve opened the text-editor with blank window. Let me quickly save this blank program with name hello.c. C language has .c extension and hello is the name of the program that satisfies the purpose of code, going to written inside of it. After saving this blank program, I have syntax highlighting. Good!

Next, we are going to print hello, world text in terminal. So, we need to write this text within hello.c. Let me do that.

hello, world

But, this hello, world is string, right? In program, you write string inside of double or single quotes. Agree? But in C, you must write string inside of double quotes. So, let me quickly wrap this text with double quotes and make it string.

"hello, world"

Great! This string is not going to print in terminal on its own. We need to invoke a function on it to print and the function is printf(). This is how we use printf() function.

printf("hello, world")

C is one of those languages the required semicolon to complete the statement. In C, semicolon is not optional but required. And that way I need to write,

printf("hello, world");

Semicolon at the end. Great. But you know, compiled languages like C is different than interpreted language in terms of execution. In interpreted languages, the execution start from top and execute each statement or expression that comes in flow. But, in compiled language you need to tell the starting point - a point from where the compilation process starts. This is where the main() function comes in picture. Your program must contain one main() function and this is the function from where your program will going to compile.

In order to run our printf() statement, we need to put it inside of main() function this way.

main() {
  printf("hello, world");
}

This indentation inside of function is not required. It is just for readability purpose. But, it is required for this course. If your program contain confused indentation, you will likely lose the grade even if your project perfectly works!

You are going to use curly braces to define block like I did to define main() function block. Whatever statements we write inside of this curly braces, are considered part of the main() function.

After compilation of this main() function, it returns something. It returns an integer with 0 or greater than 0. Here, 0 means successful compilation and any other value than 0 mean something goes wrong with your program! Let’s add the type signature before the main() function to indicate, what this main() is going to be written and also write return 0 explicitly.

int main() {
  printf("hello, world");

  return 0;
}

Yes, this return statement should be at the end of main() function.

In C, you don’t get a single function by default and printf() is not an exception. You need to include a library in which this function is written. The library or header file is stdio.h and its standard header file that comes with C. You can include this file in our program like -

#include<stdio.h>

int main() {
  printf("hello, world");

  return 0;
}

You need to write the include statement at the top of your program and the blank line after this include statement is optional. But, again it is strongly recommended and required for this course.

That’s it! This is our hello, world program in C. It’s time to execute this program.

Execution

We need a compiler to execute any C program. For this purpose, we are going to use GCC. This is the compiler that comes with most of the GNU/Linux system. A quick --version command will let you know that C is installed on your system or not.

$ gcc --version
gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you get similar output, then you have gcc on your system else you need to install. In my case, I’ve gcc so I can go further and execute this program. The execution of C program done in two steps —

  1. Compiles the program,
  2. Executes the compiled program.

To compile the program, this command is used.

$ gcc hello.c -o hello

This will compile your hello.c program and after successful completion it will generate output (-o) with name hello. You will get nothing if compilation happen successfully in terminal. In my case, I don’t get anything, so that means my program execute successfully and has build hello. A quick ls will show you the same.

$ ls
hello.c hello

In order to execute this hello executable, I need to write

$ ./hello
hello, world

And we get the output! But, this is a little clumsy. A \n after the hello, world string will help. Let’s add that.

#include<stdio.h>

int main() {
  printf("hello, world\n");

  return 0;
}

Let’s compile and run the program again.

$ gcc hello.c -o hello && ./hello
hello, world

Here, I’ve combines both commands into single one using && terminal operator. You will going to use so many terminal commands in this course along with C. So, be ready!

Looks like we are running out of time for this lecture. I know you might have many questions on this program and execution process. But, let’s first try from your side at home and then in the next lecture you can ask questions.

Saturday, January 7, 2023

MERN: Workshop - Before We Start

JavaScript delenda est — Comment from HN

Long time ago, I gave the workshop on MERN stack with colleagues. Here, I'm publishing the notes based on that workshop with modifications to suit them as blog post.


You're currently reading the circulated pdf that we passed to team who are planning to attend the workshop. The pdf was circulated a week ago before the first session in this workshop to better prepare them.


The workshop is a seven weeks long workshop where we're going to talk/learn the MERN. Here, MERN means MongoDB, Express, React, and Node. Yes, we're going to talk/learn about all these technologies but not in this particular order. This workshop is live workshop where you're going to do the coding with us. That is the reason why you need couple of software on your computer in order to do the mentioned coding challenges. 

Following are the list of essential software need for the first session of the workshop. In future, we'll install more software as needed.

  • Node
  • NPM or Node Package Manager
  • Text Editor

Node & NPM

We're going to install the Node and NPM using Node Version Manager or NVM. With NVM, you can install multiple version of Node on your computer side-by-side without a problem.

Mac or GNU/Linux

If you're Mac or GNU/Linux, open the Installing and Updating and copy either curl or wget URL in terminal.

This will install the NVM on your computer. You need to re-start the terminal and run the following command to confirm the installation of NVM.

$ nvm --version
0.39.3

If you get some version as the output of this command, you've successfully installed the NVM on your computer.

Next we need to install Node and NPM using this NVM. It is quite simple as running following command.

$ nvm install node

This command will install the latest version of Node (with NPM) on your computer. After the installation is done, run following two commands to confirm the installation of Node and NPM.

$ node --version
v19.3.0

$ npm --version
9.2.0

Windows

If you're using Windows system, you need to nvm-windows. You can download the exe from release page and then you can easily install the exe on your Windows computer.

Once the installation is done, open the Command Prompt or PowerShell and run the following command to confirm the installation of NVM.

> nvm --version
1.1.10

Next we need to install Node and NPM using this NVM. It is quite simple as running following command.

> nvm install latest

This command will install the latest version of Node (with NPM) on your computer. After the installation is done, run following two commands to confirm the installation of Node and NPM.

> node --version
v19.3.0

> npm --version
9.2.0

Text Editor

We need text editor to write the code! We've many options including vim and emacs. But, we're going to use Visual Studio Code for this workshop and we suggest you to use even if you already have your favorite text editor.

You can easily download the Visual Studio Code from the official website for your operating system.

Prerequisites

Finally, these are the prerequisites for the works and all sessions.

  • You know HTML, CSS and JavaScript.
  • You know some server-side programming.
  • You know how to write and run terminal commands in Terminal or Command Prompt.
  • You know a little git.

You need to attend this and all following sessions, if you are planning to learn React.js, Vue.js or Angular. You are now ready for the workshop.

Monday, January 2, 2023

સવારામ બાપા રચિત તિથિ અથવા ગગન ગઢ રમવા હાલો

ક્યાંક સનમાનમાં ચરણ વંદન કરે, ક્યાંક સનમાનમાં વેદવાણી.

ક્યાંક સનમાનમાં કસુંબા રેડીયા, ક્યાંક સનમાનમાં ચા ને પાણી,
ક્યાંક સનમાનમાં કરે તેલ ફુલેલચોળી, નવરાવે અંગ લઈ તાતાં પાણી.

ક્યાંક સનમાનમાં ભોજન વિધવિધનાં, ક્યાંક સનમાનમાં સેકેલી ધાણી,
ક્યાંક સનમાનમાં ગાળો ખાવી પડે, ક્યાંક સનમાનમાં મધુરવાણી.

ક્યાંક સનમાન કરે સિદ્ધ સાચા ગણી, ક્યાંક સનમાન કરે નીચ જાણી,
સવો કહે સર્વનાં કર્મ સૌ ભોગવે, એમાં શું આપણે લાભ કે હાણી.


ગગન ગઢ રમવાને હાલો, નીરાશી પદમાં સદા માલો….ટેક

પડવે ભાળ પડી તારી, મધ્યો મધ્ય નીરખ્યા મોરારી
વાલમ પર જાવું હુ વારી; ગગન – ૧

બીજે બોલે બહુનામી, ઘટોઘટ વ્યાપી રહ્યા સ્વામી
જુગતીથી તમે જોઈલો અંતર જામી; ગગન – ૨

ત્રિજે તુરઈ વાજાં વાગે, સુરતા મારી સનસુખ રહી જાગે
માહ સુને મોરલીયું વાગે; ગગન – ૩

ચોથે ચંદ્ર ભાણ વાળી, જોવે કોઈ આપાપણાને ટાળી
ત્રીવેણી ઉપર નુર લ્યો નીહાળી; ગગન – ૪

પાંચમ પવન થંભ ઠેરી, લાગી મુને પ્રેમ તણી લેરી
સુરતા મારી શબ્દુમાં ઘેરી; ગગન – ૫

છઠે જોવો સનમુખ દ્વારો, ત્રીવેણી ઉપર નાયાનો આરો
ત્યાં તો સદા વરસે અમર ધારો; ગગન – ૬

સાતમે સમરણ જડયું સાચું, આતો કોઈ વીરલા જાણે વાતું
જડયું હવે આદુનું ખાતુ; ગગન – ૭

આઠમે અકળ કળા એની, વાતું હવે ક્યાં જઈ કરુ વ્રેહની
રહું હું તો શબ્દ નીસીમાં ધેની; ગગન – ૮

નુમે મારે નીરભે થયો નાતો, છોડાવ્યો જમપુરીથી જાતો
સતગુરુએ શબ્દ દીધો સાચો; ગગન – ૯

દશમે જડી દોર તણી ટેકી, મધ્યમાં મળ્યા અલખ એકાએકી
સુરતા મારી દંગ પામી દેખી; ગગન – ૧0

એકાદશી અવીધટ ધાટ એવો, શબ્દ લઈને સુરતાને સેવો
સદાય તમે સોહં પુરુષ સેવો; ગગન – ૧૧

દ્વાદસી દૂર નથી વાલો, સમજ વીના બારે ફરતો ઠાલો
સુખમણ સાથે પી લ્યો અમર પ્યાલો; ગગન – ૧૨

તેરસે વાળી ત્રિવેણી ઉપર ઘારા, જપુ નીજનામ તણી માળા
પ્રગટ્યા રવી ઉલટાયા અજવાળાં; ગગન – ૧૩

ચૌદસે કહ્યુ ચીત કરે નહી મારુ, થયું ઓચીંતુ અજવાળું
સતગુરુએ તોડયું વજર તાળું; ગગન – ૧૪

પુનમે દેખી પુરણ પદ પામી, મળ્યા જયારે ફુલગરજી સ્વામી
રહે છે સવો ચરણમાં શીસ નામી; ગગન – ૧૫


બધા ભજનિકો એ આ સરસ ભજન ગાયું છે , એમાં પણ નિરંજન પંડ્યા એ ગાયેલ મને વધુ પસંદ પડ્યું. https://www.youtube.com/watch?v=FKcFix8Y7Wg.

Friday, April 22, 2022

Article Worth of Content

I recently read a few books. After completing these books, I felt that the author is stretching the content by repeating the same idea again and again with different words, examples, and angles. What could have been covered in a concise article (or 4-5 pages) was extended into a full-length book. I noticed a similar pattern when reviewing an online course.

Tuesday, November 9, 2021

Assign Default Attributes Values While Creating an Instance

Consider the following example where we're creating a window instance of the ApplicationWindow.

var window = new Gtk.ApplicationWindow(this);

Once the window instance is created, we can go ahead and assign some default values to the attributes such as default_height, default_width, and title like this.

window.default_height = 400;
window.default_width = 200;
window.title = "hello, world";

All-in-all, we can have the following code (if you want to try out from your side to see the output).

public class Application : Gtk.Application {
  public Application() {
    Object(
      application_id: "com.github.username.reponame",
      flags: ApplicationFlags.FLAGS_NONE
    );
  }

  protected override void activate() {
    var window = new Gtk.ApplicationWindow(this);

    window.default_height = 350;
    window.default_width = 280;
    window.title = "hello, world";

    window.show_all();
  }
}

int main(string[] args) {
  var application = new Application();
  return application.run(args);
}

Vala provide a way to define the attributes' default values at the time of instance creation. In this way, we don't have to write it separately and we don't have to prefix each property with instance name. We can mentioned the properties in curly brackets.

This is how we can create an instance of ApplicationWindow, right!

var window = new Gtk.ApplicationWindow(this);

Instead of terminating the statement with semicolon at the end, let's add the curly brackets.

var window = new Gtk.ApplicationWindow(this) {

};


Within this curly brackets, let's assign the default values to attributes without prefixing the window and separate them by comma.

var window = new Gtk.ApplicationWindow(this) {
  default_height = 350,
  default_width = 280,
  title = "hello, world"
};

Don't forget to add ; after the closing curly bracket.

I find this lot cleaner! Here is the complete code, if you're interested to run.

public class Application : Gtk.Application {
  public Application() {
    Object(
      application_id: "com.github.username.reponame",
      flags: ApplicationFlags.FLAGS_NONE
    );
  }

  protected override void activate() {
    var window = new Gtk.ApplicationWindow(this) {
      default_height = 350,
      default_width = 280,
      title = "hello, world"
    };

    window.show_all();
  }
}

int main(string[] args) {
  var application = new Application();
  return application.run(args);
}

This is applicable to almost all Gtk widgets.


Saturday, November 6, 2021

Click on Button Doesn't Print Text in Terminal

I was working on the simple application where, as part of intermediate step, I need to print "Button Clicked!" text in terminal when button is clicked. I know that the Gtk.Button has support for clicked signal and I can connect it using .connect() method in following way.

button.clicked.connect(() => {
  stdout.printf("Button Clicked!");
});

But, this was not working as expected! If I click on button, nothing prints in terminal unless I terminate the running application and then I can see the "Button Clicked!" text. If I click on button four times, I was not seeing "Button Clicked" in terminal. But, as soon as I terminate the application, "Button Clicked!" is printed four times. So, it was working but not the way, I expected. The code was correct and I don't see any problem with code.

But then I found this answer on Stack Overflow. The only problem which I had in above code is absence of \n. I added and it works like the way I expected!

Here is the code snippet related to this issue (in case if you're interested).

public class Application : Gtk.Application {
  public Application() {
    Object(
      application_id: "com.github.username.reponame",
      flags: ApplicationFlags.FLAGS_NONE
    );
  }

  protected override void activate() {
    var window = new Gtk.ApplicationWindow(this) {
      default_height = 400,
      default_width = 300,
      title = "Button Click"
    };

    var button = new Gtk.Button.with_label("Click Me!") {
      margin = 12
    };

    button.clicked.connect(() => {
      stdout.printf("Button Clicked!\n");
    });

    window.add(button);
    window.show_all();
  }
}

int main(string[] args) {
  var application = new Application();
  return application.run(args);
}


Sunday, March 24, 2019

Free Software Sunday

You might have heard about the Open Source Friday initiative by GitHub to improve the contributions and awareness of Open Source Software. I like this idea and considering myself to do the same – contributing to software but not to Open Source. To Free Software. The Software that is listed on GNU's website or the software that is licensed under GNU GPL.  
 
I'm a full-time web developer and all Fridays are one of my busy scheduled days at the office. For me, it is not possible to spend a few hours in front of my laptop. Even for me, these are the days when I spend the least amount of time with my family and loved ones. So, I have done this another modification – Instead of Friday, it will be on Sunday.  
 
At this moment, I'm not quite sure about how I'll going to contribute to Free Software. It might be Code or Testing or Docs or Translation. I'm planning to go first with Docs and Translation for my native Gujarati language. After that as time permit and based on my knowledge I may move to other areas of contributions.  
 
Let's see how this work. I'll update this post after three months with experimental status.