Wednesday, June 3, 2015

Upload files to Amazon EC2 Linux instance

scp -i myAmazonKey.pem file.zip ec2-user@mec2-50-17-16-67.compute-1.amazonaws.com:~/.

Saturday, April 4, 2015

Useful Linux/Unix commands

List files from current folder:
ls -l

Get current shell:
echo $SHELL

Get present working directory:
pwd

Get content from Home directory:
ls ~

List files from current directory:
ls .

Navigate to home directory:
cd

Navigate to root folder:
cd /

Find out file type:
file [path]

Navigate to a "two words" folder:
cd word1\ word2
cd 'word1 word2'

Hidden file name example:
.hiddenfile

List all files(including hidden):
ls -a

Manual page for a certain command:
man <command>
man -k <search term>

Chain parameters example for listing all files and add kilo, bytes to size:
ls -alh

Create a new directory:
mkdir learning

Create a new directory with parameter to display the action and parameter to create all directories if needed:
mkdir -pv dir1/dir2

Remove empty directory:
rmdir dir

Create new empty file:
touch filename

Copy a directory (including subfolders and files) to a new one:
cp -r dir1 dir2

Copy a file:
cp filesrc filedest

Move a directory (including subfolders and files) to a new one:
mv dir1 dir2

Rename file and directory:
mv filedir filedirnew

Remove a file:
rm filename

Remove non-empty folder:
rm -r folder

Interactive remove a folder or file:
rm -i file

Edit file with vi:
vi filename

Enter insert mode vi:
i

Enter edit mode from insert mode vi:
ESC

Save and exit from vi:
ZZ
:wq

Save vi changes, but don't exit:
:w

Discard changes and exit:
:q!

View file using different command than vi:
cat filename

View large files:
less filename
Note: b - previous page; Space - next page; q - quit;

Add numbers to vi lines editing:
:set nu

Navigating file in vi, edit mode:
Arrow keys - move the cursor around
j, k, h, l - move the cursor down, up, left and right (similar to the arrow keys)
^ - move cursor to beginning of current line
$ - move cursor to end of the current line
nG - move to the nth line (eg 5G moves to 5th line)
G - move to the last line
w - move to the beginning of the next word
nw - move forward n word (eg 2w moves two words forwards)
b - move to the beginning of the previous word
nb - move back n word
{ - move backward one paragraph
} - move forward one paragraph

Delete commands in vi, edit mode:

x - delete a single character
nx - delete n characters (eg 5x deletes five characters)
dd - delete the current line
dn - d followed by a movement command. Delete to where the movement command would have taken you. (eg d5w means delete 5 words)

Undo changes in vi, edit mode:

u

Copy/Cut-Paste vi:

Position the cursor where you want to begin cutting.
Press v to select characters (or uppercase V to select whole lines).
Move the cursor to the end of what you want to cut.
Press d to cut (or y to copy).
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.

Wildcards:
* - Zero character or many of characters
? - Just one character
[] - Range of characters






Add data to Infragistics Grid using DataTable in C#

using System.Data;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;

.....................

DataTable table = new DataTable("Table");

//Create three columns that will hold sample data.
DataColumn column1 = new DataColumn("CCY", typeof(string));
DataColumn column2 = new DataColumn("Percentage", typeof(int));
            

//Add the three columns to the table.
table.Columns.AddRange(new DataColumn[] { column1, column2});
table.Rows.Add("EUR",20);
table.Rows.Add("DKK", 120);

//Add the table to the dataset.
//this.dataSet1.Tables.Add(table);
manualSpreadsheetControl1.DataSource = table;
............

Sunday, February 22, 2015

Perl on Amazon Ec2 Linux AMI: Can't locate Class.pm in @INC when using Path::Class

This error is fixed by using the following command:

sudo perl -MCPAN -e 'install Path::Class'

Install GCC on the Amazon Linux AMI instance

1. Connect to your instance using the following command (I'm using MAC OS Terminal):
sudo ssh -i Key.pem ec2-user@Public_IP

2. Launch the following command to install GCC:
sudo yum install gcc

3. Verify gcc is installed:
gcc --version

Saturday, February 21, 2015

Simple XSLT Example


1. Following XML is received as input

<?xml version="1.0" encoding="UTF-8"?>
<Teams>
<team>
<title>Real Madrid</title>
<country>Spain</country>
</team>
<team>
<title>Arsenal Londra</title>
<country>England</country>
</team>
</Teams>



2. Following code is transforming the above XML into HTML format:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2 style="font-family:arial">European Football Teams</h2>
    <table border="0" style="font-family:arial">
      <tr bgcolor="#9a0000" style="color:#fff">
        <th style="text-align:left">Name</th>
        <th style="text-align:left">Country</th>
      </tr>
      <xsl:for-each select="Teams/team">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="country"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>


3. And the HTML output:


More information when creating a new SSTP VPN connection to an Amazon AWS Windows Server


After creating a new SSTP connection and installing the certificate there are some additional steps that can be followed.

Those are in order not to route all Internet Traffic through the Amazon AWS Windows VPN and NAT server.

Here are the steps:

1. Right click the VPN connection adaptor -> Go to Properties and under Advanced config make sure "Use default gateway on remote network" is unchecked.

2. Connect to the VPN Server

3. As connection is succesful, there are no active routes to the private network instances. In order for this to be possible, following command needs to be run as administrator:
route add 10.0.1.10 mask 255.255.255 172.19.3.0

where:
10.0.1.10 - Private IP of the instance to be accessed via RDP
172.19.3.0 - VPN IP for the VPN and NAT Windows Server

4. You should now be able to RDP into the private instance.

5. The newly added routes should be automatically removed on VPN disconnect. If not, they can be automatically removed using:
route delete 10.0.1.10