Notes, summaries, assignments, exams, and problems for Computers

Sort by
Subject
Level

Python Best Practices: Style, Concepts, and Comprehensions

Classified in Computers

Written on in English with a size of 386.58 KB

Python Coding Style: PEP 8

PEP 8: Indentation: Use 4 spaces. Line Length: Limit to 79 characters. Imports: Import on separate lines. Naming: Follow naming conventions. Comments: Explain non-obvious code. Whitespace: Use blank lines judiciously. Function Arguments: Use spaces after commas. Annotations: Follow type annotation guidelines.

Documentation: Use docstrings. Vertical Whitespace: Separate code logically. Imports Formatting: Organize import statements. Avoid Wildcard Imports: Be explicit. Consistency: Maintain consistency in style.

Four Core Programming Concepts

Four Big Programming Concepts: Abstraction and encapsulation, Parameterization, Iteration (loops), Expressions (calculations).

Understanding NamedTuple

NamedTuple: Named Fields: namedtuple... Continue reading "Python Best Practices: Style, Concepts, and Comprehensions" »

JavaScript Fundamentals: Quick Reference Cheat Sheet

Classified in Computers

Written on in English with a size of 2.61 KB

JavaScript Fundamentals Cheat Sheet

1. Variables

  • let: Used to declare variables that are block-scoped. This means they only exist within the block they are defined in (e.g., inside a loop or an if statement).
  • const: Used for constants, which are also block-scoped. Once assigned a value, they cannot be reassigned.
  • var: Declares variables that are function-scoped. This can lead to issues with variable hoisting and is generally less preferred in modern JavaScript.

2. Functions

  • Functions are reusable blocks of code designed to perform a specific task. They can take parameters (inputs) and can return values.
  • Functions can be defined in different ways, including traditional function declarations and arrow functions, which provide a more concise syntax.

3.

... Continue reading "JavaScript Fundamentals: Quick Reference Cheat Sheet" »

Neural Networks: Neurons, Activation, Structure

Classified in Computers

Written on in English with a size of 3.62 KB

Biological Neurons

A biological neuron is the fundamental unit of the nervous system, responsible for transmitting information throughout the body. It consists of three main parts:

  • Dendrites: These are branch-like structures that receive signals from other neurons and transmit them to the cell body.
  • Cell Body (Soma): Contains the nucleus and other essential organelles responsible for processing information.
  • Axon: A long, thread-like extension that carries nerve impulses away from the cell body to other neurons, muscles, or glands.

Neurons communicate using electrical and chemical signals through synapses, where neurotransmitters help in transmitting the signals. The brain contains billions of neurons that work together to perform cognitive functions,... Continue reading "Neural Networks: Neurons, Activation, Structure" »

Understanding Constructors and Class Variables in OOP

Classified in Computers

Written on in English with a size of 3.89 KB

Constructor

A constructor is a special method in object-oriented programming that is automatically called when an instance (object) of a class is created. The main purpose of a constructor is to initialize the object's attributes (properties) and allocate resources if needed. Constructors have the same name as the class and do not have a return type.

Example of a Constructor

Here is an example in Python:

class Person:
    def __init__(self):
        self.name = "John Doe"
        self.age = 30

# Creating an instance of the Person class
person = Person()

print(person.name)  # Output: John Doe
print(person.age)   # Output: 30

In this example, __init__ is the constructor method in the Person class. It initializes the name and age attributes of the... Continue reading "Understanding Constructors and Class Variables in OOP" »

Cache Write Policies & Virtual Memory: A Deep Dive

Classified in Computers

Written on in English with a size of 3.47 KB

Cache Write Policies

Write-Through

  • Definition: Writes data to both the cache and main memory simultaneously.
  • Synchronization: Cache and main memory are always synchronized.
  • Write Speed: Slower, because every write goes to both cache and memory.
  • Data Integrity: Ensures data in both cache and main memory is identical.
  • CPU Performance Impact: Slower, due to the additional write to main memory.
  • Use Cases: Ideal for systems where data consistency is critical (e.g., databases).
  • Cache Miss Handling: Writes to both cache and memory on a miss.
  • Complexity: Simple to implement; doesn't require tracking of data in the cache.

Write-Back

  • Definition: Writes data to the cache first and only writes to memory when the cache line is evicted.
  • Synchronization: Cache and main
... Continue reading "Cache Write Policies & Virtual Memory: A Deep Dive" »

Key Concepts: Node.js Modules, Express Routing, Body Parser

Classified in Computers

Written on in English with a size of 6.67 KB

Understanding Node.js Modules & Core Functionality

In Node.js, modules are fundamental. They represent reusable blocks of code that can be exported from one file and imported into another, promoting a modular and organized application structure. Node.js features a built-in module system, allowing developers to utilize core modules, create custom modules, or integrate third-party modules.

Core Modules in Node.js

Core modules are pre-packaged with Node.js, offering essential functionalities for common tasks like file system operations, HTTP request handling, and path manipulation.

Some commonly used core modules in Node.js are:

  • fs (File System): For interacting with the file system.
  • http (HTTP): For creating HTTP servers and clients.
  • path (Path)
... Continue reading "Key Concepts: Node.js Modules, Express Routing, Body Parser" »

Java Programming: Classes, Objects, and Key Concepts

Classified in Computers

Written on in English with a size of 5.28 KB

Classes (الصفوف)

  • A class consists of variables (fields) and methods.
  • Variables are data members of a class.
  • Methods are functions that define the class's behavior.

Variables (المتغيرات)

  • Declared with a data type and a name.
  • Can be public or private.
  • Examples: int age, String name.

Methods (الأساليب)

  • Functions that perform specific tasks.
  • Can have parameters and return values.
  • Types:
    • Void methods: Don't return a value.
    • Return type methods: Return a value.
    • Static methods: Can be called without creating an object.
    • Instance methods: Require an object to be called.
    • Abstract methods: Declared without a body; used in abstract classes.
    • Overloaded methods: Multiple methods with the same name but different parameters.

Constructors (البناؤون)

... Continue reading "Java Programming: Classes, Objects, and Key Concepts" »

Programming Language Fundamentals: Core Concepts

Posted by Anonymous and classified in Computers

Written on in English with a size of 7.28 KB


1. Why Study Programming Language Concepts?

  • Expressiveness: Leverage diverse language features

  • Selection: Match language to task (e.g., LISP for AI, PHP for web)

  • Learning: Foundations ease uptake of new languages

  • Efficiency: Choose constructs (recursion vs. iteration) for performance

  • Maintenance: Better code reuse and understanding


2. Programming Domains and Typical Languages

DomainFocusLanguage Example
ScientificFloating-point computationsFortran
BusinessReports, decimals, textCOBOL
Artificial IntelligenceSymbolic processing, linked listsLISP/Prolog
SystemsEfficiency, low-level controlC
WebMarkup, scripting, general-purposeHTML/JS/PHP/Java

3. Language Categories

  • Imperative: Variables + assignment + iteration (C, Java, Python, Perl)

  • Functional: Computation

... Continue reading "Programming Language Fundamentals: Core Concepts" »

C Code Examples: Data Structures and Algorithms

Classified in Computers

Written on in English with a size of 5.54 KB

Recursive Binary Tree Traversals

Inorder Traversal:

void inorder(struct node *root)
{
  if(root != NULL)
  {
    inorder(root->left);
    printf("%d\t", root->data);
    inorder(root->right);
  }
}

Preorder Traversal:

void preorder(struct node *root)
{
  if(root != NULL)
  {
    printf("%d\t", root->data);
    preorder(root->left);
    preorder(root->right);
  }
}

Postorder Traversal:

void postorder(struct node *root)
{
  if(root != NULL)
  {
    postorder(root->left);
    postorder(root->right);
    printf("%d\t", root->data);
  }
}

Linked List Operations

Search

void search(struct node *head,int key)
{
  struct node *temp = head;
  while(temp != NULL)
  {
    if(temp->data == key)
      printf("key found");
    temp =
... Continue reading "C Code Examples: Data Structures and Algorithms" »

Digital Logic: Moore's Law, Logic Gates, and Number Systems

Classified in Computers

Written on in English with a size of 708.55 KB

Lecture 1: Moore's Law

Moore's Law: The number of transistors on microchips doubles every two years.

Lecture 2: Logic Gates

I7WgAAAABJRU5ErkJggg==

i3AAAAABJRU5ErkJggg==

+NnQQWHnrkU5hEgARmEjCXFieBuVQxHFZoESCBhRZfu1ongdmFNPtxFQIkMFepI+jBkMCCho4VvYwACczL2qMNLDy0x6cIGoEjR45Iq1atZNWqVbqNnTt3SpUqVYJujxWdQYArMGdwZ68OI4AY19dff10GDBggbdu2lblz50p8fLzDo2L3ZhEggZlFjOXDBgEEmaekpEhcXBzJy6NaJYF5VHEcNhEgAiIkMM4CIkAEPIsACcyzquPAiQARIIFxDhABIuBZBEhgnlUdB04EiAAJjHOACBABzyJAAvOs6jhwIkAESGCcA0SACHgWARKYZ1XHgRMBIkAC4xwgAkTAswiQwDyrOg6cCBABEhjnABEgAp5FgATmWdVx4ESACJDAOAeIABHwLAIkMM+qjgMnAkSABMY5QASIgGcRIIF5VnUcOBEgAiQwzgEiQAQ8iwAJzLOq48CJABEggXEOEAEi4FkESGCeVR0HTgSIAAmMc4AIEAHPIkAC86zqOHAiQAT+DyAtVcWtdpgpAAAAAElFTkSuQmCC

PKhJg4vKJJngcj4CICTBwugs1dMQJeQYCJwyua5HkwAi4iwMThItjcFSPgFQSYOLyiSZ4HI+AiAkwcLoLNXTECXkGAicMrmuR5MAIuIsDE4SLY3BUj4BUEmDi8okmeByPgIgJMHC6CzV0xAl5BgInDK5rkeTACLiLAxOEi2NwVI+AVBJg4vKJJngcj4CICTBwugs1dMQJeQYCJwyua5HkwAi4iwMThItjcFSPgFQSYOLyiSZ4HI+AiAkwcLoLNXTECXkGAicMrmuR5MAIuIsDE4SLY3BUj4BUEmDi8okmeByPgIgJMHC6CzV0xAl5BgInDK5rkeTACLiLAxOEi2NwVI+AVBP4HSdmP4LA25GYAAAAASUVORK5CYII=

5hQAAAAASUVORK5CYII=

eg8CIAACIAACfhGAQPiFDYVAAARAAARAwNkEIBDOjj96DwIgAAIgAAJ+EYBA+IUNhUAABEAABEDA2QT+D4sjTswCubX7AAAAAElFTkSuQmCC

o3LOcXr2Tof4HmKwTSBU6n03g8Hv9jfn5+pseNz2fo4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXYBQ99+AfITIBAvYOjjKxaQAIF2AUPffgHyEyAQL2Do4ysWkACBdgFD334B8hMgEC9g6OMrFpAAgXaBf18koFmMFdorAAAAAElFTkSuQmCC

wFbJNthuSOezwAAAABJRU5ErkJggg==

AND, OR, and NOT gates are universal.

Logic word problem steps:

Example: In a bank, there were four employees: the bank manager, assistant manager, teller, and the security guard. The bank has a single vault for the storage of their money. This vault was designed so that it needs four signals to open it. These four signals are from the bank manager, assistant manager, teller, and the security guard. For the vault to open, it needs the following conditions:

  1. No single employee can open the vault.
  2. It can be opened with three employees as long as one of them is the manager.
  3. It can be opened by the manager together with the assistant
... Continue reading "Digital Logic: Moore's Law, Logic Gates, and Number Systems" »