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)

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