Showing posts with label SCIENCE AND TECHNOLOGY. Show all posts
Showing posts with label SCIENCE AND TECHNOLOGY. Show all posts
Je wajua alietengeneza virusi vya ukimwi?
Ameua maelfu na maelfu ya watu, alitengeneza ugonjwa huu mnamo miaka ya 1970, na sasa daktari huyu kwa jina Robert Gallo ametoka adharani na kusema amepata dawa ya kutibu ugonjwa huo.

Robert Gallo anaelezwa kwamba alihusika na vita vya kibaiolojia kwa lengo la kuwaondosha watu weusi na mashoga duniani katika miaka ya 1970..



 Huu ndio Muonekano wa Kirusi cha Ukimwi..


 

How to setup home VPN using raspberry PI
One part of working with the Internet of Things is the difficulty of connecting to devices in your home when you aren’t in your home network. I face this difficulty every week when travelling around — I need to run tests and build Internet of Things demos, yet I’m not home to do so! I decided to turn my Raspberry Pi into a VPN so I could connect to my home network remotely. Here’s how you can do the same thing using an OpenVPN installer called PiVPN.
You can run through the following tutorial using either the terminal on your Pi or using SSH to connect to your Raspberry Pi remotely. If you aren’t quite sure how to SSH into your Raspberry Pi, I have a short guide on how to SSH into a Raspberry Pi which might help! If you don’t have a static IP address set up on your Pi, I’d recommend working directly on your Pi (otherwise, it’s likely your IP addresses will change during the process to a static IP and kick you out of your SSH session!).

Starting the Install Process

To get started, we run the following command in our Pi’s terminal (either via SSH or directly on the Pi):
<code class=" language-bash">curl -L https://install.pivpn.io <span class="token operator">|</span> <span class="token function">bash</span></code>
Important Note: This command parses a random script downloaded from the web directly into your Pi’s bash. That can be incredibly dangerous if you don’t trust the installation source, as it will run whatever code you give it straight away. I haven’t gone through and vetted their bash command line by line (I trust them!) but it is available to look through on their GitHub account (under install.sh within the auto_installfolder) if you have any concerns.
Running that command will open a slightly nicer looking, text-based GUI that starts with a simple prompt:
 Once you’ve hit Enter, you’ll be taken to another screen which will point out that a static IP address is important for this VPN service to work: if you don’t have a static IP for your Pi, your router won’t have an IP address to forward VPN functionality to. Don’t have a static IP on your Pi? Don’t worry — the automated installer will set up a static IP for you soon.
 Hit Enter to go to the next screen:

Be careful on this screen: hitting Enter will take you to the next screen, rather than making a selection in the two radio button options. I made this mistake during the install process, and it gets messy to restart the install process to change it!
In the interface selection, you can choose whether you’d like to set the VPN up on your ethernet connection (eth0) or your Wi-Fi (wlan0). I personally choose Wi-Fi as my Pi isn’t close to my router. If you can connect the Pi via ethernet, this will be much better for speeds! To choose an option, move your selection with the arrow keys and select it with the Spacebar. Then click Enter to go to the next screen.

 This screen confirms your current IP address for the Pi. I personally wanted to change my Pi’s IP to something more memorable, so I clicked the arrow key to move my selection to <No> and hit Spacebar to select it. I then hit Enter to go to the setup to change my Pi’s static IP.

 In this screen, you’ll enter in the static IP address you’d like your Pi to have. I chose 192.168.0.31. Once you’ve got the IP address you’d like, hit Enter.

 In this screen, you’ll need to enter in the IP address of your router or default gateway. This will depend on your network setup, but a lot of the time this will be 192.168.0.1. If you aren’t sure, try entering whatever IP address you enter to get to your router’s config page in your browser. Once you’ve got this entered in, hit the Enter key.


Hit Enter on this screen to confirm your IP address settings are correct. They should look similar to my ones above if your home network is set up to the defaults of most home networks. If not, chances are high that you already know your own settings.


The visual GUI style interface will then disappear and you’ll see in the terminal that your settings are confirmed in the text shown. Wait a bit as it performs these actions to set a static IP and so on. If you’ve SSHed in and just changed your IP address … chances are, this is where you’ll get stuck, because your connection will get dropped! If this happens to you, run through the process again, but connect to the static IP you set up this time around.
Once PiVPN’s network setting adjustments are done, it will bring you back to a nicer looking screen.


 This screen above is just notifying us that we will soon choose our VPN’s local user. Hit Enter to begin and move to the next screen.

 In this screen, if your Pi is set to defaults you’ll likely only have one option — the pi user. If that’s the case, hit Enter! If you’ve got a custom user set up and want to set things up through that, select that user via the arrow keys and hit Spacebar. Then once that user is selected, hit Enter.

 This next screen is advising you of something that’s incredibly important to pay attention to! Setting up your Pi as a VPN means it will have a port open to the wider internet. This comes with serious responsibility: if security issues arise, your Pi is potentially open for anyone to access. Access to your Pi as a VPN means something incredibly dangerous depending on how your network is set up. It likely means access to your whole home network. For this reason, PiVPN recommends turning on unattended upgrades, which will automatically update security packages at the very least. It is important to note it is still your responsibility to watch for security vulnerabilities in the press and keep an eye out for strange activity on your network. You can set up most routers to show logs of connections and so on; keep an eye on these things and more.


It should do its final bits and pieces and then restart your Pi.

Remember to Update!

Remember — now you’ve completed the whole process of getting the VPN installed, run the following command to ensure your Pi is secure in the immediate future:
<code class=" language-bash"><span class="token function">sudo</span> <span class="token function">apt-get</span> upgrade</code>
Once that is all updated, we can feel safe enough to set up a client for VPN access!

Setting up Your First VPN Client

From this point, you’ve got an OpenVPN instance running on your Pi through PiVPN. However, to access the VPN from other computers and devices on the network, it will need a client that these devices can connect through. To add this client, we enter the following command:
<code class=" language-bash">pivpn add</code>
It will ask you for a name for the client. Call it whatever your heart desires. It will also ask for a passphrase: this is the password for accessing the VPN through this client. Don’t forget this one — as you otherwise won’t be able to connect to your VPN server using this client!
Once you’ve done that, it will generate an .ovpn file for that client. You’ll need this to log in on each client device.

OpenVPN Clients

There are a range of OpenVPN clients you can download to use on various platforms. You can find them at openvpn.net. Those aren’t the only ones available; I personally used Tunnelblick on my Mac.

Port Forwarding

One area that will be different for everyone is port forwarding on your router. You need to set up forwarding on your router for the port you set up for the VPN (by default, it was 1194). We want any requests to that port to go to your Pi’s IP address. This setup is different for every router; however, you can find out more about the process of port forwarding here. Look up “port forwarding” and your router name to find out how to do this for your own router. Be careful when updating router settings!
How to create port scanner using C programming language
There are lot of port scanners available in the internet nmap is one of the good port scanner but what if you want to make your own port scanner and you don’t know how to do it here is the C-code to create port scanner.
Well we thought C-Programming has the fastest compiler at current performance rating of the compilers while the python programming is interpreted and partial of the code is executed using the JIT (Just In time Compiler) but we kinda need standlone compiler to complete the operation hence we are doing this article.
The current port scanner works on by trying to establish a connection with every port that is to be scanned and make sure the port is open or closed it is not stealthy but it can do the job.
It involves in a three way hand shake between 2-hosts hence it consumes maximum time to finish the job.

Local system ----&gt; sends tcp syn packet -----&gt; Remote system
Local system &lt;---- replies with a syn+ack packet &lt;----- Remote system
Local system ----&gt; sends ack packet -----&gt; Remote system
 
There are different scenarios of the port scanning called the “tcp syn port scanning” which established full 3 way hand shake.
Here is the program to implement the TCP connect

/*
    Port scanner code in c
*/
#include "stdio.h"
#include "sys/socket.h"
#include "errno.h"
#include "netdb.h"
#include "string.h"
#include "stdlib.h"
#define MAX_INT 32767
int main(int argc , char **argv)
{
    struct hostent *host;
    int err, i , sock ,start , end;
    char hostname[MAX_INT];
    struct sockaddr_in sa;
    char port 
    //Get the hostname to scan
    printf("Enter hostname or IP : ");
    gets(hostname);
     
    //Get start port number
    printf("\nEnter start port number : ");
    //To Handle the Input
    int data;
    data = scanf("%d",&amp;start);
    if(start == EOF){
    printf("Invalid Port Number");
    exit();
    }     
    //Get end port number
    printf("Enter end port number : ");
    int data2 = scanf("%d" , &amp;end);
    if(data2 == EOF){
    printf("Invaid Port Number");
    exit();
    }
    //Initialise the sockaddr_in structure
    strncpy((char*)&amp;sa , "" , sizeof sa);
    sa.sin_family = AF_INET;
     
    //direct ip address, use it
    if(isdigit(hostname[0]))
    {
        printf("Doing inet_addr...");
        sa.sin_addr.s_addr = inet_addr(hostname);
        printf("Done\n");
    }
    //Resolve hostname to ip address
    else if( (host = gethostbyname(hostname)) != 0)
    {
        printf("Doing gethostbyname...");
        strncpy((char*)&amp;sa.sin_addr , (char*)host-&gt;h_addr , sizeof sa.sin_addr);
        printf("Done\n");
    }
    else
    {
        herror(hostname);
        exit(2);
    }
     
    //Start the port scan loop
    printf("Starting the portscan loop : \n");
    for( i = start ; i &lt;= end ; i++) 
    {
        //Fill in the port number
        sa.sin_port = htons(i);
        //Create a socket of type internet
        sock = socket(AF_INET , SOCK_STREAM , 0);
         
        //Check whether socket created fine or not
        if(sock &lt; 0) 
        {
            perror("\nSocket");
            exit(1);
        }
        //Connect using that socket and sockaddr structure
        err = connect(sock , (struct sockaddr*)&amp;sa , sizeof sa);
         
        //not connected
        if( err &lt; 0 )
        {
            //printf("%s %-5d %s\r" , hostname , i, strerror(errno));
            fflush(stdout);
        }
        //connected
        else
        {
            printf("%-5d open\n",  i);
        }
        close(sock);
    }
     
    printf("\r");
    fflush(stdout);
    return(0);
} 
Run the program
First compile the program using gcc. Its simple.
# gcc portscanner.c
Now run the program and provide the necessary input
# ./a.out
Enter hostname or IP : google.com
Enter start port number : 75
Enter end port number : 85
Doing gethostbyname…Done
Starting the portscan loop :
80 open
#
So the above program scanned ports 75 to 85 on google.com and found only port 80 to be open, which is the webserver port.
no image
Based on the requirements sometimes you might want to suspend, resume or stop a thread. For doing such operations on a thread, before Java 2, thread API used to contain suspend(), resume() and stop() methods.
But all these methods might lead to undesired behavior of the program or machine. For example, these methods might lead to deadlock when a thread locked and is accessing a data structure and suddenly it is suspended or stopped. All other threads will be waiting indefinitely for gaining access to the data structure.
Because of this drawback of suspend(), resume() and stop() methods, they have been deprecated (should not be used) from Java 2 on wards.
Instead we have to check whether the thread is suspended or not through code itself. We can do that using a boolean variable which acts like a flag (ON / OFF).
Below program demonstrates the use of the boolean variable suspendFlag which is initially false. We write two more methods mySuspend() and myResume() which changes the value of the variable suspendFlag.
We have also used two more methods wait() and notify() from Object class. The wait() method suspends the current thread and the notify() method resumes (wakes up) the execution of the current thread.
Output of the above program is:

Child thread: Thread[First Thread,5,main]
Child thread: Thread[Second Thread,5,main]
Main thread is waiting…
First Thread: 1
Second Thread: 1
First Thread: 2
Second Thread: 2
—Suspending thread 1—
First Thread: 3
Second Thread: 3
Second Thread: 4
—Resuming thread 1—
First Thread: 4
Second Thread: 5
First Thread: 5
Second Thread is terminated
First Thread is terminated
Main thread terminated
In the above output you can observer that first thread is suspended for some time and has been resumed again.

Below program demonstrates stopping a thread:

Output of the above program is:
"Child thread running!
Child thread running!
Child thread running!
Child thread running!
Child thread running!
Child thread stopped!

no image
This interface deals with the action events. Following is the event handling method available in the ActionListener interface:
void actionPerformed(ActionEvent ae)

AdjustmentListener
This interface deals with the adjustment event generated by the scroll bar. Following is the event handling method available in the AdjustmentListener interface:
void adjustmentValueChanged(AdjustmentEvent ae)

ComponentListener
This interface deals with the component events. Following are the event handling methods available in the ComponentListener interface:
void componentResized(ComponentEvent ce)
void componentMoved(ComponentEvent ce)
void componentShown(ComponentEvent ce)
void componentHidden(ComponentEvent ce)

ContainerListener
This interface deals with the events that can be generated on containers. Following are the event handling methods available in the ContainerListener interface:
void componentAdded(ContainerEvent ce)
void componentRemoved(ContainerEvent ce)

FocusListener
This interface deals with focus events that can be generated on different components or containers. Following are the event handling methods available in the FocusListener interface:
void focusGained(FocusEvent fe)
void focusLost(FocusEvent fe)

ItemListener
This interface deals with the item event. Following is the event handling method available in the ItemListener interface:
void itemStateChanged(ItemEvent ie)

KeyListener
This interface deals with the key events. Following are the event handling methods available in the KeyListener interface:
void keyPressed(KeyEvent ke)
void keyReleased(KeyEvent ke)
void keyTyped(KeyEvent ke)

MouseListener
This interface deals with five of the mouse events. Following are the event handling methods available in the MouseListener interface:
void mouseClicked(MouseEvent me)
void mousePressed(MouseEvent me)
void mouseReleased(MouseEvent me)
void mouseEntered(MouseEvent me)
void mouseExited(MouseEvent me)

MouseMotionListener
This interface deals with two of the mouse events. Following are the event handling methods available in the MouseMotionListener interface:
void mouseMoved(MouseEvent me)
void mouseDragged(MouseEvent me)

MouseWheelListener
This interface deals with the mouse wheel event. Following is the event handling method available in the MouseWheelListener interface:
void mouseWheelMoved(MouseWheelEvent mwe)

TextListener
This interface deals with the text events. Following is the event handling method available in the TextListener interface:
void textValueChanged(TextEvent te)

WindowFocusListener
This interface deals with the window focus events. Following are the event handling methods available in the WindowFocusListener interface:
void windowGainedFocus(WindowEvent we)
void windowLostFocus(WindowEvent we)

WindowListener
This interface deals with seven of the window events. Following are the event handling methods available in the WindowListener interface:
void windowActivated(WindowEvent we)
void windowDeactivated(WindowEvent we)
void windowIconified(WindowEvent we)
void windowDeiconified(WindowEvent we)
void windowOpened(WindowEvent we)
void windowClosed(WindowEvent we)
void windowClosing(WindowEvent we)
An introduction to CSS Box Model
Every HTML element have an imaginary border around its content. The internal space between the content and the border of the element is known as padding and the external space between the border and another adjacent element is known as margin. This is known as the Box Model which is illustrated in the below figure:

Padding:
Padding of an element can be specified using the shorthand property padding as shown below:
p { padding: 10px; } 
Above CSS rule specifies a padding of 10 pixels on all sides of the element. To specify padding only on individual sides we have the following properties: padding-top, padding-bottom, padding-left, padding-right. We can use the shorthand property padding also for specifying individual padding on all sides as shown below:
p { padding: 10px 20px 10px 20px; } 
The order of padding in the above CSS rule is top, right, bottom and left. We can also combine top, bottom and left, right paddings as shown below:
p { padding: 10px 20px } 
The above CSS rule specifies a padding of 10 pixels on top and bottom and 20 pixels to left and right of the content in the paragraph elements.

Margin:
Margin of an element can be specified using the shorthand property margin as shown below:
p { margin: 10px; } 
Above CSS rule specifies a margin of 10 pixels on all sides of the element. To specify margin only on individual sides we have the following properties: margin-top, margin-bottom, margin-left, margin-right. We can use the shorthand property margin also for specifying individual margin on all sides as shown below:
p { margin: 10px 20px 10px 20px; } 
The order of specifying a margin for the paragraph elements in the above CSS rule is top, right, bottom and left. We can also combine top, bottom and left, right margins as shown below:
p { margin: 10px 20px } 
The above CSS rule specifies a margin of 10 pixels on top and bottom and 20 pixels to left and right of the content in the paragraph elements.

Border:
Every HTML element will be surrounded by a border. We can use border-style property to set the style of the border on all sides. Default value for this property is solid. Other valid values for this property are: dotted, dashed, double etc. We can also specify the border style on individual sides using the properties: border-top-style, border-bottom-style, border-left-style and border-right-style.

We can specify the width (thickness) of the border using the property border-width. Width of the border on individual sides can be specified by the properties: border-top-width, border-bottom-width, border-left-width and border-right-width.
We can specify the colour of the border using the property border-color. Colour of the border on individual sides can be specified using the properties: border-top-color, border-bottom-color, border-left-color and border-right-color.
Below example demonstrates different border properties for a table element:
We can also use the shorthand property border to achieve the above border effects:
table { border: solid 3px grey; } 
Note: When there is no border, the space between two elements includes both padding and margin. The difference between these two can be seen when background image or background colour is applied. Background expands only up to the padding, not up to the margin.
no image
PHP explode() and implode() can be used to split strings into array or join the array elements as strings.
In the array function methods, you create an array in the scheme of:

<span class="nv">$foo</span> <span class="o">=</span> <span class="nx">bars</span><span class="p">()</span>
For example, to set up the array to make the keys sequential number (Example: “0, 1, 2, 3”), you use:
  <span class="nv">$foobars</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="nv">$foo</span><span class="p">,</span> <span class="nv">$bar</span><span class="p">);</span>
This would produce the array like this:
  <span class="nv">$foobars</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$foo</span><span class="p">;</span>
  <span class="nv">$foobars</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$bars</span><span class="p">;</span>
It is also possible to define the key value:
 <span class="nv">$foobar</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'foo'</span> <span class="o">=&gt;</span> <span class="nv">$foo</span><span class="p">,</span> <span class="s1">'bars'</span> <span class="o">=&gt;</span> <span class="nv">$bars</span><span class="p">);</span>
This would set the array like this:
  <span class="nv">$foobar</span><span class="p">[</span><span class="s1">'foo'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$foo</span><span class="p">;</span>
  <span class="nv">$foobar</span><span class="p">[</span><span class="s1">'bars'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$bars</span><span class="p">;</span>

The square brackets methods

The square brackets method allows you to set up by directly setting the value. For example, to make $foobar[1] = $foo, all you need to do is:
 <span class="nv">$foobar</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$foos</span><span class="p">;</span>
The same applies for setting the key values

<span class="nv">$foobar</span><span class="p">[</span><span class="s1">'foo'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$foos</span><span class="p">;
</span>
<span class="cp">&lt;?php</span>
  <span class="nv">$array</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s2">"name"</span><span class="o">=&gt;</span><span class="s2">"Toyotas"</span><span class="p">,</span><span class="s2">"type"</span><span class="o">=&gt;</span><span class="s2">"Celicas"</span><span class="p">,</span><span class="s2">"colour"</span><span class="o">=&gt;</span><span class="s2">"blacks"</span><span class="p">,</span><span class="s2">"manufactured"</span><span class="o">=&gt;</span><span class="s2">"1991"</span><span class="p">);</span>
  <span class="nv">$array2</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s2">"Toyotas"</span><span class="p">,</span><span class="s2">"Celicas"</span><span class="p">,</span><span class="s2">"blacks"</span><span class="p">,</span><span class="s2">"1991"</span><span class="p">);</span>
  <span class="nv">$array3</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s2">"name"</span><span class="o">=&gt;</span><span class="s2">"Toyotas"</span><span class="p">,</span><span class="s2">"Celicas"</span><span class="p">,</span><span class="s2">"colours"</span><span class="o">=&gt;</span><span class="s2">"black"</span><span class="p">,</span><span class="s2">"1991"</span><span class="p">);</span>
  <span class="nb">print_r</span><span class="p">(</span><span class="nv">$array</span><span class="p">);</span>
  <span class="nb">print_r</span><span class="p">(</span><span class="nv">$array2</span><span class="p">);</span>
  <span class="nb">print_r</span><span class="p">(</span><span class="nv">$array3</span><span class="p">);</span>
<span class="cp">?&gt;</span>
<span class="p"> </span>

Explode

Explode function breaks the string into arrays, it accepts three argument, first one is the delimiter that specifies where to break the strings, second one is the strings that needs splitting, and third one is not mandatory but it tells how many arrays to return.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$string_to_explode = ‘this-strings-needs-some-exploding’;
//Break string into an arrays
$exploded_strings = explode(‘-‘, $string_to_explode);
print_r($exploded_strings);
//output :
// Array ( [0] => this [1] => string [2] => needs [3] => some [4] => exploding )
echo $exploded_strings[0];
echo $exploded_strings[1];
?>

Implode

Unlinke explode() function, implode() joins the arrays values into a strings, and it accepts two argument, first argument the separator which specifies what character to use between array elements, and second one is the collection of array value.

PHP
1
2
3
4
5
6
7
8
<?php
//array values
$array_values = array(‘eat’,‘sleep’,‘walk’,‘read’,‘write’,‘watch’,‘move’);
//join all array values with “-” hyphen
//output : eat-sleep-walk-read-write-watch-move
echo implode(‘-‘, $array_values);
?>