Labels

Android (1) bash (2) boost (2) C (34) C++ (2) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (2) Dreamweaver (2) Eclipse (3) fail2ban (4) git (5) GitHub (4) Hacking (3) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (31) javascript (3) Linux (167) Mac (19) Machine Learning (1) mySQL (48) Netbeans (4) Networking (1) Nexus (1) OpenVMS (6) Oracle (1) Pandas (3) php (16) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (47) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (3) Visual Basic (1) Visual Studio (1) Windows (2)

Sunday, 20 December 2020

Problem building mesdb

I had trouble building mesdb using Netbeans but note that it did build correctly from the original source on the box, from the command line by running make.

Friday, 18 December 2020

/bin/bash^M: bad interpreter: No such file or directory

This is caused by windows carriage returns, the ^M is a carriage return character.

Windows uses CRLF whereas Linux only uses LF source

I had this issue when working between Linux and Windows using Sublime Text

and in this case, at the bottom of the editor, switched from Windows to Unix. 

Prevent cron from sending emails

 

 > /dev/null 2>&1

Thursday, 10 December 2020

Restoring a system archived with fsarchiver.

This is a Work In Progress walk-through, restoring a system archived with fsarchiver

UPDATED: 1 July 2021

Sunday, 6 December 2020

ifconfig not in /bin ?

If ifconfig is not where I would expect it to be, that is /bin/ifconfig then don't be getting all defrosted, just do;

sudo ln -s /sbin/ifconfig /bin/ifconfig


Wednesday, 2 December 2020

Installing and Configuring Jupiter Notebooks on Debian


To install, do;

apt install jupyter-notebook

To launch in the /var/jupyterNotebooks directory, do;

cd /var/jupyterNotebooks && jupyter-notebook --ip=0.0.0.0

This will allow access to the server IP address on port 8888

The following will startup Jupyter in a sub dire 'NoteBooks' and can be closed by CTRL-C or by shutting down from the browser  The QUIT button.

!#/bin/bash
echo "Starting Jupyter Notebooks..."
/usr/bin/jupyter-notebook --notebook-dir NoteBooks

 

To connect to MySQL we need to install PyMysql and this can be done by;
 
sudo python3 -m pip install PyMysql

also

sudo python3 -m pip install PyMysql[ed25519]

sudo python3 -m pip install PyMysql[rsa] 
 
and while we're at it, pandas is;

sudo python3 -m pip install pandas
 

Wednesday, 18 November 2020

Linux Version

Find Linux distribution version release information.

RedHat

cat /etc/redhat-release

hostnamectl

Slackware

cat /etc/slackware-version

Debian

lsb_release -a

Sunday, 15 November 2020

CSS cheatsheet

The following shows the difference between html selectors, class and id.

Friday, 13 November 2020

SVN configuration

 Subversion HowTo

A simple guide to setting up svn on Slackware...

Sunday, 1 November 2020

mysql++.h and libmysql++-dev missing in Debain 10

mysql++ 

is missing in Debian 10 and despite several attempts to install it, I haven't yet been able to, so...

to install it under Debian Bullseye, do;

apt install libmysql++-dev

Bullseye can be found here: https://www.debian.org/devel/debian-installer/

See also here: https://packages.debian.org/search?keywords=libmysql%2B%2B-dev&searchon=names&suite=all&section=all


Saturday, 24 October 2020

Setup VPN in Debian

In this case, using xfce and assuming Network manager is installed and configured, you need to then install the following;

sudo apt-get install network-manager-openconnect

You may need to install additional network-manager plug-ins and you can search those by;

sudo apt search 'network-manager-*'

then installing as;

sudo apt-get install network-manager-plugin-name

Monday, 19 October 2020

Saturday, 17 October 2020

Connect to remote mySQL server from the command line.

mysql -u username -h xxx.xxx.xxx.xxx -p

where username is the username of the remote mySQL server.

The following can also be used to test connection;

nc -z -w1 xxx.xxx.xxx.xxx 3306

MySQL Master Slave replication setup

MySQL replication setup

mySQL info

A quick way to get some mysql information is to run

mysql --help --verbose

How to setup a ramdisk in Linux

How to setup a ramdisk in Linux

Friday, 16 October 2020

Change temporary tables in mySQL to memory

To change the location of temporary tables in mySQL, we need to edit the tmpdir variable in my.cnf or which ever file contains the [mysqld] section.

Thursday, 15 October 2020

Thursday, 8 October 2020

Check for FULLTEXT INDEX in mySQL database

When converting from MyISAM to InnoDB;

It is important if running an older version of MySQL to first check for FULLTEXT INDEX as full-text indexing is not supported by InnoDB in older databases.

To run a check, execute the following query;

SELECT TABLE_SCHEMA, TABLE_NAME
FROM information_schema.statistics
WHERE index_type LIKE 'FULLTEXT%' 


Additionally, to convert multiple tables at once, do;

SELECT CONCAT('ALTER TABLE ',TABLE_NAME,' ENGINE=InnoDB;') 

FROM INFORMATION_SCHEMA.TABLES

WHERE ENGINE = 'MyISAM' AND table_schema = 'mydb';

You may need to use the options to show Full text in the results to avoid lines being truncated, also watch out from some dodgy table names, like group.





Sunday, 4 October 2020

To update default browser in Debian Linux

To update the default web browser in Debian, do;

sudo update-alternatives --config x-www-browser

I noticed this had changed after I installed Chrome...

Saturday, 3 October 2020

Exchange Web Services in evolution Mail

The below is a screen shot of how I managed to connect to Exchange Web Services in the Evolution Mail client.

Thursday, 1 October 2020

MySQL copy table

MySQL copy table with and without data;

CREATE TABLE IF NOT EXISTS table_copy

SELECT * FROM table;

Saturday, 26 September 2020

SSH as root

If you really want to ssh at root;

edit /etc/ssh/sshd_config

Friday, 25 September 2020

Apache, php, mySQL and phpMyAdmin install on Debian

See also here for Slackware configuration.

To install and configure apache, MySQL and phpMyAdmin

Wednesday, 23 September 2020

Install ifconfig on Debian

 apt-get install net-tools

MySQL views

The basic syntax to create a view is as follows;

CREATE VIEW view_name
AS
SELECT something, somethingElse
FROM someTable;

Saturday, 19 September 2020

Xdebug install and configuration for use with PhpStrom

To enable and configure Xdebug for use with PhpStorm

This was carried out on my Mac, yet to be tested under Linux.

Friday, 18 September 2020

Linux links

Quick reminder on links in Linux


ln -s sourceFile linkFile (soft link or symbolic link)

ln sourceFile linkFile (hard link)

DL - Messages

 

Friday, 11 September 2020

Wednesday, 9 September 2020

Monday, 7 September 2020

DL - Query to check for missing gas cut stamping details

A reminder of why I used a combination of JOIN and INNER JOIN

This serves as a decent example of this.

CLion CYGWIN warning - TODO

TODO

sudo

A quick reminder on adding a user to the sudo file.


We want to use visudo as root to edit the /etc/sudoers file.

we add our user as follows;

username ALL=(ALL) ALL

Saturday, 5 September 2020

Run a C program as a daemon in Linux

Tested on Slackware 14.2 (to be tested on Debian)

Mostly from here

The complete working skeleton code can be found here 

When launched, this will live for 20 seconds and then terminate, logging startup and exit messages to /var/log/messages not syslog as expected on Slackware 14.2 but verified to write to /var/log/syslog on Debian 10.5

This can be pulled from: https://github.com/plisken1/daemon_template.git

Run a shell script (or an application) as a daemon in Linux

This is aimed at Linux systems running systemd (Debian and RedHat), mostly from here 

See my other blog post here

Writing to the message log in Linux with C

 The following is an example of writing to the message log in Linux with C

from here, maybe here and also here if you are feeling brave.

#include <syslog.h>

#include <stdio.h>


int main()

{


setlogmask (LOG_UPTO (LOG_NOTICE));


openlog ("myprogramlog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);


for (int x=0;x<10;x++)

   {

   syslog (LOG_NOTICE, "Program started, count = %d",x);

   syslog (LOG_INFO, "A tree falls in a forest");

   }


closelog ();


return 0;


}

Linux Daemon Writing HOWTO

 The following is a copy of the document from here

Linux Daemon Writing HOWTO

Devin Watson

v1.0, May 2004
This document shows how to write a daemon in Linux using GCC. Knowledge of Linux and a familiarity with C are necessary to use this document. This HOWTO is Copyright by Devin Watson, under the terms of the BSD License.

Friday, 4 September 2020

Build C++ app in CLion for Linux (including a MySQL application)

How to build a C++ application, using MySQL and deploy on Linux.

In this case, we are using Debian 10 (also works on Slackware 14.2)

We are building an application (example can be found here, albeit slightly modified but importantly includes mysql.h). Also on GitHub here 

MySQL install on Debian & solution to mysql-config not found.

To install mysql server on Debian

apt-get install mariadb-server

To start, run;

service mysql start

I also found mysql_config not to be found on Debian 10

likely due to the development stuff not being installed as I could also not find /usr/include/mysql

so, installing and resolving is as follows;

sudo apt-get install libmariadb-dev-compat

also worthwhile maybe;

alp-get install libmysqlcppconn-dev

apt-get install libmysql++

Wednesday, 2 September 2020

Monday, 31 August 2020

Sunday, 30 August 2020

Install Java 8 on Debian

The following can be used to install Java 1.8 on Debian 10

From the following link;

https://adoptopenjdk.net/installation.html?variant=openjdk8&jvmVariant=hotspot#x64_linux-jdk




1) wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -

2) sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/

If the above fails;

2) - (optional) sudo apt-get install -y software-properties-common

3) sudo apt-get install adoptopenjdk-8-hotspot



both java installations (assuming the default was installed) can be found in /usr/lib/jvm

Also, mind update netbeans.conf (probably in /usr/local/netb*/etc/) to point to java 8 as opposed to (11 for example), assuming we're using NB8.2

Failure to do the above may not prevent NB from launching but may well prevent you from Creating a New Project


Wednesday, 26 August 2020

start/stop apache on Mac


sudo apachectl start

sudo apachectl stop

also note

brew services 

PHP install on MacOS with note on Debian 10.5

For Mac with Home-brew

brew install php

After install with Home-brew, the location of both the default and new install can be seen below;


the latter is the original Mac install.

Also see here

For Debian;


sudo apt-get install php

then

sudo apt-get install php7.3-cgi

Note, replace the 7.3 with whatever php version was installed in the previous step.

This can be checked by

php -version

or

dpkg -s php



Sunday, 23 August 2020

C++ File structure in both Netbeans and CLion

Below shows the file structure of a simple C++ application in both Netbeans and CLion (on a Mac).


Friday, 21 August 2020

Debian 10 install on Thinkpad p53


The following is my account of installing Debian 10.5 onto a Lenovo ThinkPad P53




Wednesday, 19 August 2020

Tuesday, 18 August 2020

Gascut stamping instructions

How to populate Gas Cut stamping if this has not been completed automatically.

Sunday, 16 August 2020

Linux Display Managers


Debian/Ubuntu

/etc/X11/default-display-manager

RedHat/CentOS/Fedora

/etc/sysconfig/desktop

OpenSuSe

/etc/sysconfig/displaymanager


OR on systemd systems, do;


systemctl status display-manager


To switch Display Managers (Debian)

sudo dpkg-reconfigure <displayManagerName>

Actually with the above, we can use any installed DisplayManager and then from the prompt, simply choose the one we wish to switch to.

To restart the Display Manager (Debian), do;

sudo service <displayManager> restart

Example: sudo service gdm restart



See also here 

and here for the good old RedHat logo, which is a must for any Applications Menu logo.

Saturday, 15 August 2020

Linux - UEFI or Legacy boot.

To find out whether we are booted in UEFI or Legacy mode, so;

[ -d /sys/firmware/efi ] && echo UEFI || echo Legacy

Basically, if the refi file exists, we are in UEFI mode.

I'm not sure if the /sys folder is even there on < 2.6 kernels, it doesn't appear on my Slackware 8.1 (specifically for the SCS machine).

Thursday, 13 August 2020

Some apt-get stuff



To search for packages, do;


apt-cache search package

To update package list, do;


apt-get update

 

See also here

 

Wednesday, 12 August 2020

Kill a running query in mysql

If we are finding that we are struggling to connect to a MySQL database, it can be a result of a long running query and this can usually be terminated as follows;

Firstly, login to the MySQL database and run;

show processlist;

We can then kill the process bu the ID as follows;

kill id;

This can be verified bu again running show processlist; to ensure that the query has indeed been stopped.


Saturday, 25 July 2020

Switch between text and graphical environments in Debian or RHEL

To switch between booting to a graphical environment and a console


Firstly run

systemctl get-default

which will show current setting, either

graphical.target

or

multi-user.target


To change, use 

systemctl set-default [graphical.target or multi-user.target]

To effect the change without rebooting, do

systemctl start [graphical.target or multi-user.target]


Of course in Slackware, we would simply edit Default Runlevel in /etc/inittab

Saturday, 18 July 2020

Register RHEL from command line

To register RHEL from the command line, do the following;


subscription-manager register --username user --password pass --auto-attach

This can be verified at https://access.redhat.com/management

RHEL Network Configuration


RedHat Network configuration


Run nmtui

Mount CD from command line in RedHat

How to mount a CD in RedHat


Linux shell command shortcuts

Handy forgotten shortcuts, for those lazy moments;



  • UP Arrow - Previous command.
  • TAB - Autocomplete.
  • history - Displays command history.
  • !! - Execute previous command (I don't like, prefer UP ARROW).
  • !n - Executes the command n in the history.
  • !$ - Recall argument used on the previous command (if there was one).
  • ALT . - Filter through previous arguments (doesn't always work, especially on Mac).
  • ^r (CTRL r) - search through history. 




Sunday, 12 July 2020

Passing arrays to functions in C

The following is an example of how to pass a CHAR array to a function in C


In this example, we are simply counting the number of letters in a char array;


int getNumberOfLetters(char w[])
{
     int l=0;
        while (w[l]!='\0')
        {
            l++;
        }
        return l;    
}


char word[100]; // initialise a char array with 100 cells

scanf("%s",word); // Get a word as input

int length = getNumberOfLetters(word); // call our function

Another Example, this time printing out the passed string;

#include <stdio.h>

void my_function(char * str)
{
    printf("%s\n",str);
}

int main()
{
    char name[]="Harold Hellman";
    my_function(name);

    return 0;
}


We can create a function that takes an array of chars as follows;

void myFunction (char* arg)

OR

void myFunction (char arg[])

and similarly, we can call either of the above with;

char myArray[10]="Harry";

myFunction(myArray);

Saturday, 11 July 2020

Bool data type in C

The following is an example of how to define and use a bool datatype in C


typedef enum { false, true } bool;

bool myVar = true;

if (myVar)
{
  // do something
}

Or using an int (any integer is considered true, but not 0 ofc);

    int notZero=1;

    while(notZero)
    {
        scanf("%d",&notZero);
    }

Finally using stdbool.h (probably preferred);

#include <stdbool.h>


bool condition=true;

    while(condition)
    {
      // do something
    }

With regards to C++, I'm not so sure we even need to #include stdbool.h

Wednesday, 8 July 2020

Application Blocked By Java Security

Solution to the following error


Fig.1

This documentes the requirements for launching an app with all-permissions.

Friday, 3 July 2020

Format specifiers in C with a note on data types.

With the printf() function, we use the following;

%d - integer variable.
%c - character.
%f - for float variable.
%s - for string variable.
%lf - for double.
%x - for hexadecimal.
\n - gives us a newline.

An example of use can be seen below;

#include <stdio.h>

int main()
{
    int i = 5;
    float f = 9.8;
    
    printf("Here we have an integer: %d",i);
    printf("\n");
    printf("and here we have a float: %f",f);
    return 0;
}

An overview C++ data types


Friday, 26 June 2020

C++ Boost Libraries

Usage examples of the c++ boost libraries

C++ Header file template

C++ Header file template (including a guard)



#ifndef HEADERNAME_H_
#define HEADERNAME_H_

// CONTENT

#endif

The above basically ensures that only one instance of a definition is loaded or defined.

A basic C++ file with a header

What follows is a basic C++ file with a Header file


 -- taken from https://www.learncpp.com/cpp-tutorial/header-files/ --


Sunday, 21 June 2020

Makefile basics

The basis of a simple Makefile

# Define source filename here:
SRC = main.cpp 

# Define output filename here:
OP = test.o

# Define compiler here:
CC = g++

# Define flags here:
CFLAGS = -o

program:
@echo "Building binary: "$(OP)
$(CC) $(CFLAGS) $(OP) $(SRC)

clean:
@echo "Removing binary:"$(OP)
rm $(OP)


Thursday, 18 June 2020

Path bug with Debian as root.

I noticed a bug in Debian 10.4 https://www.debian.org/News/2020/20200509 where certain commands are not in the root path by default.

Example;
adduser which is in /usr/sbin and as root adducer is not found.

Of course you can do /usr/sbin/adduser but which kind of looney would be wanting to do that.

The above can be seen when doing su and doing su - gets around it without modifying anything.



How to find the Hostname and Domain name on Mac or Linux

To find the hostname on a Mac, simply do as one would on a Linux box;

hostname

To find the domain name on a Mac, we can do as we would on a Linux box also;

cat /etc/resolv.conf

The following may also help on a Mac;

scutil --dns

It may also be worth looking under the Search Domains section;

System Preferences >> Network >> [Select NIC] >> Advanced  >> DNS

On Linux, we can also do the following;

domainname - not always set for some reason, especially on my Slackware systems.

dnsdomainname - This shows on my Slackware systems.

nisdomainname - not always set for some reason, especially on my Slackware systems.

ypdomainname - not always set for some reason, especially on my Slackware systems.


Wednesday, 10 June 2020

Useful Eclipse Java autocomplete settings

Out of the box, autocomplete for Java in Eclipse has been found to be quite, well lacking and just not right, so...

Sunday, 7 June 2020

Double tapping the space bar inserts a period or full stop on Mac

If you have a Mac and find that you are randomly seeing a full stop or period being inserted after words randomly, then it is most likely that you have the following setting enabled;


SETTINGS > KEYBOARD > TEXT

Saturday, 6 June 2020

Stored Procedures in MySQL and PostgrSQL

The following will create a storied procedure called getPercentage() with MySQL

DELIMITER $$

CREATE PROCEDURE getPercentage()
BEGIN   SELECT (COUNT(fault_resolved)/ count(id)*100)AS percent
    FROM log;
END$$
DELIMITER ;

Note:  The DELIMITER $$ exists to change the delimiter used, which is normally ;
This means we can have our statement inside and using a ; but will not be seen as the end of the statement.

This can be called by

CALL getPercentage();

Examples of basic C++ Header and class files.

Example of basic Header and class files

How to add Eclipse software repository to RedHat Core Ready Studio

RedHat Code Ready Studio is just a customised Eclipse but there may be reasons for wishing to use this as opposed to Eclipse itself, which as it happens can also have the RedHat stuff added to, termed "Bring your won Eclipse":

https://access.redhat.com/documentation/en-us/red_hat_codeready_studio/12.12/html/installation_guide/assembly_installing-devstudio-in-eclipse

Thursday, 4 June 2020

How to boot into macOS Recovery and optionally erase the disk

The following can be used to reboot into recovery;


Command (⌘) + R
Reinstall the latest macOS that was installed on your Mac (recommended).

Option + ⌘ + R
Upgrade to the latest macOS that is compatible with your Mac.

Shift + Option + Command (⌘) +  R
Reinstall the macOS that came with your Mac, or the closest version still available.

To optionally erase the disk;


Choose View > Show All Devices and then choose the top drive, the system drive and choose erase.
Note: Its worth copying the drive name as we can use it to name the newly formatted drive, if that's your thing.

Reference here and here for recover options.

Wednesday, 3 June 2020

SCS upgrade to support usb mouse and keyboard.

This document is/was written retrospectively and exists to document the changes made to the SCS Linux computer during the upgrade to support USB keyboard and mouse. This was successfully tested in Glasgow and at the time of writing, will can be rolled out to all other depots.


1- BACKGROUND.

1b- NOTES AND FILES.


2- PROCEDURE TO UPGRADE SCS USING CONFIGURED KERNEL (HEISENBERG).


3- STEPS TO SWITCH FROM PS2 TO USB.


4- STEPS TO SWITCH FROM USB TO PS2.


5- PROCEDURE TO REVERSE UPGRADE.


6- PROCEDURE TO CREATE HEISENBERG KERNEL.


7- LINKS.


LAST UPDATED: 29 July 2020

Tuesday, 2 June 2020

Some quick comparisons between black and while box testing.

Black Box Testing:


  1. Requires No knowledge of the internal structure of program or application.
  2. Requires No programming knowledge required.
  3. The main goal is to test the behaviour of the software or application.
  4. Focused on the external or end-user perspective.
  5. Generally provide less detailed reports.
  6. Not time consuming.

White Box Testing:


  1. Requires knowledge of the internal structure of program.
  2. Requires programming knowledge.
  3. The main goal to test the internal operations of the system.
  4. Focused on code itself, its structure, conditions, paths and branches.
  5. Generally provide the most detailed reports.
  6. Extremely time consuming.

Sunday, 31 May 2020

Find files in Linux

Basic use of the find command in Linux

To find a file named my file.txt anywhere;
find / -name "myfile.txt"

To find a file named my file.txt in the current directory;
find . -name myfile.txt

To find all files in the current directory;
find . -name *.txt

To find all jpg files in /home/plisken;
find /home/plisken -name *.jpg

To search the contents of files in current directory;
find . -type f -exec grep "keyword" '{}' \; -print

Tuesday, 26 May 2020

Add to the shell PATH in MacOS

The following will add to the shell path in MacOS;

Open .bath_profile
(Don't forget [SHIFT + CMD + .] toggles displaying of hidden filed in finder.)

To ad a folder such as /Users/plisken/connectiq/bin we would add the following line to the end of .bash_profile;

export PATH="/Users/plisken/connectiq/bin:$PATH"

OR

export PATH=$PATH:/Users/plisken/connectiq/bin

and of course we can check the current $PATH by doing echo $PATH

Relaunching the terminal may be required...


Saturday, 16 May 2020

PHP variables and scope

In php variables have scope (don't all languages)...

A variable declared outside of a function will not be available inside of a function, unless be declare it inside the function with the global command.

Wednesday, 13 May 2020

Sync data from Fitbit to the Apple Health app.

What follows is a documented account on how to achieve reliable synching of data between the Fitbit and the Apple Health app.

A step by step of this project, how it came about, progress, problems and solutions along the way can be found here

Tuesday, 12 May 2020

IRC revisited

See here and here for nick registration instructions for Freenode and Dalnet respectively.


Monday, 11 May 2020

Quickly add dir to OSX

A quick and dirty method of adding dir to a Mac is as simple as creating a link to /bin/ls

ls is located in /bin

By default we can't add or modify things there (topic for another time), but we can modify things in /usr/local/bin so where better a place to add a dir file/command...

goto /usr/local/bin
and do sudo ln -s /bin/ls dir

dir now exists in /usr/local/bin as a symbolic link to /bin/ls

Sunday, 10 May 2020

Alternative methods of joining results from two tables


If we are wanting to pull information from two different tables that are linked in some way, the conventional way of doing this is as follows:

SELECT  table1.item, table2.item
FROM table1 JOIN table2 ON table1.item = table2.item;

However an alternative is to use the following;

SELECT  table1.item, table2.item
FROM table1, table2
WHERE table1.item = table2.item;


Saturday, 9 May 2020

iPad keyboard click, camera should and lock screen sound not working

If the lock screen sound, keyboard click and camera sound aren't working on iPad, but you find other sounds are, such as music, ringtones etc, it is worth checking the control centre by swiping down from top right of screen as the system may have been muted.

It's important to note that while in this state, in settings, the keyboard click and lock screen sound options will still show as enabled.

Thursday, 30 April 2020

Change text in an HTML document and passing php variable to javascript.

To change text in an html document or web page, we can use javascript.

If we were using php to echo the html then unfortunately, once the echo is done, the html is created so to speak and it's no longer possible to change or update it.

But, we can use javascript, as per the example below, where the 1st line could be high up on the page and would display old text and once the script below runs, this old text would be changed to new text.

This can of course be done by embedding php echo statements to include variables, which is also a way of passing a variable from php to javascript.



<p align="left" id="id1">old text</p>


<script>
document.getElementById("id1").innerHTML = "new text";
</script>

OR

<script>
document.getElementById("dt").innerHTML = "<?php echo $someVar ?>";
</script>

Half adder and 1 bit full bit adder

Tuesday, 28 April 2020

basic web page redirect or reload

The following is a basic web page redirect;

<html>
  <head>
    <meta HTTP-EQUIV="refresh" CONTENT="3; URL=index.html">
  </head>
</html>

 
The following is a basic javascript equivalent;
 
<script>
setTimeout(function () 
{
   // 5 seconds
   window.location.href= 'index.html';
}, 5000);
</script>
 
 
 
To reload a page without getting an alert, we can do the following;
 
<script>
    function reload_page()
    {
        window.location = window.location.href;
    }
</script>
 
then call it by;
 
<script type="text/javascript">
     reload_page();
</script>';
 
or from php;
 
echo '<script type="text/javascript">'.'reload_page();'.'</script>';


To call the function after some time, for example, to refresh the page in 5 seconds, we can do the following to call the reload_page function detailed above;


<script>
setTimeout(reload_page,5000);
</script>


Sign Magnitude, Two's compliment binary representations

The following table shows the difference between Sign Magnitude and Two's compliment

As an additional note, two's compliment involves inverting and adding 1.
So if we look at the table below for 0100 which is 4, the two's compliment representation of -4 would be 1100

How do we get there, well we first invert from 0100 to 1011 and then add 1 to give 1100

To go the other way;
If we have -3 which is 1101 we invert to give 0010 and add 1 to give 0011 which is of course 3

Saturday, 18 April 2020

Add a Right Click action to any Application

The following is an automator screenshot of how to add a Right Click action to highlighted text in any application on a Mac.

Thursday, 16 April 2020

Cyclomatic Complexity

Cyclomatic Complexity


Cyclomatic Complexity is the number of independent paths through code and there are many websites that do a better job of explaining it than I can, but...

Wednesday, 8 April 2020

To test a fail2ban filter using fail2ban-regex

We can test any fail2ban filters by using the following:

fail2ban-regex <logfile> <filter>

Example:

fail2ban /var/log/apache/error_log /etc/fail2ban/filter.d/apache-noscripts.conf


Tuesday, 7 April 2020

To block, unblock or check IP addresses with iptables in Linux

To block or check IP addresses with iptables

The format to block and IP address is as follows:
iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP

To block an IP address, use the following;
iptables -A INPUT -s 192.168.254.100 -j DROP

To view all blocked IP addresses, do;
iptables -L INPUT -v -n
OR
iptables -L INPUT -v -n | less
OR (especially if blocked with fail2ban) **
iptables -L -n --line

To check for a specific IP address, do;
iptables -L INPUT -v -n | grep "192.168.254.100"

To unblock an IP address, do;
iptables -D INPUT -s 192.168.254.100 -j DROP

Alternatively to unblock an entry blocked with fail2ban (see ** above) do;
iptables -L -n --line
then find the IP address you wish to unban.
then do
iptables -D ruleName n
where ruleName is the rule name  associated with the banned IP
and n is the number associated with the banned IP

ref: https://www.cyberciti.biz/faq/linux-howto-check-ip-blocked-against-iptables/



Set and retrieve cookies with php

The format for setting a cookie in php is as follows:

setcookie(name, value, expire, path, domain, security);

I only use the name, value and expire, where expire is in seconds, so;
time() + 24*60*60 is 1 day.

Tuesday, 24 March 2020

Server Settings for Dreamweaver

Server Settings for Dreamweaver to allow publishing to a site connected to locally.

In my example, my web server is on my local network, accessible from the internet, so to prevent setting up firewall rules and port forwarding to allow external access to FTP etc, I would rather connect using the local private IP address.
However, previously when attempting this, the default directory was the home directory for the user used which is no good.

The screen shot below, shows how to properly accomplish this;


Saturday, 7 March 2020

MySQL triggers

The below are examples of 2 triggers I set up on a database recently.

The first one was to evaluate a condition on inserting a new record, while the second one was to evaluate the same condition but this time on update.

Sunday, 1 March 2020

Backup and restore MySQL database

To backup a MySQL database


See this link here

shell> mysqldump [arguments] > file_name
shell> mysqldump --all-databases > dump.sql

shell> mysqldump --triggers --routines --all-databases > dump.sql  
shell> mysqldump --databases db1 db2 db3 > dump.sql

shell> mysqldump --databases dbname > dump.sql


OR omit the --databases


shell> mysqldump test > dump.sql

To dump only specific tables from a database use;

shell> mysqldump dbmane table1 table3 table7 > dump.sql

To dump only the structure from a database use;

shell> mysqldump --no-data dbmane > dump.sql 

shell> mysqldump --d dbmane > dump.sql  

Note: -d includes the triggers. 

To dump only the routines from a all databases use;

mysqldump -u username -p -n -t -d -R --all-databases > routines.sql
 

To add the host 192.168.254.198 and the user root, do;

shell> mysqldump --host=192.168.254.198 --port=3307 -u root -p dbmane > dump.sql

See also my post here for details on how to simply copy the table structure.

Real examples with my_db:

The following will backup the structure, triggers, functions and procedures; 
mysqldump --host=[...] -udev -p --no-data --triggers --routines my_db > my_db_structure.sql
 
The following will backup the entire database, as above but including the data;
mysqldump --host=[...] -udev -p --triggers --routines my_db > my_db_all.sql

To restore a MySQL database

See this link here

shell> mysql -u root -p < dump.sql

Within mysql (first login, see below);
mysql> source dump.sql

To login to mysql, do;
mysql -u username -p

If the dump file does not create the database, then this must first be created;
shell> mysqladmin create dbname

Within mysql (this works for me);
mysql> CREATE DATABASE IF NOT EXISTS dbname; mysql> USE dbname; mysql> source dump.sql

Real example with my_db:
Firstly, ensure the database has been created by logging in and doing:
 
CREATE DATABASE mydb;
 
then;
 
mysql --host=[...] -udev -p my_db < my_db_all.sql
 
 
To backup and restore database users and grants, see here