Thursday, May 1, 2025

MySQL Tutorial

  1. MySQL Introduction
  2. MySQL Server Installation
  3. MySQL SHOW, USE, DESCRIBE
  4. MySQL CREATE and DROP
  5. MySQL CREATE TABLE
  6. MySQL NULL and NOT NULL
  7. MySQL Data Types in Tables
  8. MySQL INSERT Values Into Table
  9. MySQL INSERT Alternatives
  10. MySQL Custom Reports
  11. MySQL SELECT DISTINCT
  12. MySQL WHERE Clause
  13. MySQL AND & OR Conditions
  14. MySQL NOT Condition
  15. MySQL ORDER BY - ASC & DESC
  16. MySQL UPDATE Data
  17. MySQL DELETE From Table
  18. MySQL LIKE - NOT LIKE
  19. MySQL WHERE IN - NOT IN
  20. MySQL LIMIT - Number of Rows
  21. MySQL BETWEEN Range
  22. MySQL TRUNCATE TABLE
  23. MySQL DROP TABLE, DROP DB
  24. MySQL JOINS - Preparations
  25. MySQL INNER JOIN Explained
  26. MySQL LEFT JOIN Explained
  27. MySQL RIGHT JOIN Explained
  28. MySQL UNION & UNION ALL
  29. MySQL AVG Function
  30. MySQL COUNT Function
  31. MySQL MAX, MIN Functions
  32. MySQL SUM Function
  33. MySQL UCASE, LCASE Functions
  34. MySQL MID Function
  35. MySQL LENGTH Function
  36. MySQL VIEWs ?
  37. MySQL HAVING Clause
  38. MySQL ALTER TABLE
  39. MySQL DEFAULT Values
  40. MySQL BACKUP, RESTORE Database

Django To-Do Tutorial

 

  1. To Do First Simple CMS
  2. To Do Creating Django App
  3. To Do Understanding Routing
  4. To Do Modeling Database
  5. To Do Improving Models
  6. To Do Listing Posts
  7. To Do Base Template
  8. To Do Navigation
  9. To Do Post Details
  10. To Do Redirects in Django
  11. To Do Html Forms
  12. To Do Add New Post

Django Tutorial

  1. Django Installation
  2. Django Creating Project
  3. Django Files, Project Structure
  4. Django Dev Server
  5. Django First Html Page
  6. Django URL Routing, Navigation
  7. Django Dynamic Navigation
  8. Django Base Template
  9. Django Include CSS
  10. Django Static Files
  11. Django Bootstrap 4
  12. Django Gallery, News Template

Bootstrap 4 Tutorial

 

  1. BS 4 Setup, First Page
  2. BS 4 Header, Footer
  3. BS 4 Local CSS, JS
  4. BS 4 Jumbotron, Colors
  5. BS 4 Grid System
  6. BS 4 Typography
  7. BS 4 Tables
  8. BS 4 Images
  9. BS 4 Buttons
  10. BS 4 Button Groups
  11. BS 4 Progress Bars
  12. BS 4 Badges
  13. BS 4 Alerts
  14. BS 4 List Groups
  15. BS 4 Pagination, Breadcrumbs
  16. BS 4 Cards
  17. BS 4 Navbars
  18. BS 4 Modals
  19. BS 4 Forms
  20. BS 4 Carousel

JavaScript Tutorial

 

  1. JS Introduction
  2. JS Setup, First Script
  3. JS Doctype, Functions
  4. JS Alerts, PopUp Boxes
  5. JS External, Inline JS
  6. JS Comments
  7. JS Variables
  8. JS Data Types
  9. JS Name Rules
  10. JS Functions
  11. JS Function Parameters
  12. JS Multiple Parameters
  13. JS Return Values
  14. JS Functions as Arguments
  15. JS Endless Loop, Infinite
  16. JS Global vs Local
  17. JS Numbers, Math Ops
  18. JS If Statement
  19. JS If Else, Functions
  20. JS If inside If
  21. JS Switch Statement
  22. JS For Loop
  23. JS While Loop
  24. JS Do While Loop
  25. JS Event Handlers
  26. JS On Mouse Over, Out
  27. JS Load, Unload Events
  28. JS Objects
  29. JS Object Creation
  30. JS Object Initialization
  31. JS Arrays
  32. JS Adding Elements, Arrays
  33. JS Concatenation, Arrays
  34. JS Join, Pop Elements
  35. JS Reverse, Push, Sort
  36. JS Prompt Box, User Input
  37. JS Random Numbers
  38. JS Get Window Size
  39. JS Redirects
  40. JS User Agent

C++ Object Oriented Tutorial

  1. C++ OO Introduction
  2. C++ OO Creating Objects
  3. C++ OO Run External Apps
  4. C++ OO String Operations
  5. C++ OO Data Types
  6. C++ OO Conflicting Objects
  7. C++ OO Pointer to Class
  8. C++ OO Scope Resolution Operator
  9. C++ OO Private vs Public Access
  10. C++ OO Getters and Setters
  11. C++ OO Constructors
  12. C++ OO Constructor Overloading
  13. C++ OO Default Constructor Parameters
  14. C++ OO Destructors
  15. C++ OO Static Variables in Classes
  16. C++ OO Static Method in Classes
  17. C++ OO Friend Functions
  18. C++ OO Inheritance
  19. C++ OO Protected vs Private
  20. C++ OO Public Inheritance
  21. C++ OO Protected Inheritance
  22. C++ OO Private Inheritance
  23. C++ OO Changing Access Levels
  24. C++ OO Multiple Inheritance
  25. C++ OO Constructor Calling Constructor
  26. C++ OO Method Overloading
  27. C++ OO Accessing Overloaded Methods
  28. C++ OO This Pointer
  29. C++ OO Objects As Parameters
  30. C++ OO Polymorphism, Virtual Functions
  31. C++ OO Pointers in Polymorphism
  32. C++ OO Pure Virtual Functions
  33. C++ OO Abstract Classes
  34. C++ OO Virtual Inheritance, Diamond Problem

C++ Tutorial

  1. C++ Introduction
  2. C++ First Program, Compilation
  3. C++ Line by Line Explanations
  4. C++ Strings
  5. C++ Variables
  6. C++ Telnet, Headers
  7. C++ Simple Calculator
  8. C++ Keyboard Input
  9. C++ Basic Math Operations
  10. C++ Data Types
  11. C++ If Statement
  12. C++ Comparing Numbers
  13. C++ If Else Statement
  14. C++ While Loop
  15. C++ Do While Loop
  16. C++ For Loop
  17. C++ Switch Statement
  18. C++ Run External Programs
  19. C++ Functions
  20. C++ Where to Create Functions
  21. C++ Functions With Arguments
  22. C++ Multiple Arguments
  23. C++ Default Arguments
  24. C++ Return From Function
  25. C++ Unary Scope Operator
  26. C++ Function Overloading
  27. C++ Random Numbers
  28. C++ Arrays
  29. C++ Printing Array Elements
  30. C++ Number of Elements
  31. C++ Sum of All Elements
  32. C++ Arrays in Functions
  33. C++ Multidimensional Arrays
  34. C++ Comments
  35. C++ Elements from Multidim. Array
  36. C++ Constants - const
  37. C++ Constants - #define
  38. C++ Pointers Explained
  39. C++ Pointer Declaration
  40. C++ Dereferencing a Pointer
  41. C++ Change Variable with Pointer
  42. C++ Null Pointer
  43. C++ Loop using Pointers
  44. C++ Array of Pointers
  45. C++ Pointers to Pointer
  46. C++ References
  47. C++ Multiple References
  48. C++ Pointers in Functions
  49. C++ Pointers as Arguments
  50. C++ References as Arguments
  51. C++ Struct - Data Structures
  52. C++ Struct - Data Extraction
  53. C++ Passing Struct to Function
  54. C++ Struct and Pointers
  55. C++ OO Introduction
  56. C++ OO Creating Objects
  57. C++ OO Run External Apps
  58. C++ OO String Operations
  59. C++ OO Data Types
  60. C++ OO Conflicting Objects
  61. C++ OO Pointer to Class
  62. C++ OO Scope Resolution Operator
  63. C++ OO Private vs Public Access
  64. C++ OO Getters and Setters
  65. C++ OO Constructors
  66. C++ OO Constructor Overloading
  67. C++ OO Default Constructor Parameters
  68. C++ OO Destructors
  69. C++ OO Static Variables in Classes
  70. C++ OO Static Method in Classes
  71. C++ OO Friend Functions
  72. C++ OO Inheritance
  73. C++ OO Protected vs Private
  74. C++ OO Public Inheritance
  75. C++ OO Protected Inheritance
  76. C++ OO Private Inheritance
  77. C++ OO Changing Access Levels
  78. C++ OO Multiple Inheritance
  79. C++ OO Constructor Calling Constructor
  80. C++ OO Method Overloading
  81. C++ OO Accessing Overloaded Methods
  82. C++ OO This Pointer
  83. C++ OO Objects As Parameters
  84. C++ OO Polymorphism, Virtual Functions
  85. C++ OO Pointers in Polymorphism
  86. C++ OO Pure Virtual Functions
  87. C++ OO Abstract Classes
  88. C++ OO Virtual Inheritance, Diamond Problem

HTML Tutorial

  1. HTML Introduction
  2. HTML Best Editor
  3. HTML First Page
  4. HTML Understanding CharSets
  5. HTML Comments
  6. HTML Keywords, Description
  7. HTML Headings H1 to H6
  8. HTML Paragraphs
  9. HTML Preformated Text
  10. HTML Font Size
  11. HTML Color
  12. HTML Font Face
  13. HTML Breaks, Horizontal Lines
  14. HTML Unordered Lists
  15. HTML Ordered Lists
  16. HTML Description Lists
  17. HTML Images
  18. HTML Images as Links
  19. HTML Tables
  20. HTML Forms - Data Entry
  21. HTML Insert YouTube
  22. HTML External CSS
  23. HTML Internal CSS
  24. HTML Inline CSS

Python Tutorial

  1. Python Intro - Why to Learn Python
  2. Python Installation, First Script
  3. Python Prompt, CMD, Terminal
  4. Python Syntax, Indentation
  5. Python Comments, DocStrings
  6. Python Variables, Contexts
  7. Python Concatenation, Types
  8. Python Numbers
  9. Python Casting, int, float, str
  10. Python Indexing, Space Striping
  11. Python Strings, len, lower, upper
  12. Python Replace, Split
  13. Python Keyboard Input
  14. Python Lists
  15. Python Length, Indexes
  16. Python Change, Insert, Append
  17. Python Delete, Remove, Pop
  18. Python Search, Clear
  19. Python Tuples
  20. Python Tuples, Operations
  21. Python Sets
  22. Python Sets, Add, Update
  23. Python Sets, Remove Discard
  24. Python Dictionaries
  25. Python Dictionary Operations
  26. Python If, elif, else
  27. Python While Loops
  28. Python Break, Continue
  29. Python For Loops
  30. Python Dictionary Iteration
  31. Python Functions
  32. Python Function Arguments
  33. Python Keyboard Arguments
  34. Python Return Multiple Values
  35. Python Iteration, Iter, Next
  36. Python Modules
  37. Python Standard Library Examples
  38. Python Files, Reading
  39. Python Files, Write, Append
  40. Python Delete Files, Folders
  41. Python Try, Except, Finally

Wednesday, April 30, 2025

How to Generate CTCSS Tones - Python

Change frequency and duration to suit your needs. 

import math
import numpy as np
import pyaudio

# Define the frequency and duration of the tone
frequency = 88.5  # Hz
duration = 360  # seconds

# Generate the audio samples
samples_per_second = 44100
num_samples = samples_per_second * duration
x = np.arange(num_samples)
samples = 0.5 * np.sin(2 * np.pi * frequency * x / samples_per_second)

# Initialize PyAudio
p = pyaudio.PyAudio()

# Open a stream and play the audio
stream = p.open(format=pyaudio.paFloat32,
                channels=1,
                rate=samples_per_second,
                output=True)
stream.write(samples.astype(np.float32).tostring())

# Close the stream and PyAudio
stream.stop_stream()
stream.close()
p.terminate()

First, the necessary modules are imported:

  • math for mathematical functions
  • numpy as np for scientific computing with Python
  • pyaudio for audio input/output

The frequency and duration of the audio tone to be generated are then defined with the following lines: 

frequency = 88.5  # Hz
duration = 360  # seconds

The number of samples to generate is calculated based on the desired frequency and duration, along with the samples per second value: 

samples_per_second = 44100
num_samples = samples_per_second * duration

A numpy array x is generated to represent the time values for the audio samples to be generated: 

x = np.arange(num_samples)

The audio samples themselves are then generated as a sine wave with an amplitude of 0.5: 

samples = 0.5 * np.sin(2 * np.pi * frequency * x / samples_per_second)

PyAudio is then initialized: 

p = pyaudio.PyAudio()

An audio stream is opened with the desired format (32-bit floating point), number of channels (1), and sample rate (samples per second). The output parameter is set to True to indicate that audio should be played through the stream: 

stream = p.open(format=pyaudio.paFloat32,
                channels=1,
                rate=samples_per_second,
                output=True)

The audio samples are then written to the stream, converted to a string of 32-bit floating point values: 

stream.write(samples.astype(np.float32).tostring())

Finally, the stream is closed and PyAudio is terminated: 

stream.stop_stream()
stream.close()
p.terminate()

C Program - strcmp() Function - Compares Two Strings Character by Character

This is a C program that demonstrates how to compare two strings using the strcmp() function. 

#include <stdio.h>
#include <string.h>

int main()
{

    char left[] = "aaa";
    char right[] = "aaa";

    int compare_strings;

    compare_strings = strcmp(left, right);

    //printf("%d", compare_strings);

    if (compare_strings == 0)
    {
        printf("Same");
    }
    else if (compare_strings < 0)
    {
        printf("Left Positionaly Smaller");
    }
    else if (compare_strings > 0)
    {
        printf("Left Positionaly Bigger");
    }

    return 0;

}

Result: 

Same
Process returned 0 (0x0)   execution time : 0.035 s
Press any key to continue.

Here's a breakdown of the code block by block: 

#include <stdio.h>
#include <string.h>

These are header files that are included in the program to provide definitions for functions used later in the code. stdio.h is included for standard input/output functions, while string.h is included for string manipulation functions. 

int main()
{

This is the main function of the program, where execution begins. The function returns an integer value (in this case, 0) to indicate the status of the program when it exits. 

    char left[] = "aaa";
    char right[] = "aaa";

    int compare_strings;

    compare_strings = strcmp(left, right);

This declares two character arrays, left and right, and initializes them both with the same string "aaa". It also declares an integer variable compare_strings.

The strcmp() function is used to compare the two strings. The function returns an integer value that indicates the lexicographic relation between the two strings. The value 0 indicates that the strings are equal, a negative value indicates that left is lexicographically smaller than right, and a positive value indicates that left is lexicographically larger than right

    if (compare_strings == 0)
    {
        printf("Same");
    }
    else if (compare_strings < 0)
    {
        printf("Left Positionaly Smaller");
    }
    else if (compare_strings > 0)
    {
        printf("Left Positionaly Bigger");
    }

This uses a series of if statements to check the value of compare_strings and print out a message based on the result.

If compare_strings is 0, it means that the two strings are equal, so the program prints "Same".

If compare_strings is negative, it means that left is lexicographically smaller than right, so the program prints "Left Positionaly Smaller".

If compare_strings is positive, it means that left is lexicographically larger than right, so the program prints "Left Positionaly Bigger"

    return 0;
}

This statement ends the main() function and returns the value 0 to indicate successful program execution.

C Program - strncpy() Function - Copy Specific Number of Characters from a String to Another String

This is a C program that demonstrates how to copy a specific number of characters from one string to another using the strncpy() function. 

//copy just specific number of charactes from string

#include <stdio.h>
#include <string.h>

int main()
{

    char some_string[] = "Hack The Planet, coz it's fun.";

    char target_string[20]; //ako stavis vise onda je garbage

    printf("Some String: %s \n", some_string);
    printf("Initial Target String: %s \n", target_string);

    strncpy(target_string, some_string, 10); //150, 5

    printf("Final Target String: %s \n", target_string);

    return 0;

}

Result: 

Some String: Hack The Planet, coz it's fun.
Initial Target String:
Final Target String: Hack The P

Process returned 0 (0x0)   execution time : 0.031 s
Press any key to continue.

Here's a breakdown of the code block by block: 

#include <stdio.h>
#include <string.h>

These are header files that are included in the program to provide definitions for functions used later in the code. stdio.h is included for standard input/output functions, while string.h is included for string manipulation functions. 

int main()
{

This is the main function of the program, where execution begins. The function returns an integer value (in this case, 0) to indicate the status of the program when it exits. 

    char some_string[] = "Hack The Planet, coz it's fun.";

    char target_string[20];

    printf("Some String: %s \n", some_string);
    printf("Initial Target String: %s \n", target_string);

This declares two character arrays: some_string and target_string. The former is initialized with a string literal, while the latter is left uninitialized.

The program then uses printf() to display the original input string some_string and an initial value of target_string on the console. 

    strncpy(target_string, some_string, 10);

    printf("Final Target String: %s \n", target_string);

The strncpy() function is used to copy the first 10 characters of some_string into target_string. The strncpy() function is similar to strcpy(), but it takes an additional argument that specifies the maximum number of characters to copy.

If the source string is shorter than the specified length, the remaining characters in the destination string are padded with null characters.

Finally, the program uses printf() to display the final value of target_string

    return 0;
}

This statement ends the main() function and returns the value 0 to indicate successful program execution.

C Program - strcpy() Function - Copy Content of One String into Another String

This is a C program that demonstrates the use of the string manipulation functions in the C standard library. The program prompts the user to input a string using the gets() function and then copies the string into a new character array using the strcpy() function. 

#include <stdio.h>
#include <string.h>

int main()
{

    //char some_string[] = "This is some string.";

    char some_string[100];

    printf("Enter Some String: \n");
    gets(some_string);

    char target_string[10];

    printf("Some String: %s \n", some_string);
    printf("Initial Target String: %s \n", target_string);

    strcpy(target_string, some_string);

    printf("Final Target String: %s \n", target_string);

    /*
    for (int x = 0; x < strlen(target_string); x++) {
        printf("%c \n", target_string[x]);
    }
    */

    return 0;

}

Result: 

Enter Some String:
this is original string
Some String: this is original string
Initial Target String:
Final Target String: this is original string

Process returned 0 (0x0)   execution time : 10.649 s
Press any key to continue.

Here's an explanation of each block of code in the program: 

#include <stdio.h>
#include <string.h>

These are header files that are included in the program to provide definitions for functions used later in the code. stdio.h is included for standard input/output functions, while string.h is included for string manipulation functions. 

int main()
{

This is the main function of the program, where execution begins. The function returns an integer value (in this case, 0) to indicate the status of the program when it exits. 

    char some_string[100];

    printf("Enter Some String: \n");
    gets(some_string);

This declares a character array called some_string with a size of 100 and prompts the user to input a string using the gets() function. The gets() function reads a line of text from standard input and stores it in the some_string array. However, as mentioned earlier, using gets() is not recommended due to potential buffer overflow vulnerabilities. 

    char target_string[10];

    printf("Some String: %s \n", some_string);
    printf("Initial Target String: %s \n", target_string);

    strcpy(target_string, some_string);

    printf("Final Target String: %s \n", target_string);

This declares a new character array called target_string with a size of 10 and then uses the printf() function to display the original input string some_string and an initial value of target_string on the console.

The strcpy() function is then used to copy the contents of some_string into target_string. This replaces the original contents of target_string with the input string.

Finally, the program uses printf() to display the final value of target_string

    return 0;
}

This statement ends the main() function and returns the value 0 to indicate successful program execution.

C Program - strcat() Function - How to Concatenate Strings in C

This code combines two input strings entered by the user using the strcat() function from the string.h library. 

#include <stdio.h>
#include <string.h> //strcat() function

int main()
{

    char first_string[100];
    char second_string[100];

    printf("First String: ");
    gets(first_string);

    printf("Second String: ");
    gets(second_string);

    strcat(first_string, second_string);
    printf("Combination: %s \n", first_string);

    return 0;

}

Result: 

First String: some
Second String:  string
Combination: some string

Process returned 0 (0x0)   execution time : 17.672 s
Press any key to continue.

Here's a line-by-line explanation: 

#include <stdio.h>
#include <string.h> //strcat() function

int main()
{

    char first_string[100];
    char second_string[100];

The program includes the necessary header files, and defines two character arrays with a size of 100 each. 

    printf("First String: ");
    gets(first_string);

    printf("Second String: ");
    gets(second_string);

The program prompts the user to enter two strings using printf() function and reads them using the gets() function.

Note: gets() function is considered unsafe and is deprecated in modern C. It is recommended to use fgets() instead. 

    strcat(first_string, second_string);
    printf("Combination: %s \n", first_string);

    return 0;

}

The program uses the strcat() function to concatenate the two strings, storing the result in the first_string variable. The concatenated string is then printed to the console using printf() function. Finally, the program returns 0 to indicate successful completion.

C Program - strlen() Function Example - Find the Length of a String

This program prompts the user to enter a string and then calculates and displays the length of the entered string. The program continues to prompt the user for input until the program is terminated. 

#include <stdio.h>
#include <string.h>

int main()
{

    char some_string[100];
    int length;

    while (1)
    {
        printf("Enter String: \n");
        gets(some_string);

        length = strlen(some_string);
        printf("String Length for %s is %d: \n", some_string, length);
        printf("-------------------------------------- \n");
    }

    return 0;
}

Result: 

Enter String:
some string
String Length for some string is 11:
--------------------------------------
Enter String:
test
String Length for test is 4:
--------------------------------------
Enter String:

Here's a line-by-line explanation of the code: 

#include <stdio.h>
#include <string.h>

This program includes the standard input/output library and the string library. 

int main()
{
    char some_string[100];
    int length;

This declares a character array some_string of size 100 to store the user input and an integer length to store the length of the input string. 

    while (1)
    {
        printf("Enter String: \n");
        gets(some_string);

This is a loop that prompts the user to enter a string and reads it from the console using gets() function. gets() reads the input as a character string, which is then stored in some_string.

Note: gets() is not safe to use, as it does not check the length of the input, so it can cause a buffer overflow if the input string is larger than the size of the array. 

        length = strlen(some_string);
        printf("String Length for %s is %d: \n", some_string, length);
        printf("-------------------------------------- \n");
    }

This calculates the length of the input string using the strlen() function and stores it in the length variable. The length is then printed to the console using printf() function. 

    return 0;
}

This ends the main function and returns 0, indicating successful execution of the program.

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...