Skip to main content

Posts

Showing posts with the label COMPUTER SCIENCE

OS

Hardware => Operating system => Application  OS Provide - Hardware Abstraction - Resource management Abstraction: B/W Application and hardware - Easy program writing - Reusable functionality - Portable Resource management - Multiple app but limited resource - Manage CPU, Memory, Network, Secondary Memory etc   --------------- CPU Each have a unique address - Memory addrs - IO Addrs - Memory Mapped IO addrs Memory addrs 32 bit process Range: 0- 2^32-1  ---------------- Process Stack Heap Data Text System call use to access resources of kernel mode  ------------------ Sharing the CPU - Multi-programming and multi-tasking - Sharing in multi-processor environments * Race conditions and synchronization * Scheduling * Isolation of the OS and user programs * Security mechanisms * Access control * Security assessment ------------------- CPU Vs RAM - RAM hold data CPU compute on data Memory Management - Fragmentation: Und...

HD Wallet key Generation

HD Wallet key Generation Example to generate HD wallet child key in golang. package main import ( "github.com/tyler-smith/go-bip32" "log" "github.com/btcsuite/btcutil/base58" ) func main(){ // root key rootKey := "xpub661MyMwAqRbcFPUpZvj3QydNRASDRHEZ1TyvTkhDTAPqytQLx7j8XWFEsnArLx9rbfHTCcCUfp6K75qcAqkp83ASXnCpiXWT5M6Hcc92wSV" decoded := base58.Decode(rootKey) masterKey, _ := bip32.Deserialize([]byte(decoded)) /* (m) / | \ / | \ m/0 m/1 m/2 ... . . . */ childKey, _ := masterKey.NewChildKey(2) // m/2 log.Println("child key: \n", childKey) }

Hello World in Go

Your First Program Traditionally the first program you write in any programming language is called a “Hello World” program – a program that simply outputs  Hello World  to your terminal. Let's write one using Go. First create a new folder where we can store our program. Create a folder named  ~/src/go_example . (Where  ~  means your home directory) From the terminal you can do this by entering the following commands: mkdir src/go_example touch src/go_example/main.go Using your text editor type in the following in the main.go: package main import "fmt" // this is a comment func main() { fmt.Println("Hello World") } Open up a new terminal and type in the following: cd src/go_example go run main.go You should see  Hello World  displayed in your terminal. The  go run  command takes the subsequent files (separated by spaces), compiles them into an executable saved in a temporary directory and then runs the program....

Android Keystore encryption and decryption

Android Keystore In this post we will learn how to store a key in android provider keystore and encrypt and decrypt. Keystore KeyStore ks = KeyStore.getInstance("AndroidKeyStore"); SecretKey key = new SecretKeySpec(keyByte, alg); KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(key); // store key in keystore ks.setEntry( "keyName", new KeyStore.SecretKeyEntry(secretKeyEntry.getSecretKey()), new KeyProtection.Builder(KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) .setBlockModes(KeyProperties.BLOCK_MODE_GCM) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) .build()); // get key from key store SecretKey keyStoreKey = (SecretKey) ks.getKey(" keyName", null); Encryption Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, keyStoreKey); byte[] encryptedByte = c...

Python Input Output

Python Input Output We use the print() function to output data to the standard output device (screen). Up till now, our programs were static. The value of variables were defined or hard coded into the source code. To allow flexibility we might want to take the input from the user. In Python, we have the input() function to allow this. The syntax for input() is s = input("Enter value: ") print (s )

Python Arithmetic

Python Arithmetic Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages print ( 2 + 2) print ( 50 - 5 * 6) print ( ( 50 - 5 * 6 ) / 4) print ( 8 / 5)

Python Control Flow

Python Control Flow if Statements The if statement is used for conditional execution x = 5 if x < 0 : print ( 'x is Negative' ) elif x == 0 : print ( 'x is Zero' ) elif x > 0 : print ( 'x is Positive' ) else : print ( 'x is not a number' ) The while statement The while statement is used for repeated execution as long as an expression is true x = 0 while x < 6 : print ( x ) x = x + 1 : for Statements In Python’s for statement iterates over the items of any sequence (a list or a string) fruits = ["apple", "orange", "banana", "cherry"] for fruit in fruits : print ( fruit ) The range() Function If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates arithmetic progressions for i in range ( 5 ): print ( i ) Output 0 1 2 3 4 More example on range range ( 5 , 10 )...

Python Variables

Python Variables Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. x = 5 y = "John" print (x) print (y) Variables do not need to be declared with any particular type and can even change type after they have been set. x = 5 # x is integer x = "John" # now x is a string Assign Value to Multiple Variables x, y = 5, 'John' print(x) print (y) You can also use the + character to add a variable to another variable x = "Python is" y = "awesome" print (x + y)

Python Comments

Python Comments In this post, We will learn about comments in Python. Comments can be used to explain Python code. Comments can be used to make the code more readable Single line comment # this is the first comment print ("Hello World") print ("Hello World") # this is the first comment Multi-line comment   # this is a comment # written in # more than on line "print ("Hello World") ''' this is a comment written in more than on line ''' "print ("Hello World")

Python Getting Started

Python Getting Started In this post, We will learn how to write first program in Python. Installation  Many system will have already Python installed. To check Python installed on Windows operating system run below command on windows command shell (cmd.exe). python --version To check Python installed on linux operating system run below command on Linux terminal. python --version Python Quick start Create a Python file hello_world.py here .py extension indicate that it is a python file. Let's write first Python program. Open hello_world.py in text editor and write below program in it. print ("Hello World") Run python file on command line. The way to run a python file is like this on the command line python hello_world.py Above program will print Hello World on your terminal.

Docker Installation Error

Docker Installation Error docker info Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/info: dial unix /var/run/docker.sock: connect: permission denied sudo docker info Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Fixes Install docker using below command sudo snap install docker

Trigonometry

Trigonometry The word ‘trigonometry’ means ‘triangle measurement’.It involves the ratios of the sides of right triangles and the angles. The main three ratios are called tangent, sin, and cosine. Being one of the most important topics for the  CAT exam , trigonometry requires the candidates to be well prepared with excessive practice to solve the related questions. There are some triangle questions which can be solved much faster if you can remember the trigonometric ratios involved, especially questions based on heights and distances. So, here is a detailed lesson on trigonometry for CAT topic along with various illustrations to help you understand the topic easily. There are three sides to a right-angled triangle which are named as follows depending on the angle.  Opposite Side The opposite side refers to the side opposite to the angle in question (θ). In this case, the opposite side is BC. Adjacent Side The Adjacent side is the side adjacent to angle...

Download Server Directory

Download Server Directory In this post we will learn how to download  all the file of a remote server directory or folder. Step Open your Ubuntu terminal and run below command wget -r -np -nH --cut-dirs=3 -R index.html <folder-url> Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Java Getter and Setter

Java Getter and Setter Java Getter and Setter Example class GetterAndSetter { private String name; // constructor GetterAndSetter(String name) { this.name = name; } // getter public String getName() { return this.name; } // setter public void setName(String name) { this.name = name; } } public class Main { public static void main(String[] args) { // instance of client class GetterAndSetter getterAndSetter = new GetterAndSetter("Rozgardesh"); System.out.println(getterAndSetter.getName()); } } Compile and Run javac Main.java javac Main Output Rozgardesh Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Rozgardesh (रोजगार देश)

Java Constructor

Java Constructor In this post we will learn how to create constructor in Java. class DemoClass { public int constructor1; public String constructor2; DemoClass(int constructor1) { this.constructor1 = constructor1; } DemoClass(String constructor2) { this.constructor2 = constructor2; } } public class Main { public static void main(String[] args) { DemoClass demoClass1 = new DemoClass(1); DemoClass demoClass2 = new DemoClass("Demo"); } } Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.                                                     Rozgardesh (रोजगार देश)

Create Virtual Env for Python3.7

Create Virtual Env for Python3.7 Install Python3.7  sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get install python3.7 Install Python3.7-Venv sudo apt-get install python3.7-venv Create Virtual Env python3.7 -m venv env Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

How to call parent class method from child class object in Java

How to call parent class method from child class object in Java Save below program in Main.java file class ParentClass { public void printParent() { System.out.println("Calling parent class method..."); } } class ChildClass extends ParentClass { public void printChild() { System.out.println("Calling child class method..."); } } public class Main { public static void main(String[] args) { ChildClass childClass = new ChildClass(); childClass.printParent(); } } Compile program javac Main.java Run program java Main Output Calling parent class method... Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Rust: String Vs str

What are the differences between Rust's `String` and `str`? String is the dynamic heap string type, like Vec: use it when you need to own or modify your string data. str is an immutable sequence of UTF-8 bytes of dynamic length somewhere in memory. Since the size is unknown, one can only handle it behind a pointer. This means that str most commonly appears as &str: a reference to some UTF-8 data, normally called a "string slice" or just a "slice". Prefer &str as a function parameter or if you want a read-only view of a string. String when you want to own and mutate a string. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.