- MySQL Introduction
- MySQL Server Installation
- MySQL SHOW, USE, DESCRIBE
- MySQL CREATE and DROP
- MySQL CREATE TABLE
- MySQL NULL and NOT NULL
- MySQL Data Types in Tables
- MySQL INSERT Values Into Table
- MySQL INSERT Alternatives
- MySQL Custom Reports
- MySQL SELECT DISTINCT
- MySQL WHERE Clause
- MySQL AND & OR Conditions
- MySQL NOT Condition
- MySQL ORDER BY - ASC & DESC
- MySQL UPDATE Data
- MySQL DELETE From Table
- MySQL LIKE - NOT LIKE
- MySQL WHERE IN - NOT IN
- MySQL LIMIT - Number of Rows
- MySQL BETWEEN Range
- MySQL TRUNCATE TABLE
- MySQL DROP TABLE, DROP DB
- MySQL JOINS - Preparations
- MySQL INNER JOIN Explained
- MySQL LEFT JOIN Explained
- MySQL RIGHT JOIN Explained
- MySQL UNION & UNION ALL
- MySQL AVG Function
- MySQL COUNT Function
- MySQL MAX, MIN Functions
- MySQL SUM Function
- MySQL UCASE, LCASE Functions
- MySQL MID Function
- MySQL LENGTH Function
- MySQL VIEWs ?
- MySQL HAVING Clause
- MySQL ALTER TABLE
- MySQL DEFAULT Values
- MySQL BACKUP, RESTORE Database
Thursday, May 1, 2025
MySQL Tutorial
Bootstrap 4 Tutorial
- BS 4 Setup, First Page
- BS 4 Header, Footer
- BS 4 Local CSS, JS
- BS 4 Jumbotron, Colors
- BS 4 Grid System
- BS 4 Typography
- BS 4 Tables
- BS 4 Images
- BS 4 Buttons
- BS 4 Button Groups
- BS 4 Progress Bars
- BS 4 Badges
- BS 4 Alerts
- BS 4 List Groups
- BS 4 Pagination, Breadcrumbs
- BS 4 Cards
- BS 4 Navbars
- BS 4 Modals
- BS 4 Forms
- BS 4 Carousel
JavaScript Tutorial
- JS Introduction
- JS Setup, First Script
- JS Doctype, Functions
- JS Alerts, PopUp Boxes
- JS External, Inline JS
- JS Comments
- JS Variables
- JS Data Types
- JS Name Rules
- JS Functions
- JS Function Parameters
- JS Multiple Parameters
- JS Return Values
- JS Functions as Arguments
- JS Endless Loop, Infinite
- JS Global vs Local
- JS Numbers, Math Ops
- JS If Statement
- JS If Else, Functions
- JS If inside If
- JS Switch Statement
- JS For Loop
- JS While Loop
- JS Do While Loop
- JS Event Handlers
- JS On Mouse Over, Out
- JS Load, Unload Events
- JS Objects
- JS Object Creation
- JS Object Initialization
- JS Arrays
- JS Adding Elements, Arrays
- JS Concatenation, Arrays
- JS Join, Pop Elements
- JS Reverse, Push, Sort
- JS Prompt Box, User Input
- JS Random Numbers
- JS Get Window Size
- JS Redirects
- JS User Agent
C++ Object Oriented Tutorial
- C++ OO Introduction
- C++ OO Creating Objects
- C++ OO Run External Apps
- C++ OO String Operations
- C++ OO Data Types
- C++ OO Conflicting Objects
- C++ OO Pointer to Class
- C++ OO Scope Resolution Operator
- C++ OO Private vs Public Access
- C++ OO Getters and Setters
- C++ OO Constructors
- C++ OO Constructor Overloading
- C++ OO Default Constructor Parameters
- C++ OO Destructors
- C++ OO Static Variables in Classes
- C++ OO Static Method in Classes
- C++ OO Friend Functions
- C++ OO Inheritance
- C++ OO Protected vs Private
- C++ OO Public Inheritance
- C++ OO Protected Inheritance
- C++ OO Private Inheritance
- C++ OO Changing Access Levels
- C++ OO Multiple Inheritance
- C++ OO Constructor Calling Constructor
- C++ OO Method Overloading
- C++ OO Accessing Overloaded Methods
- C++ OO This Pointer
- C++ OO Objects As Parameters
- C++ OO Polymorphism, Virtual Functions
- C++ OO Pointers in Polymorphism
- C++ OO Pure Virtual Functions
- C++ OO Abstract Classes
- C++ OO Virtual Inheritance, Diamond Problem
C++ Tutorial
- C++ Introduction
- C++ First Program, Compilation
- C++ Line by Line Explanations
- C++ Strings
- C++ Variables
- C++ Telnet, Headers
- C++ Simple Calculator
- C++ Keyboard Input
- C++ Basic Math Operations
- C++ Data Types
- C++ If Statement
- C++ Comparing Numbers
- C++ If Else Statement
- C++ While Loop
- C++ Do While Loop
- C++ For Loop
- C++ Switch Statement
- C++ Run External Programs
- C++ Functions
- C++ Where to Create Functions
- C++ Functions With Arguments
- C++ Multiple Arguments
- C++ Default Arguments
- C++ Return From Function
- C++ Unary Scope Operator
- C++ Function Overloading
- C++ Random Numbers
- C++ Arrays
- C++ Printing Array Elements
- C++ Number of Elements
- C++ Sum of All Elements
- C++ Arrays in Functions
- C++ Multidimensional Arrays
- C++ Comments
- C++ Elements from Multidim. Array
- C++ Constants - const
- C++ Constants - #define
- C++ Pointers Explained
- C++ Pointer Declaration
- C++ Dereferencing a Pointer
- C++ Change Variable with Pointer
- C++ Null Pointer
- C++ Loop using Pointers
- C++ Array of Pointers
- C++ Pointers to Pointer
- C++ References
- C++ Multiple References
- C++ Pointers in Functions
- C++ Pointers as Arguments
- C++ References as Arguments
- C++ Struct - Data Structures
- C++ Struct - Data Extraction
- C++ Passing Struct to Function
- C++ Struct and Pointers
- C++ OO Introduction
- C++ OO Creating Objects
- C++ OO Run External Apps
- C++ OO String Operations
- C++ OO Data Types
- C++ OO Conflicting Objects
- C++ OO Pointer to Class
- C++ OO Scope Resolution Operator
- C++ OO Private vs Public Access
- C++ OO Getters and Setters
- C++ OO Constructors
- C++ OO Constructor Overloading
- C++ OO Default Constructor Parameters
- C++ OO Destructors
- C++ OO Static Variables in Classes
- C++ OO Static Method in Classes
- C++ OO Friend Functions
- C++ OO Inheritance
- C++ OO Protected vs Private
- C++ OO Public Inheritance
- C++ OO Protected Inheritance
- C++ OO Private Inheritance
- C++ OO Changing Access Levels
- C++ OO Multiple Inheritance
- C++ OO Constructor Calling Constructor
- C++ OO Method Overloading
- C++ OO Accessing Overloaded Methods
- C++ OO This Pointer
- C++ OO Objects As Parameters
- C++ OO Polymorphism, Virtual Functions
- C++ OO Pointers in Polymorphism
- C++ OO Pure Virtual Functions
- C++ OO Abstract Classes
- C++ OO Virtual Inheritance, Diamond Problem
HTML Tutorial
- HTML Introduction
- HTML Best Editor
- HTML First Page
- HTML Understanding CharSets
- HTML Comments
- HTML Keywords, Description
- HTML Headings H1 to H6
- HTML Paragraphs
- HTML Preformated Text
- HTML Font Size
- HTML Color
- HTML Font Face
- HTML Breaks, Horizontal Lines
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Description Lists
- HTML Images
- HTML Images as Links
- HTML Tables
- HTML Forms - Data Entry
- HTML Insert YouTube
- HTML External CSS
- HTML Internal CSS
- HTML Inline CSS
Python Tutorial
- Python Intro - Why to Learn Python
- Python Installation, First Script
- Python Prompt, CMD, Terminal
- Python Syntax, Indentation
- Python Comments, DocStrings
- Python Variables, Contexts
- Python Concatenation, Types
- Python Numbers
- Python Casting, int, float, str
- Python Indexing, Space Striping
- Python Strings, len, lower, upper
- Python Replace, Split
- Python Keyboard Input
- Python Lists
- Python Length, Indexes
- Python Change, Insert, Append
- Python Delete, Remove, Pop
- Python Search, Clear
- Python Tuples
- Python Tuples, Operations
- Python Sets
- Python Sets, Add, Update
- Python Sets, Remove Discard
- Python Dictionaries
- Python Dictionary Operations
- Python If, elif, else
- Python While Loops
- Python Break, Continue
- Python For Loops
- Python Dictionary Iteration
- Python Functions
- Python Function Arguments
- Python Keyboard Arguments
- Python Return Multiple Values
- Python Iteration, Iter, Next
- Python Modules
- Python Standard Library Examples
- Python Files, Reading
- Python Files, Write, Append
- Python Delete Files, Folders
- 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
numpyasnpfor scientific computing with Pythonpyaudiofor 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 . ...