Skip to main content

Posts

Showing posts with the label programming

Basic CLI Application Using Golang

Writing a Basic CLI Application Using Go Go is a great language for building command-line tools due to its simplicity and powerful standard library. In this article, we will go through how to create a simple CLI app in Go that accepts commands and flags from the user. Step 1: Install Go Before you start, ensure that Go is installed on your machine. You can download it from here . Once installed, verify by running: go version Step 2: Set Up Your Project Create a new folder for your project and navigate into it: mkdir cli-app cd cli-app Step 3: Write Your CLI App In your project folder, create a file called main.go . This is where we'll write our CLI code. package main import ( "flag" "fmt" "os" ) func main() { name := flag.String("name", "World", "a name to say hello to") flag.Parse() if len(os.Args) Step 4: Run the Application You...

Why Interfaces are Awesome in Go

Why Interfaces are Awesome in Go Language Go, or Golang, is known for being a simple, yet powerful programming language. One of the core concepts that makes Go stand out is interfaces . Interfaces in Go help you write flexible, reusable, and maintainable code. They allow different types to share common behaviors without worrying about the exact type behind the scenes. In this article, we'll dive into why interfaces are awesome, with easy-to-understand examples. We’ll also give some tips on how to make the best use of them in your Go programs. What is an Interface? An interface in Go defines a set of method signatures (rules), but it doesn't provide the implementation. Instead, any type that implements these methods can be said to "satisfy" the interface. This allows you to write code that can work with different types as long as they share certain behaviors. Basic Example of an Interface package main import "fmt" // Define an interface with ...

Hash Tables : Designing Hash Functions

In the last post , we saw how collision in handled in a hash table. Now its time to explore some real world scenarios because come on, what is the use of learning all this if we can't apply it in real world softwares. As we learned that open addressing and chaining were both good in different scenarios only if we met a condition that the keys are uniformaly distributed. But its not the application job to pass distributed keys to hash tables, its our job to map any key to some random location. We do this using a hash function (or prehash function, whatever term you prefer). A hash function should map the keys as uniform as possible. So lets discuss some decent hash functions to some high end hash functions. What Problems Does Hashing Solve ? Simple Implementation of Hash Table Collision Resolution Chaining Open Addressing Desining ...

Authentication System : Basic Design

Being a system administrator, it is our main concern to protect users' data from theft and corruption. Regarding theft, we focus in building a sophisticated but secure authentication system which can fulfill all the basic needs we discussed in the last article . In the previous 2 articles, we learned about authentication and authorization. Also we understood the complications in building a secure system which can prevent tresspassing. But we have not code anything yet to build something. So in this article we will be designing an authentication system which will provide the functionalities we want and which will help us understand how the tech giants like google have taken security to another level. We will be writing code in php but the same applies to other languages also. What we'll be using Blueprint Building the system Running the system Additional Care What we'll be using Lets see what are the languages we will be using and database plus som...

The Art of Debugging

Writing unorganised code for something to work is an easy task, just put anything anywhere and see if the result is coming or not. If the result comes out in first attempt then you are really lucky but normal people like me are not. Then what we should do to check where the problem is occuring, we put some print statements (or console.log) to check the result in various places and observe where the output is deviating from its path. Well, it itself is a good practise of debugging the code but it does not work always especially not with large projects. So what should we do then ? According to me, we should give debugger a chance to find the bugs in our program. Debugging is an important part of writing programs because it teaches you to write unit tests for the parts of the program where it can fail. To perform debugging, we need a debugger and thankfully we have one, gdb (GNU debugger). In this article we will start by seeing some basic debugging techniques which involves logging the...

Understanding Python Decorators

If you have ever wondered what those @something mean above a python function or method then you are going to have your answers now. This @something line of code is actually called a decorator. I have red from various articles about them but some of them were not able to clarify the concept of a decorator and what we can achieve with them. So in this post we'll learn a lot about python decorators. Here is a list of topics we'll be covering. What is python decorator Understanding the concept Multiple decorators on same function class method decorator Where can we use decorators What is python decorator A python decorator is nothing but a function which accepts your given function as a parameter and returns a replacement function. So its like something this def decorator(your_func): def replacement(your_func_args): #do some other work return replacement @decorator your_func(your_func_args): #your_func code Now when your_func gets called then...

See More of C

Why more of c ? Function Pointers Search and Sort Multi-Threaded Programming Time Functions Random Numbers String Conversion Process Creation and System commands execution DataBase Handling CGI Scripting More Links Why digging more of C ? Being a high level language and the features C support there is not a need to ask why should we learn more about C. C programs are relatively faster than most of other high level languages like python or java. That may be because C programs are compiled first or may be because C libraries and fucntions are more hardware oriented. But whatever is the reason, C programs are way better. I can show you an example of it to you. There is a program which corrects the spelling of a mis-spelled word like it changes "somethinh" to "something". Now here is the comparison between the programs written in C and than that written in python Property Program i...

Python : Learn it my way

Why Python The first question we should ask ourself before learning something is "Why should we learn it" .I don't know about other stuff but i can answer why should you learn python. Python is a scripting as well as programming language. What does that mean is we can use it for web servers, softwares etc. Also it has a vast open source community behind it which provides thousands of libraries, frameworks and applications based on python.Today, development is moving forward to use languages like python, perl , ruby etc. So if we want to keep ourself updated with latest technologies then we'll have to learn them.Python also becomes handy for GUI development.Learning python is considered to be easier than any other object oriented language. Is this a python tutorial ? Obviously not. This is not a python tutorial. I am just gonna show you the right path to get yourself into python. When i first faced python(during sublime plugin development), it seems so scary that i s...

Hybrid Apps : A New Prodigy

Hybrid Apps : The New Era What are hybrid apps ? Hybrid apps are the love children of web applications and java-based applications. Web applications are constructed using HTML, JavaScript, CSS, PHP and other web fundamental languages. These are run and operated on browsers so they are globally available on the web. On the other hand, java-based applications as the name suggest require java to construct them. These applications are stand-alone apps and may or may not require internet to work. Hybrid apps are the apps which are built using web development languages and are stand-alone applications which work like any other java based applications. If you are confused right now or curious to learn building these apps then keep reading because i am gonna list the features and the tools required to build your own simple app in less than 10 minutes. Features of Hybrid Apps Easy Languages As i told in the previous section, these apps are build using web development languages which a...

String Cloning

String Copy Functions Coders, programmers and all the rookies who are new to programming always use string copy functions.As the name suggests, these are standard library functions which copies one string into other.Here we'll discuss two standard functions: strcpy() : which copies the whole string into another strncpy() : which copies a part of one string into another Syntax The first function takes 2 arguments: strcpy(char *target, char *source) ; The second function takes 3 arguments: strncpy(char *target, char *source, int n) ; Here "n" represents the number of characters which are to be copied into another string Working Example #include #include int main() { int n ; char source[25], target[25] ; strcpy(source, "fetch-info.blogspot.com") ; strncpy(target, source, 10) ; printf("Source String: %s\n", source) ; printf("Target String: %s",target) ; return 0 ; } OUTPUT Source String: fetch-info.bl...

Bubble Sort

Bubble Sorting Among variaous other sorting algorithm, bubble sort algorithm is one of the popular and frequently used algorithm to sort elements either in ascending or descending order. Bubble sort algorithm starts by comparing the first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, you mustn't swap the element. Then, again second and third elements are compared and swapped if it is necessary and this process go on until last and second last element is compared and swapped. This completes the first step of bubble sort. If there are  n  elements to be sorted then, the process mentioned above should be repeated  n-1  times to get required result. But, for better performance, in second step, last and second last elements are not compared becuase, the prop...

Insertion Sorting-Some Extra Stuff

Insertion Sorting Intro:- Insertion sort is one of the many sorting algorithms which implements sorting in a very elegant way. It is much less efficient on large lists than more advanced algorithms such as  quicksort , heapsort, or  merge sort .Its algo is easy to understand.If the first few objects are already sorted, an unsorted object can be inserted in the sorted set in proper place. This is called insertion sort. An algorithm consider the elements one at a time, inserting each in its suitable place among those already considered (keeping them sorted). Insertion sort is an example of an incremental  algorithm; it builds the sorted sequence one number at a time. This is perhaps the simplest example of the incremental insertion technique, where we build up a complicated structure on n items by first building it on n − 1 items and then making the necessary changes to fix things in adding the last item. The given sequences are typically stored in arrays....