Notes, summaries, assignments, exams, and exercises for Computer science for Other courses

Secure PHP File Upload Script for Word Documents

Computer science3.43 KB

Secure PHP Word Document Upload Script

This PHP script manages secure document uploads, specifically restricting files to the Microsoft Word format, validating file sizes, handling duplicate filenames, and saving the record to a MySQL database.

PHP Upload Code

<?php
// PROGRAMMING BEGINS //::::::::::::::::::::::::::::::: DOCUMENT
if ($success1) {
    // define() is a function that defines a constant. Equates to 300KB
    define('max_file_size', 3000000);
    define('UPLOAD_DIR2', 'documents/');

    $file = str_replace(' ', '_', $_FILES['file']['name']);
    
    // Calculate the maximum size of a file to upload
    $max = number_format(max_file_size / 2048, 1) . ' KB';
    
    // Define or calculate the file size
    $size = number_format(
...
Continue reading "Secure PHP File Upload Script for Word Documents" »

Database Normalization and Indexing Principles

Computer science3.08 KB

1. Functional Dependency (FD)

A functional dependency A → B means: if you know the value of attribute A, you can always determine the value of attribute B. In other words, no two rows can have the same A value but different B values.

Example: In a table Student(StudentID, Name, Email): StudentID → Name, Email (Given a StudentID, the Name and Email are always uniquely determined.)

2. Boyce-Codd Normal Form (BCNF)

A relation is in BCNF if, for every functional dependency X → Y, X is a superkey.

  • Compliance: Every determinant in the table is a candidate key—no changes needed.
  • Evaluation: Whenever there is a non-trivial FD X → Y where X is not a superkey. This means some attribute depends on only part of a key, or on a non-key attribute—causing
...
Continue reading "Database Normalization and Indexing Principles" »

Data Structures Master Cheat Sheet: CC-104 Exam Prep

Computer science8.93 KB

CC-104 Data Structures Master Cheat Sheet

1. High-Yield Formulas & Operations

  • 2D Array Address (Row-Major):
    Address = Base + Size × (i × TotalColumns + j)
  • 2D Array Address (Column-Major):
    Address = Base + Size × (j × TotalRows + i)
  • Circular Queue Index Increment:
    rear = (rear + 1) % MAX;
  • AVL Tree Balance Factor:
    Balance Factor = Height(Left Subtree) - Height(Right Subtree)
    (Valid values are strictly -1, 0, or 1. Anything else triggers rotation).
  • 3-Step Postfix Conversion Shortcut (A + B * C):
    1. Bracket by precedence: (A + (B * C))
    2. Move operators right of brackets: (A (B C)*)+
    3. Remove brackets: A B C * +

2. Mandatory Comparison Tables

Array vs. Linked List

FeatureArrayLinked List
Memory LayoutContiguous (sequential blocks)Non-contiguous (scattered
...
Continue reading "Data Structures Master Cheat Sheet: CC-104 Exam Prep" »

Essential Kubectl Commands: The Ultimate Kubernetes Cheat Sheet

Computer science7.76 KB

Key Takeaways

  • kubectl is the core tool for managing Kubernetes clusters, enabling you to inspect, deploy, troubleshoot, and scale workloads from the command line. Mastering flags like -n, -o, and --dry-run is essential.
  • Use a consistent workflow for debugging: get → describe → logs. This structured approach surfaces issues faster and reduces downtime.
  • Favor declarative over imperative commands by using YAML manifests with kubectl apply to promote version control and repeatability.

Kubernetes (K8s) is the industry standard for orchestrating containerized applications, but managing it can be complex. At the center of every Kubernetes workflow is kubectl, the command-line utility used to interact with clusters, deploy applications, and troubleshoot

...

Continue reading "Essential Kubectl Commands: The Ultimate Kubernetes Cheat Sheet" »

Java Stream Classes and ArrayList Methods

Computer science2.78 KB

What is a Stream and its Classes in Java?

Introduction
A Stream is a sequence of data that flows between a program and an input/output device. Streams are used to perform input and output operations in Java. Java provides stream classes in the java.io package for reading and writing data. Streams simplify file handling and data communication.

Types of Streams

1. Input Stream

Used to read data from a source such as a file, keyboard, or network. Data flows from the source to the program.

2. Output Stream

Used to write data to a destination such as a file, screen, or network. Data flows from the program to the destination.

Various Stream Classes in Java

1. FileInputStream

Used to read data from a file. It reads data in byte format and is suitable for reading...

Continue reading "Java Stream Classes and ArrayList Methods" »

Админ панель: управление пользователями в WPF с SQL Server и экспортом данных

Computer science3.31 KB

Админ панель







Панель администратора









Инициализация страницы

public AdminPage()
{
    InitializeComponent();
    LoadUsers();
}

Загрузка пользователей

private void LoadUsers()
{
    using (SqlConnection conn = new SqlConnection(connStr))
    {
        conn.Open();
        string sql = "SELECT id_User, Login, Block, FailPassword FROM Users";
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        System.Data.DataTable dt = new System.Data.DataTable();
        da.Fill(dt);
        dgUsers.ItemsSource = dt.DefaultView;
    }
}

private void btnRefresh_Click(object sender, RoutedEventArgs e) => LoadUsers();

Добавление пользователя

private
...
Continue reading "Админ панель: управление пользователями в WPF с SQL Server и экспортом данных" »

Implementing Cloud-Native Security Best Practices

Computer science2.79 KB

Objective

To implement robust cloud-native security controls, including Encryption, Access Management, and Network Security.


Core Security Principles

  • Encryption: Protects data at rest (stored) and in transit (moving).
  • Access Management (IAM): Ensures the Principle of Least Privilege by managing user roles and Multi-Factor Authentication (MFA).
  • Network Security: Uses VPCs, Firewalls, and DDoS protection to isolate resources and filter malicious traffic.

Implementation Procedure

1. Data Encryption

  • At Rest: Use services like AWS KMS, Google KMS, or Azure Key Vault to manage cryptographic keys. Enable encryption on storage buckets (S3/Blob) and use Transparent Data Encryption (TDE) for databases.
  • In Transit: Force HTTPS/TLS protocols for all web traffic.
...
Continue reading "Implementing Cloud-Native Security Best Practices" »

I is correct ii is correct

Computer science52.48 KB

1. Number Systems & Data Types

Question 1: What is the decimal equivalent of 0xBEEF?

  • 48879

Question 2: What is the decimal number equivalent of the octal value 0465?

  • 309

Question 3: What is the binary equivalent of decimal 135?

  • 0b10000111

Question 4: What is the octal equivalent of 0x5EED?

  • 057355

Question 5: What is the binary equivalent of 0xBEAD?

  • 0b1011111010101101

Question 6: What is the range of an unsigned byte?

  • 0 to 255

Question 7: What is the range of a signed word?

  • 0x80000000 to 0x7FFFFFFF

[Exam 1] Question 8: What is the two's complement representation of -128 expressed as a signed half word?

  • 0b1111111110000000

[Exam 1] Question 9: What is the Octal equivalent of Hex 0xDEAF?

  • 0157257

[Exam 1] Question 10: Convert 0xA1A to decimal:

  • 2586

[Exam 1] Question

...
Continue reading "I is correct ii is correct" »

Flutter Employee Management App: Add, Show, Search, Update & Delete

Computer science14.65 KB

Flutter Employee Management App

This Flutter project demonstrates a simple employee management system with login, navigation, and full CRUD operations (Add, Show, Search, Update, and Delete).

HomePage with Tabs

The first HomePage uses a DefaultTabController with five tabs: Add, Show, Search, Update, and Delete.

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 5,
      child: Scaffold(
        appBar: AppBar(
          title: const Text("Employee Management"),
          bottom: const TabBar(
            isScrollable: true,
            tabs: [
              Tab(text: "Add"),
              Tab(text: "Show"),
              Tab(text:
...
Continue reading "Flutter Employee Management App: Add, Show, Search, Update & Delete" »

Banker's Algorithm Implementation in C

Computer science3.52 KB

This program demonstrates the Banker's Algorithm, a classic deadlock avoidance strategy used in operating systems to manage resource allocation safely.

C Source Code

#include <stdio.h>

int n, m;
int alloc[10][10], max[10][10], need[10][10];
int avail[10], work[10], finish[10];

// Safety Algorithm
int checkSafety() {
    int seq[10], count = 0;

    for (int i = 0; i < n; i++) finish[i] = 0;
    for (int i = 0; i < m; i++) work[i] = avail[i];

    while (count < n) {
        int found = 0;
        for (int i = 0; i < n; i++) {
            if (!finish[i]) {
                int j;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > work[j]) break;
                }
                if (j == m)
...
Continue reading "Banker's Algorithm Implementation in C" »