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

Sort by
Subject
Level

CUDA Matrix Multiplication: Shared Memory

Classified in Computers

Written on in English with a size of 3.23 KB

CUDA Matrix Multiplication Using Shared Memory

This code demonstrates matrix multiplication in CUDA, leveraging shared memory for optimization. It includes two examples: a kernel using shared memory and a host-side implementation using the Thrust library.

CUDA Kernel with Shared Memory

The following CUDA kernel performs matrix multiplication using shared memory to optimize data access:


__global__ void matMulShared(int *A, int *B, int *C, int rowsA, int colsA, int colsB) {
    __shared__ int tile_A[TILE_SIZE][TILE_SIZE], tile_B[TILE_SIZE][TILE_SIZE];
    int row = blockIdx.y * TILE_SIZE + threadIdx.y, col = blockIdx.x * TILE_SIZE + threadIdx.x, temp = 0;
    for (int i = 0; i < (colsA + TILE_SIZE - 1) / TILE_SIZE; ++i) {
        if (row <
... Continue reading "CUDA Matrix Multiplication: Shared Memory" »

Essential PHP Programming Examples for Beginners

Posted by Anonymous and classified in Computers

Written on in English with a size of 1.26 KB

Addition of Two Numbers

<?php
if(isset($_POST['n1']) && isset($_POST['n2'])){
    $n1 = $_POST['n1'];
    $n2 = $_POST['n2'];
    $res = $n1 + $n2;
    echo "<h3>User Input Numbers:</h3>";
    echo "First Number = $n1 <br>";
    echo "Second Number = $n2 <br>";
    echo "Sum = $res";
}
?>

Enter Two Numbers:





PHP Conditional, Loops and Arrays Example

<?php
echo "<h3>Loop Example (1 to 5):</h3>";
for($i=1;$i<=5;$i++){
    echo "Number: $i <br>";
}
echo "<h3>Array Example:</h3>";
$fruits = array("Apple","Banana","Mango","Orange");
foreach($fruits as $f){
    echo "$f<br>";
}
?>

Student Registration Form

Name:

Email:

Gender:
Male
Female

Subjects:
Math
Science
English

Course:

... Continue reading "Essential PHP Programming Examples for Beginners" »

JDBC Drivers, JSP Tags, and ResultSet Implementation

Posted by Anonymous and classified in Computers

Written on in English with a size of 2.86 KB

JDBC Driver Types

Type 1: JDBC-ODBC Bridge

  • Converts JDBC calls to ODBC
  • ❌ Slow, platform dependent, and obsolete

Type 2: Native API Driver

  • Uses database-specific native libraries
  • ⚠️ Faster than Type 1 but platform dependent

Type 3: Network Protocol Driver

  • Uses middleware server to connect
  • 🌐 Platform independent but slower due to network

Type 4: Thin Driver

  • Directly connects to database using pure Java
  • ✅ Fast, platform independent, and most used

Tags in JSP

1. Directive Tags

  • Provide instructions to the JSP container
  • Syntax: <%@ ... %>
  • Example: page, include, taglib

2. Scripting Tags

  • Scriptlet Tag: Write Java code <% ... %>
  • Expression Tag: Display output <%= ... %>
  • Declaration Tag: Declare variables or methods <%! ... %>

3. Action

... Continue reading "JDBC Drivers, JSP Tags, and ResultSet Implementation" »

Python Logic for Sequences and Base Conversions

Classified in Computers

Written on in English with a size of 3.82 KB

Tile Sequence Validation Logic

The following function determines if a sequence of tiles is valid by checking their compatibility and adjusting their orientation if necessary.

def is_valid_sequence(seq: list[Tile]) -> bool:
    if len(seq) < 2:
        res = True
    else:
        if not are_compatible(seq[0], seq[1]):
            seq[0] = seq[0][1], seq[0][0]
        i = 1
        while i < len(seq) and are_compatible(seq[i - 1], seq[i]):
            if seq[i - 1][1] != seq[i][0]:
                seq[i] = seq[i][1], seq[i][0]
            i += 1
        res = i == len(seq)
    return res

Square-Free Number Verification

This function checks if a positive integer is square-free, meaning no prime factor has an exponent greater than one.

def
... Continue reading "Python Logic for Sequences and Base Conversions" »

Essential Network Packet Filtering Syntax Reference

Posted by Anonymous and classified in Computers

Written on in English with a size of 12.41 KB

Basic Protocol Filters

Use these filters to quickly isolate traffic based on common protocols:

  • arp (Address Resolution Protocol)
  • dns (Domain Name System)
  • http (Hypertext Transfer Protocol)
  • https (HTTP Secure)
  • icmp (Internet Control Message Protocol)
  • ip (Internet Protocol)
  • ipv6 (Internet Protocol Version 6)
  • ntp (Network Time Protocol)
  • smtp (Simple Mail Transfer Protocol)
  • ftp (File Transfer Protocol)
  • ssh (Secure Shell)
  • tls (Transport Layer Security)
  • udp (User Datagram Protocol)
  • tcp (Transmission Control Protocol)
  • dhcp (Dynamic Host Configuration Protocol)
  • bootp (Bootstrap Protocol)
  • radius (Remote Authentication Dial-In User Service)
  • snmp (Simple Network Management Protocol)
  • kerberos
  • smb (Server Message Block)
  • nbns (NetBIOS Name Service)
  • nbss (NetBIOS Session Service)
... Continue reading "Essential Network Packet Filtering Syntax Reference" »

Operating Systems: System Calls, Processes, and Forking

Classified in Computers

Written on in English with a size of 2.83 KB

Operating Systems: System Calls and File Descriptors

OS vs. User ModeRead vs. Write OperationsSpecial File Descriptors

System Calls and Kernel Mode

Public functions provided by the OS.

open(*pathname, Flags): Returns a file descriptor; returns -1 on error.

int main(int argc, char *argv[]) {
  int fd = open(argv[1], O_WRONLY | O_CREAT | O_EXCL, 0644);
  if (fd == -1) {
    printf("There was a problem creating \"%s\"!\n", argv[1]);
    return 1;
  }
  close(fd);
  return 0;
}

Handling Data Streams

read may not return all requested bytes; it returns the actual count read. It only returns 0 at the end of the file.

void copyContents(int sourceFD, int destinationFD) {
  char buffer[kCopyIncrement];
  while (true) {
    ssize_t bytesRead = read(sourceFD,
... Continue reading "Operating Systems: System Calls, Processes, and Forking" »

Assembly Language Programming: Code Analysis and Solutions

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.63 KB

Assembly Language Code Analysis and Solutions

Section 1: Instruction Correctness Check

.data

calculate WORD 100
wVal DWORD 2

Instructions:

  1. mov bl, calculate
  2. mov ax, wVal

Question 1: Are the above two instructions correct? If not, justify your claim. [2 marks]

Answer:

Both instructions are incorrect.

  • For the mov operation, the operands must generally be of the same size.
  • In instruction 1, bl is 8 bits (1 byte), but calculate is defined as a WORD (16 bits or 2 bytes). The operand sizes do not match.
  • In instruction 2, ax is 16 bits (2 bytes), but wVal is defined as a DWORD (32 bits or 4 bytes). The operand sizes do not match.

Section 2: Loop Pseudo-code

Question 2: Write the pseudo-code for the loop that calculates the sum of the integers 3 + 2 + 1. [2 marks]

... Continue reading "Assembly Language Programming: Code Analysis and Solutions" »

Python Fundamentals: Strings, Lists, Math, and Plotting Examples

Posted by Anonymous and classified in Computers

Written on in English with a size of 6.74 KB

P1: Python String Manipulation Techniques

Demonstrating String Operations

s = "hello"
print(s.capitalize())
print(s.upper())
print(s.rjust(100))
print(s.center(100))
print(s.replace('l','(M)'))
print(s)
print("don't")

Indexing

a = 'symbiosis2024'
print(a[2])

Negative Indexing

print(a[-1])
print(a[-6])

Slicing

print(a[9:12])
print(a[9:])
print(a[9:-1])
print(a[:8])
print(a[-12:-1])

Stride [start index:end index:step size]

print(a[0:13:2])
print(a[0::2])

Concatenation

b = 'hello'
c = 'world'
d = b + c
print(d)
e = b + " " + c
print(e)

Repetition

f = a * 3
print(f)
g = "2024"
print(g * 2)
print(a + '2')

Reversing a String

print(a[::-1])

Split

h = "sspu"
print(h.split()) # Returns a list
i = "05/08/2024"
print(i.split("/"))
j = "14:20:25"
print(j.split("
... Continue reading "Python Fundamentals: Strings, Lists, Math, and Plotting Examples" »

Nmap, Netcat, and Metasploit Commands Cheat Sheet

Classified in Computers

Written on in English with a size of 7.67 KB

Nmap Options

-PE: Quickly check if host is up.

-sn: Disable port scanning (host discovery).

-n: Disables DNS resolution (checks IP online without looking up hostnames).

-O: OS detection.

-A: OS detection, Version detection, Script scanning, traceroute.

-sV: Service detection (banner info, version).

-vV: Provides verbose output.

-sC: Scan with default scripts for additional info gathering.

--min-rate=5000: Ensures scan sends at least 5k packets per second.

nmap --script smb-enum-shares.nse -p 445 (ip): List shares and their properties.


To see scripts starting with X: ls /path/X

To execute script with script tracing: sudo nmap -script=smb-os-discovery -script-trace target_ip

To enumerate the SMB share files: sudo nmap -script=smb-enum-shares target_ip

Vulnerability... Continue reading "Nmap, Netcat, and Metasploit Commands Cheat Sheet" »

Assembly Instruction Set Categories and Functions

Posted by Anonymous and classified in Computers

Written on in English with a size of 5.73 KB

🧾 Data Transfer Instructions

These instructions are used to move data between registers, memory, and I/O ports.

InstructionUse
MOVTransfer data between registers or memory locations
PUSH / POPPerform stack operations (store/retrieve data)
XCHGExchange contents of two operands
IN / OUTInput from or output to a port
LEALoad Effective Address
LDS / LESLoad Pointer and Segment Register
XLATTranslate byte using a lookup table

➕ Arithmetic Instructions

These instructions perform basic mathematical operations.

InstructionUse
ADD / SUBAddition / Subtraction
ADC / SBBAdd/Subtract with Carry/Borrow
INC / DECIncrement / Decrement a value
MUL / IMULUnsigned / Signed Multiplication
DIV / IDIVUnsigned / Signed Division
NEGTwo's Complement (Negation)
CMPCompare operands
... Continue reading "Assembly Instruction Set Categories and Functions" »