11:05, 15th April 2023
In PHP, files are created and written to using the fopen() function, which generates a new file if one does not already exist, provided it is opened in either write mode (w) or append mode (a). Writing content to a file is handled by the fwrite() function, which takes the file reference and a string as its parameters.
Opening an existing file in write mode will erase all of its previous content, leaving a blank slate for new data, whereas append mode preserves existing content and adds new data to the end of the file. Once all required operations are complete, the fclose() function is used to close the file, and appropriate file permissions must be in place to allow PHP to write data to the server's storage.
11:04, 15th April 2023
PHP provides a range of built-in functions for handling dates and times, including date(), mktime(), strtotime() and time(), which format, calculate and convert dates and timestamps. The date() function allows formatting local dates and times using specified characters such as Y for four-digit years or l for day names, while mktime() generates Unix timestamps from given dates. strtotime() converts textual date descriptions into timestamps and time() returns the current timestamp. Timezone settings can be adjusted using date_default_timezone_set() to ensure accurate local time representation and date_default_timezone_get() retrieves the current default timezone. Examples demonstrate formatting dates and times in various styles, calculating timestamps for specific dates and adjusting outputs based on timezone configurations.
19:21, 19th March 2023
How to secure and protect WordPress through .htaccess File
Securing a WordPress site involves implementing various .htaccess strategies to enhance protection and performance. Restricting access to the wp-admin area helps prevent unauthorised users from tampering with backend settings. Blocking specific IP addresses through .htaccess can deter malicious activity, while protecting the wp-config.php file ensures sensitive database credentials remain hidden. Preventing hot-linking stops others from using your site's images without permission, and redirecting feeds to Feedburner reduces the risk of exposing internal resources.
Setting up a maintenance page during updates or repairs maintains a professional appearance and prevents user confusion. Additionally, optimising performance through gzip compression and caching headers improves load times and reduces bandwidth usage. Tools like Wordfence or BulletProof Security offer further layers of protection by identifying vulnerabilities and blocking threats. Renaming the .htaccess file or using plugins to manage security settings can simplify maintenance. These measures collectively create a robust defence against common threats, ensuring the site remains secure and efficient.
13:52, 9th March 2023
A bash for loop is a programming construct that allows commands to be executed repeatedly, either for a set number of iterations or indefinitely, and can be used directly at the command line or within a script. The basic syntax involves specifying a variable alongside a list of values or a range, with commands placed between do and done keywords.
Ranges can be expressed using brace expansion such as {1..10} in bash version 3.0 and above, with an optional step value available in version 4.0 and above using the format {start..end..increment}. A C-style three-expression syntax, borrowed from the C programming language, is also supported, using an initialiser, a condition and a step expression within double parentheses, and this approach has the advantage of accepting variables within its range definitions, unlike brace expansion. The older seq command can generate number sequences for use in loops but is considered outdated and less efficient than built-in methods.
Loops can be made infinite by omitting all expressions from the C-style syntax, while the break and continue statements allow early exit from or continuation within a loop respectively. For loops can also iterate over arrays, shell variables containing lists, command substitution output and command-line arguments. Practical applications include automating server maintenance tasks such as running updates or checking uptime across multiple machines, managing firewall rules, installing packages and pinging a range of IP addresses, though for more complex automation tasks, dedicated tools are generally recommended.
10:25, 6th March 2023
WordPress 4.6 Admin Font Change Fix – How To Restore Open Sans Font?
Changing the font in the WordPress admin panel can be achieved through a plugin, though there are some limitations to consider. The plugin allows users to modify the appearance of the dashboard, including the font used in the TinyMCE editor, which is particularly useful for non-English users. However, early versions of the plugin had issues with certain user roles, such as editors, who might encounter access errors. These were later addressed in updates.
While the plugin provides a straightforward solution, it does not support fonts available through Google's Early Access program, such as NanumGothic. For those preferring manual adjustments, editing CSS files in the /wp-admin/css/ directory is an option, though this method is discouraged due to the risk of losing automatic WordPress updates.
01:30, 25th February 2023
Making Pretty PDFs with Quarto
Quarto, an open-source scientific and technical publishing system, can produce professional-looking PDF documents through the use of custom extensions. A Quarto extension for styled PDFs is built around a LaTeX configuration file that handles visual elements such as a coloured sidebar, custom fonts, repositioned page numbers and adjusted section heading styles, all defined within a structured repository containing supporting files for page styling and optional branding imagery. Colours are defined using hex values at the outset, making it straightforward to update the overall appearance later, and fonts such as Ubuntu can be loaded from within the extension directory itself.
The extension is installed via the command line and, once in place, is activated by specifying it as the output format in the document's configuration. Those wishing to adapt the template can either modify the installed files directly or fork the underlying repository to maintain their own version, with adjustments to colours, logos and typography all achievable through relatively minor edits to the core LaTeX file. While HTML formats are generally preferable for accessibility reasons, PDF remains a practical necessity in many professional contexts, and this approach offers a reusable, consistent way to produce polished outputs.
11:44, 20th February 2023
How to Back Up and Restore MySQL Databases with mysqldump
The mysqldump utility is a command-line tool used to back up and restore MySQL and MariaDB databases by generating SQL statements that can recreate the original database, with support also for CSV and XML output formats. A single database can be backed up with a straightforward command referencing the username and database name, while multiple or all databases can be captured in one operation using the relevant flags, and InnoDB databases benefit from the addition of a single-transaction flag to avoid locking issues during the process. Large databases can be compressed by piping output through gzip, and including a timestamp in the filename helps distinguish multiple backups stored in the same location.
Restoring a dump requires creating a target database first and then passing the dump file to the mysql client, and it is also possible to restore a single database from a full multi-database dump using the one-database option. For those who want to transfer data directly between servers, mysqldump output can be piped straight to a remote mysql client without saving an intermediate file.
Backups can be automated using cron jobs, with database credentials stored securely in a restricted configuration file and old backup files removed automatically using the find command. Common issues such as access denied errors, connection failures and packet size limits each have straightforward remedies, and individual tables or schema-only exports are also possible through additional command options.
14:28, 12th February 2023
MySQL Tutorial
The MySQL Tutorial is a comprehensive resource covering all aspects of MySQL, from foundational concepts to advanced administration, offering structured guidance for developers and database administrators. It includes step-by-step instructions for setting up a local database, detailed explanations of features such as stored procedures, triggers, views and indexes and practical examples for working with data through various programming languages like PHP, Java, Python and Node.js.
The content spans querying, managing databases and tables, using functions for calculations and data manipulation and configuring server settings, supported by tutorials on security, backups and performance optimisation. Additional sections provide references for common operations, data types and globalisation settings, alongside supplementary materials such as cheat sheets and books for further learning.
18:20, 10th February 2023
Python: Get Number of Elements in a List
In Python, there are several methods available for counting the number of elements in a list, each suited to different scenarios. The simplest and most common approach is the built-in len() function, which returns the total count of top-level elements regardless of their data types.
For lists containing duplicate values, combining set() with len() allows you to count only unique elements. When working with lists that contain other lists, len() treats each nested list as a single element, so a for loop becomes necessary to count all individual elements within them. For deeply nested lists with multiple levels, a recursive function using isinstance() can be used to check whether each element is itself a list and continue counting inward until all non-list elements, such as integers, strings and floats, have each been counted individually.
14:04, 8th February 2023
Perl Data Language provides Perl with capabilities for efficient manipulation of large N-dimensional numerical arrays, commonly used in scientific computing. It offers an interactive shell and module integration for script-based use, with features such as POSIX threading and parallel computing support through modules like PDL::Parallel::threads.
Recent updates include improvements to core functionality, new releases of affiliated modules such as PDL::Transform::Proj4 and PDL::Opt::Simplex and enhancements to graphics and data processing libraries. The project is actively developed using git on GitHub, with continuous integration testing across multiple platforms and is available through CPAN, Debian and Strawberry Perl. It integrates with external libraries including GNU Scientific Library, OpenCV, OpenGL and LAPACK, enabling a range of computational and visualisation tasks.