Saturday, November 23, 2013

Moving Ellipse in Canvas using keyboard Events

This is a simple code that you can understand easily. Here KeyboardDown event is used which means whether any keyboard is pressed down. Don't mix it with down key arrow which I have mentioned in code.

XAML CODE
<Window x:Class="workingWithText1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" KeyDown="Window_KeyDown_1">
    <Grid>
        <Canvas Background="Green">
            <Ellipse Name="ball" Fill="WhiteSmoke" Width="100" Height="100"></Ellipse>
        </Canvas>
    </Grid>
</Window>


XAML.CS CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace workingWithText1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        int i = 0;
        private void Window_KeyDown_1(object sender, KeyEventArgs e)
        {
            if ((Keyboard.GetKeyStates(Key.Down) & KeyStates.Down) > 0)
            {
                Canvas.SetTop(ball, i++);
            }

            if ((Keyboard.GetKeyStates(Key.Left) & KeyStates.Down) > 0)
            {
                Canvas.SetLeft(ball, i--);
            }

            if ((Keyboard.GetKeyStates(Key.Right) & KeyStates.Down) > 0)
                Canvas.SetLeft(ball, i++);

            if ((Keyboard.GetKeyStates(Key.Up) & KeyStates.Down) > 0)
                Canvas.SetTop(ball, i--);
        }
    }
}

Note:
Here you can take multiple variables in place of for smooth motion. 

Saturday, February 23, 2013

Wildcards in Linux

Wildcards powerful feature in many languages where they have some special meaning while giving some command
i.e In html * is selector which selects all things *{}
Similarly in SQL database queries it selects all content according to command and in the same way it have some specific meaning in linux shells. Common wild cards with description is as fallows
WildcardMatches
*zero or more characters
?exactly one character
[abcde]exactly one character listed
[a-e]exactly one character in the given range
[!abcde]any character that is not listed
[!a-e]any character that is not in the given range
{debian,linux}exactly one entire word in the options given

Wildcard examples >

Let's have a few examples. Probably the * character is already familiar to you, because it's widely used in many other places, too, not just in Linux. For example, the following removes every file from the current directory:
rm *
The following command moves all the HTML files, that have the word "linux" in their names, from the working directory into a directory named dir1:
mv *linux*.html dir1
See, I told you that moving multiple files can be just as simple as moving only one file!
The following displays all files that begin with d and end with .txt:
less d*.txt
The following command removes all files whose names begin with junk., followed by exactly three characters:
rm junk.???
With this command you list all files or directories whose names begin with hda, followed by exactly one numeral:
ls hda[0-9]
This lists all files or directories beginning with hda, followed by exactly two numerals:
ls hda[0-9][0-9]
The following lists all files or directories whose name starts with either hd or sd, followed by any single character between a and c:
ls {hd,sd}[a-c]
This command copies all files, that begin with an uppercase letter, to directory dir2:
cp [A-Z]* dir2
This deletes all files that don't end with ceh or g:
rm *[!cehg]
I could continue on and on with these examples, but you get the idea. You can use simple patterns or combine different wildcards and construct very complex patterns, and like I said before, you can use them with any commands that accept file names as arguments.

Essential Linux CLI Commands.

Essential commands for surviving at the Linux CLI
Moving around in the file system
Command
Action
pwd
"Print working directory" - show what dir you're in usually it shows absolute path. 
ls
List the contents of a dir.
ls -l
List the contents of a dir and show additional info of the files.
ls -a
List all files, including hidden files.
cd
Change directory.
cd ..
Go to the parent directory.
Examining files
Command
Action
file
Determine the type of a file.
cat
Concatenate a file.
less
View text files and paginate them if needed.
Manipulating files and directories
Command
Action
cp
Copy a file.
cp -i
Copy a file and ask before overwriting.
cp -r
Copy a directory with its contents.
mv
Move or rename a file.
mv -i
Move or rename a file and ask before overwriting.
rm
Remove a file.
rm -r
Remove a directory with its contents.
rm -i
Ask before removing a file. Good to use with the -r option.
mkdir
Make a directory.
rmdir
Remove an empty directory.
Link http://www.tuxfiles.org/

Monday, January 14, 2013

How to protect your directory and specific files

When you write some directory in your xamp then it easily open because it is local for you but what if other body opens it... To stop from it you have do just following procedure.
1. Open notepad and save it as ".htaccess"
[warning: windows does not allow to create .files without names if you use any other way... just do as it is... ]
2. Now your directory saved you can check that by writing that link.

 What if you want that other body can only open my html files not others...

3. For that: the file you have created in which you will write
Options -indexes
<FilesMatch "\.(sqlite|xml)$">
     Deny From all
</FilesMatch> 

4. So in this way you can make your directory accessible and inaccessible
for what type of file you want.
Protecting your directory through .htaccess