Tuesday, December 19, 2017

Raspberry PI - Program a Blinking LED


  1. Connect your LED's cathode (short leg) to a 0V or Ground pin of the Raspberry PI. 
  2. Again connect your LED's Anode (Long Leg) to a GPIO pin via a resistor around 150 ohms (Resistor will save your LED from burnings due to high voltages). Here we use GPIO 8 to be connected to the Anode.
  3. Write the following code.

  4. #include <wiringPi.h> //import the wiringPi lib
    #include <stdio.h>

    #define LedPin 8  //GPIO index which will be connected to the LED's Anode

    int main(void) {
    //Initializing the wiringPi
           if(wiringPiSetup() == -1) {
                   printf("setup wiringPi failed !\n");
                   return -1;
           }
                                    
                                    //Set the PIN mode as output
           pinMode(LedPin, OUTPUT);

           while(1) {
                   digitalWrite(LedPin, LOW);   //led on
                   printf("led on\n");
                   delay(1000);                 // wait 1 sec
                   digitalWrite(LedPin, HIGH);  //led off
                   printf("led off\n");
                   delay(1000);                 // wait 1 sec
           }
           return 0;

    }


  5. Save above code as blinking_led.c then compile and run as below.
  • gcc blinking_led.c -o blinking_led -lwiringPi
  • ./blinking_led



Raspberry PI - How to program with C

To program Raspberry PI with C, we are going to use a library called WiringPi .

Access to your Raspberry PI via SSH and configure the WiringPi as below.

  1. git clone git://git.drogon.net/wiringPi
  2. cd wiringPi
  3. ./build


WiringPi has its own PIN numbering system and we need to refer to that numbering system when doing programming.

Thursday, June 22, 2017

How to include a RSForm to a page built with ST Page Builder in Joomla 3

We can include a RSForm to a page built with ST page builder without using RSForm's "Content Plugin for Joomla 3.0". (Currently "Content Plugin for Joomla 3.0" is not freely available)

Main steps for this are :

1. Create a RSForm using the RSForm! Pro component
2. Create a new module including that component
3. Include the module to a page built using the ST Page Builder component

1.1) Create a RSForm



2.1) Create a new Module




















2.2) Choose the module type




















2.3) Include the required RSForm to the module (Set required position, Access, Ordering, Language, Menu Assignment etc)



















3.1) Go to the page built with ST Page builder
3.2) Drag the "Module" tool from the tool box and drop it on design where necessary




















3.3) Click on the "Edit" button and choose the necessary module we created.




















Now Form should be visible inside the page.

Monday, June 5, 2017

How to start & stop a VPN connection via shell

To list all available Network Manager connections:-
nmcli con

To start an available VPN connection:-
nmcli con up id ConnectionName

To stop an available VPN connection:-
nmcli con down id ConnectionName

Thursday, March 16, 2017

Print a web page with CSS styles

Assume you have created a web page with several CSS styles including several colours in it. However, when you try to print that web page through a web browser you might not see the included styles in the web pages's print preview.

To make available your styles to the page's print version, you have to import your print style sheet to your web page as follows.

print_style.css


.title{
color:blue
}


print_page.html


<html>
<head>
<!-- If you use media="screen" styles will be only available on the screen-->
<link rel="stylesheet" href="print_style.css" type="text/css" media="print" />
</head>

<body>

<h1 class="title">I am blue</h1>
</body>

</html>


As you can see in the above print_page.html we have linked our style sheet using attribute media with value print.


Now you can see styles available in the print_style.css in the print preview but not in screen. You can use media="screen" to display styles on the screen but not in print.

Monday, January 16, 2017

Frequently used tcpdump commands

* View available network interfaces
tcpdump -D

* Capture and prints only 10 packets from a single available interface:
tcpdump -i [any_available_interface] -c 10

* Capture and prints packets from a single available interface and display more contents inside packets.
tcpdump -l -v -i [any_available_interface]

* Capture packets and grep for a specific word.
tcpdump -l -v -i [any_available_interface] | grep [any_possible_available_word]

* Capture and prints packet details including header values in ASCII and HEX
tcpdump -l -v -X -i [any_available_interface]

* Capture and prints tcp packets from specific_src_IP:port 80 to specific_dst_IP
tcpdump -l -i [any_available_interface] port 80 and dst [any_available_IP] and src [any_available_IP] and tcp

* Capture packets from specified host and write those packets to a file.
tcpdump -w /file/path.pcap -l -i lo host [any_available_IP]

* Read and filter the packets through port 80 from above saved file and print details.
tcpdump -r /file/path.pcap -l -v port 80

Friday, January 13, 2017

Useful REGEXs

^ - says start matching from the beginning of the string.
\d - says match only digits
+ - says match minimum 1 or more occurrences
* - says match minimum 0 or more occurrences
$ - says matching happens until the end of the string.



^\d+$ - Numeric Only

^\D+$ - Characters only


^true$|^false$ - True or False only

^\d+(,\d+)*$ - Comma separated digits only (1,2,3,5)

^\d+(:\d+)$ - Two digits separated by Colon (10:00)

^(\d+(:\d+)(-\d+(:\d+)))$ - Two groups of Two digits separated by colon, connected by a dash (8:00-10:00)