Saturday, December 19, 2009

PHP string concatation

  1. $str1 = 'This ';
  2. $str2 = 'is a ';
  3. $str3 = 'test string';
  4. $full = $str1.$str2.$str3;
  5. echo $full;
  6. ?>

PHP string compare

  1. $str1 = "Test";
  2. $str2 = "Test";
  3. if ($str1 == "Test") echo "OK-1";
  4. if ($str1 == $str2) echo "OK-2";
  5. ?>

Tuesday, December 15, 2009

Shortcut command to Restart / Shutdown windows

XP : Click start -> Click "Run" -> Write : cmd
Vista, 7 : Click start -> Write : cmd

Then :
For a shortcut to RESTART Windows :
SHUTDOWN -r -t 01

For a shortcut to SHUT DOWN Windows :
SHUTDOWN -s -t 01

Monday, December 14, 2009

enable content search in windows

Content-searching can allow you to search files by what is contained within the file rather than the file-name. By default, Windows only search file names for locations that are unindexed, which can often bring frustration upon users who have Search Indexing disabled. By enabling content-searching, those who often forget filenames but remember the contents within a file can make their searching much more efficient.

searchbar.jpg

Re-enabling content-searching is very simple. First, you want to access your folder options from the Tools menu. If you don’t have the top navigation bar enabled by default, just press Alt.

folderoptions1.jpg

Click on the Search tab above to access your Search Functions. Below is a picture of the default search settings. Simply check the second button, “Always search file names and contents” to re-enable content searching. If you’re working with system files, you might also want to check the Include System Directories box below.
searchfoloptions.jpg

source : http://www.vistarewired.com/2007/03/17/how-to-search-files-by-content-data

Split screen, Notepad++

To split the screen in Notepad++ you have to right-click on the tab
with the current document and select "Clone to another view". The
screenshot at the following page explains how to switch between
horizontally and vertically split screens.

http://notepad-plus.sourceforge.net/commun/screenshots/scrsh_rotate.gif

This page explains how Notepad++ can be integrated with Stata similar
to the built-in Do-File Editor:

http://huebler.info/2008/20080427-stata.html

thanks to Friedrich

Tricks to make old Addons work on Firefox 3.5 or higher

The trick is to add some configurations in Firefox settings. All the changes you make from here on are done at your own risk. Do revert the settings if something goes wrong.

  1. Type about:config address bar of Firefox browser and hit enter. It will give you a warning. Just click the button “I’ll be careful, I promise!” and proceed…
  2. It will show a huge list of values. Now, right click any where in the free white-space on the screen and click on New –> Boolean, then name the Boolean as checkCompatibility – make it false in the next step.
  3. again right click and click on New -> Boolean and name as checkUpdateSecurity and choose false.
  4. After doing this changes to get the changes applied, Restart the Firefox browser. Now install the addon that was not supported or compatible by Firefox 3.5 and install it.
  5. Restart the Firefox browser once again. Now, the not compatible addon will work with Firefox 3.4

Hope you liked this trick.

Thanks to Blogote

Thursday, November 19, 2009

Funny !!!

valgrind: the 'impossible' happened:
Killed by fatal signal
==4660== at 0x3802088D: vgPlain_arena_malloc (m_mallocfree.c:190)
==4660== by 0x38035516: vgPlain_cli_malloc (replacemalloc_core.c:101)
==4660== by 0x380022F5: vgMemCheck_malloc (mc_malloc_wrappers.c:182)
==4660== by 0x38035BA7: do_client_request (scheduler.c:1158)
==4660== by 0x380372B1: vgPlain_scheduler (scheduler.c:869)
==4660== by 0x38051B59: run_a_thread_NORETURN (syswrap-linux.c:87)

sched status:
running_tid=1

Thread 1: status = VgTs_Runnable
==4660== at 0x4A05809: malloc (vg_replace_malloc.c:149)
==4660== by 0x4030B0: _readTime (commands.c:676)
==4660== by 0x402124: _processReceivedData (commands.c:361)
==4660== by 0x401EEC: _performReceive (commands.c:322)
==4660== by 0x401809: _performCommand (commands.c:225)
==4660== by 0x401340: commandCenter (commands.c:163)
==4660== by 0x400D39: main (Hj1.c:63)

Wednesday, November 18, 2009

strlen @ C

Take care of bastard, strlen in C does not take the last ending sign.

DESCRIPTION
The strlen() function calculates the length of the string
s, not including the terminating '\0' character.

Sunday, November 15, 2009

Saturday, November 14, 2009

Controlling Ctrl^C for quiting program, C programing

If you want Ctrl^C, not to jump out of program right away and give you a chance to save stuffs and get a backup here is the C code for it :

#include
#include
#include


void exit_program(int sig) {
printf("Wake up call ... !!! - Catched signal: %d ... !!\n", sig);
/* DO YOUR STUFFS BEFOR QUITING, if you dont want to wait for the 2nd
Ctrl^C from user you can just have the next commented line :*/
//exit(0);
(void) signal(SIGINT, SIG_DFL);//You need 2nd Ctrl^C to quit
}

int main(void) {
(void) signal(SIGINT, exit_program);
/* waits to read your signal(first Ctrl^C) while running rest of your code, on
Ctrl^C pressed will jump to exit_program method*/

while(1)
printf("I wanna catch Ctrl + C\n"), sleep(1);

return 0;
}

Giving your screen session a name

You can use screen -S name or (inside running session) - Ctrl+A :sessionname name

Wednesday, November 11, 2009

Vim/Vi command sheet

Cursor movement

  • h - move left
  • j - move down
  • k - move up
  • l - move right
  • w - jump by start of words (punctuation considered words)
  • W - jump by words (spaces separate words)
  • e - jump to end of words (punctuation considered words)
  • E - jump to end of words (no punctuation)
  • b - jump backward by words (punctuation considered words)
  • B - jump backward by words (no punctuation)
  • 0 - (zero) start of line
  • ^ - first non-blank character of line
  • $ - end of line
  • G - Go To command (prefix with number - 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert Mode - Inserting/Appending text

  • i - start insert mode at cursor
  • I - insert at the beginning of the line
  • a - append after the cursor
  • A - append at the end of the line
  • o - open (append) blank line below current line (no need to press return)
  • O - open blank line above current line
  • ea - append at end of word
  • Esc - exit insert mode

Editing

  • r - replace a single character (does not use insert mode)
  • J - join line below to the current one
  • cc - change (replace) an entire line
  • cw - change (replace) to the end of word
  • c$ - change (replace) to the end of line
  • s - delete character at cursor and subsitute text
  • S - delete line at cursor and substitute text (same as cc)
  • xp - transpose two letters (delete and paste, technically)
  • u - undo
  • . - repeat last command

Marking text (visual mode)

  • v - start visual mode, mark lines, then do command (such as y-yank)
  • V - start Linewise visual mode
  • o - move to other end of marked area
  • Ctrl+v - start visual block mode
  • O - move to Other corner of block
  • aw - mark a word
  • ab - a () block (with braces)
  • aB - a {} block (with brackets)
  • ib - inner () block
  • iB - inner {} block
  • Esc - exit visual mode

Visual commands

  • > - shift right
  • < - shift left
  • y - yank (copy) marked text
  • d - delete marked text
  • ~ - switch case

Cut and Paste

  • yy - yank (copy) a line
  • 2yy - yank 2 lines
  • yw - yank word
  • y$ - yank to end of line
  • p - put (paste) the clipboard after cursor
  • P - put (paste) before cursor
  • dd - delete (cut) a line
  • dw - delete (cut) the current word
  • x - delete (cut) current character

Exiting

  • :w - write (save) the file, but don't exit
  • :wq - write (save) and quit
  • :q - quit (fails if anything has changed)
  • :q! - quit and throw away changes

Search/Replace

  • /pattern - search for pattern
  • ?pattern - search backward for pattern
  • n - repeat search in same direction
  • N - repeat search in opposite direction
  • :%s/old/new/g - replace all old with new throughout file
  • :%s/old/new/gc - replace all old with new throughout file with confirmations

Working with multiple files

  • :e filename - Edit a file in a new buffer
  • :bnext (or :bn) - go to next buffer
  • :bprev (of :bp) - go to previous buffer
  • :bd - delete a buffer (close a file)
  • :sp filename - Open a file in a new buffer and split window
  • ctrl+ws - Split windows
  • ctrl+ww - switch between windows
  • ctrl+wq - Quit a window
  • ctrl+wv - Split windows vertically
Source : http://www.worldtimzone.com/res/vi.html

Tuesday, November 10, 2009

Write an array to file in C

int backItUp(){
FILE * hFile;
//************************
char *_fileName;
_fileName = getenv("USER");
char buffer[200];
struct timeval tv;
time_t curtime;
gettimeofday(&tv, NULL);
curtime=tv.tv_sec;
strftime(buffer,30,"%Y%m%d_%H%M",localtime(&curtime));
//"%m-%d-%Y %T"
strcat(_fileName,"_");
strcat(_fileName,buffer);
strcat(_fileName,".bak");
//*******************************
hFile = fopen( _fileName, "w");
if (hFile == NULL){
// Error, file not found
printf("*** Failed to open the file ***\n");
return FAILED;
}//end of if
else{
// Process & close file
int nWritten = fwrite(message, sizeof(SmsDBase), 200, hFile);
printf("*** Taking backup ***\n");
fclose(hFile);
}//end of else
return SUCCESS;
}//end of backItUp()

int readItUp(){
FILE * hFile;
hFile = fopen( ___fileName, "r");
if (hFile == NULL){
// Error, file not found
printf("*** Failed to open the file ***\n");
return FAILED;
}//end of if
else{
// Process & close file
int nRead = fread(message, sizeof(SmsDBase), 200, hFile);
fclose(hFile);
}//end of else
return SUCCESS;
}//end of _readItUp()

Sunday, November 08, 2009

list of Vim commands

The list of Vim commands :

http://www.tuxfiles.org/linuxhelp/vimcheat.html

copying folder in Linux / Unix terminal

cp -r /original/dir /copied/dir

Saving and quiting at Vim

If like me you wonder how the hell to write in Vim, make sure you are in the insert mode(The mode that you can actually write). You can do that by pressing i.

After finishing, you are supposed to save what you have written. So you press Esc button and then write :w. Then you can simply write :q to quit.

Pay attention that you can write commands(:w, :q, ...) in the command line and you can go to command line by pressing Esc button in Vim.

Good luck, it is a powerful editor, but as me, you got a long way a head to learn how to work with it.

Saturday, November 07, 2009

Showing Line Number while editing a file in Vi or Vim

While editing a document at Unix/Linux, press Esc button type

:set number

to have line numbers beside your editor. If you are tired of line numbers, enter the following to turn them off:

:set nonumber

Wednesday, November 04, 2009

Monday, November 02, 2009

instanceof example in Java

public class MainClass {
public static void main(String[] a) {

String s = "Hello";
if (s instanceof java.lang.String) {
System.out.println("is a String");
}
}

}

Monday, October 26, 2009

Installing Windows 7 from USB Drive

This guide works 100% for Vista & Windows 7 unlike most of the guides out there. I have seen many sites/blogs that have “Install Vista from USB guide” but either with incomplete steps or not working guide. I have also seen some guides that don’t’ use proper commands in this guide. After spending many hours I have come up with this 100% working guide.

Bootable USB drive

I just did this method on one of my friends machine and installed the new Windows 7 BETA. The main advantage is that by using USB drive you will be able to install Windows 7/Vista in just 15 minutes. You can also use this bootable USB drive on friend’s computer who doesn’t have a DVD optical drive.

The method is very simple and you can use without any hassles. Needless to say that your motherboard should support USB Boot feature to make use of the bootable USB drive.

Requirements:

*USB Flash Drive (Minimum 4GB)

*Windows 7 or Vista installation files.

Follow the below steps to create bootable Windows 7/Vista USB drive using which you can install Windows 7/Vista easily.

1. Plug-in your USB flash drive to USB port and move all the contents from USB drive to a safe location on your system.

2. Open Command Prompt with admin rights. Use any of the below methods to open Command Prompt with admin rights.

*Type cmd in Start menu search box and hit Ctrl+ Shift+ Enter.

Or

*Go to Start menu > All programs > Accessories, right click on Command Prompt and select Run as administrator.

3. You need to know about the USB drive a little bit. Type in the following commands in the command prompt:

First type DISKPART and hit enter to see the below message.

Bootable USB Drive

Next type LIST DISK command and note down the Disk number (ex: Disk 1) of your USB flash drive. In the below screenshot my Flash Drive Disk no is Disk 1.

4. Next type all the below commands one by one. Here I assume that your disk drive no is “Disk 1”.If you have Disk 2 as your USB flash drive then use Disk 2.Refer the above step to confirm it.

So below are the commands you need to type and execute one by one:

SELECT DISK 1

CLEAN

CREATE PARTITION PRIMARY

SELECT PARTITION 1

ACTIVE

FORMAT FS=NTFS

(Format process may take few seconds)

ASSIGN

EXIT

Don’t close the command prompt as we need to execute one more command at the next step. Just minimize it.

Bootable USB Drive

5. Next insert your Windows7/Vista DVD into the optical drive and check the drive letter of the DVD drive. In this guide I will assume that your DVD drive letter is “D” and USB drive letter is “H” (open my computer to know about it).

6. Maximize the minimized Command Prompt in the 4th step.Type the following command now:

D:CD BOOT and hit enter.Where “D” is your DVD drive letter.

CD BOOT and hit enter to see the below message.

7. Type another command given below to update the USB drive with BOOTMGR compatible code.

BOOTSECT.EXE/NT60 H:

14

Where “H” is your USB drive letter. Once you enter the above command you will see the below message. You might face an error – Access Denied for no priviledge in copying the bootsector to device. Solution to this is to just Exit the Command Prompt and Run it again (still need to Run as Administrator).

8. Copy your Windows 7/Vista DVD contents to the USB flash drive.

9. Your USB drive is ready to boot and install Windows 7/Vista. Only thing you need to change the boot priority at the BIOS to USB from the HDD or CD ROM drive. I won’t explain it as it’s just the matter the changing the boot priority or enabling the USB boot option in the BIOS.

Note: If you are not able to boot after following this guide means you haven’t set the BIOS priority to USB. If you got any problem in following this guide feel free to ask questions by leaving comment.


*** Main article taken from Source, but modified.

Monday, October 19, 2009

How to run Remote Desktop from CMD or RUN

To run Remote Desktop from CMD(windows command line) or run in start menu write :

mstsc.exe

or just simply

mstsc

Friday, October 16, 2009

user name @ Linux getenv("USER")

C Programming tips : getenv("USER"); is a method that returns a string that is your Linux user name(that you are logged in the terminal)

STRFTIME, your gateway to date and time in C !!!

"strftime" converts information from a time structure to a string form, and writes the string into the memory area pointed to by "string".

The "format" string tells what information is required and how it should be presented. It is much like the format string used by "printf". The format string consists of ordinary characters (which are copied directly into "*string") and placeholders consisting of a '%' followed by a letter. For a list over placeholders visit here.

concating two string in C

strcat takes two char * arguments and returns the concatenated string as a char *. Here's a simple use of strcat:
#include 
#include

int main() {
char str1[50] = "Hello ";
char str2[] = "World";

strcat(str1, str2);

printf("str1: %s\n", str1);

return 0;
}

Output:

str1: Hello World

Reading and Writing a pointer of continously memory to the file in C

int _backItUp(){
FILE * hFile;
//************************
char *_fileName;
_fileName = getenv("USER");
char buffer[200];
struct timeval tv;
time_t curtime;
gettimeofday(&tv, NULL);
curtime=tv.tv_sec;
strftime(buffer,30,"%Y%m%d_%H%M",localtime(&curtime));
//"%m-%d-%Y %T"
strcat(_fileName,"_");
strcat(_fileName,buffer);
strcat(_fileName,".bak");
//*******************************
hFile = fopen( _fileName, "w");
if (hFile == NULL){
// Error, file not found
printf("*** Failed to open the file ***\n");
return FAILED;
}//end of if
else{
// Process & close file
int nWritten = fwrite(allocatedMem, sizeof(unsigned char), (200*sizeof(SmsDB))+((75)*sizeof(unsigned char))+((200*3)*sizeof(dBlock)), hFile);
printf("*** Taking backup ***\n");
fclose(hFile);
}//end of else
return SUCCESS;
}//end of backItUp()

int _readItUp(){
FILE * hFile;
hFile = fopen( ___fileName, "r");
if (hFile == NULL){
// Error, file not found
printf("*** Failed to open the file ***\n");
return FAILED;
}//end of if
else{
// Process & close file
int nRead = fread(allocatedMem, sizeof(unsigned char), (200*sizeof(SmsDB))+((75)*sizeof(unsigned char))+((200*3)*sizeof(dBlock)), hFile);
fclose(hFile);
}//end of else
return SUCCESS;
}//end of _readItUp()

CTRL+D and CTRL+L signal handling


Code:
#include 

int main()
{
char c;
printf("Write: ");
scanf("%c", &c);
if(c == 0x0C) printf("ctrl+L was entered\n");
return 1;
}
but the execution of this doesnt..
Code:
#include 

int main()
{
char c;
printf("Write: ");
scanf("%c", &c);
if(c == 0x04) printf("ctrl+D was entered\n");
return 1;
}

ASCII Character Chart with Decimal, Binary and Hexadecimal Conversions

Character Name

Char

Code

Decimal

Binary

Hex

Null

NUL

Ctrl @

0

00000000

00

Start of Heading

SOH

Ctrl A

1

00000001

01

Start of Text

STX

Ctrl B

2

00000010

02

End of Text

ETX

Ctrl C

3

00000011

03

End of Transmit

EOT

Ctrl D

4

00000100

04

Enquiry

ENQ

Ctrl E

5

00000101

05

Acknowledge

ACK

Ctrl F

6

00000110

06

Bell

BEL

Ctrl G

7

00000111

07

Back Space

BS

Ctrl H

8

00001000

08

Horizontal Tab

TAB

Ctrl I

9

00001001

09

Line Feed

LF

Ctrl J

10

00001010

0A

Vertical Tab

VT

Ctrl K

11

00001011

0B

Form Feed

FF

Ctrl L

12

00001100

0C

Carriage Return

CR

Ctrl M

13

00001101

0D

Shift Out

SO

Ctrl N

14

00001110

0E

Shift In

SI

Ctrl O

15

00001111

0F

Data Line Escape

DLE

Ctrl P

16

00010000

10

Device Control 1

DC1

Ctrl Q

17

00010001

11

Device Control 2

DC2

Ctrl R

18

00010010

12

Device Control 3

DC3

Ctrl S

19

00010011

13

Device Control 4

DC4

Ctrl T

20

00010100

14

Negative Acknowledge

NAK

Ctrl U

21

00010101

15

Synchronous Idle

SYN

Ctrl V

22

00010110

16

End of Transmit Block

ETB

Ctrl W

23

00010111

17

Cancel

CAN

Ctrl X

24

00011000

18

End of Medium

EM

Ctrl Y

25

00011001

19

Substitute

SUB

Ctrl Z

26

00011010

1A

Escape

ESC

Ctrl [

27

00011011

1B

File Separator

FS

Ctrl \

28

00011100

1C

Group Separator

GS

Ctrl ]

29

00011101

1D

Record Separator

RS

Ctrl ^

30

00011110

1E

Unit Separator

US

Ctrl _

31

00011111

1F

Space

32

00100000

20

Exclamation Point

!

Shift 1

33

00100001

21

Double Quote

"

Shift ‘

34

00100010

22

Pound/Number Sign

#

Shift 3

35

00100011

23

Dollar Sign

$

Shift 4

36

00100100

24

Percent Sign

%

Shift 5

37

00100101

25

Ampersand

&

Shift 7

38

00100110

26

Single Quote

39

00100111

27

Left Parenthesis

(

Shift 9

40

00101000

28

Right Parenthesis

)

Shift 0

41

00101001

29

Asterisk

*

Shift 8

42

00101010

2A

Plus Sign

+

Shift =

43

00101011

2B

Comma

,

,

44

00101100

2C

Hyphen / Minus Sign

-

-

45

00101101

2D

Period

.

.

46

00101110

2E

Forward Slash

/

/

47

00101111

2F

Zero Digit

0

0

48

00110000

30

One Digit

1

1

49

00110001

31

Two Digit

2

2

50

00110010

32

Three Digit

3

3

51

00110011

33

Four Digit

4

4

52

00110100

34

Five Digit

5

5

53

00110101

35

Six Digit

6

6

54

00110110

36

Seven Digit

7

7

55

00110111

37

Eight Digit

8

8

56

00111000

38

Nine Digit

9

9

57

00111001

39

Colon

:

Shift ;

58

00111010

3A

Semicolon

;

;

59

00111011

3B

Less-Than Sign

<

Shift ,

60

00111100

3C

Equals Sign

=

=

61

00111101

3D

Greater-Than Sign

>

Shift .

62

00111110

3E

Question Mark

?

Shift /

63

00111111

3F

At Sign

@

Shift 2

64

01000000

40

Capital A

A

Shift A

65

01000001

41

Capital B

B

Shift B

66

01000010

42

Capital C

C

Shift C

67

01000011

43

Capital D

D

Shift D

68

01000100

44

Capital E

E

Shift E

69

01000101

45

Capital F

F

Shift F

70

01000110

46

Capital G

G

Shift G

71

01000111

47

Capital H

H

Shift H

72

01001000

48

Capital I

I

Shift I

73

01001001

49

Capital J

J

Shift J

74

01001010

4A

Capital K

K

Shift K

75

01001011

4B

Capital L

L

Shift L

76

01001100

4C

Capital M

M

Shift M

77

01001101

4D

Capital N

N

Shift N

78

01001110

4E

Capital O

O

Shift O

79

01001111

4F

Capital P

P

Shift P

80

01010000

50

Capital Q

Q

Shift Q

81

01010001

51

Capital R

R

Shift R

82

01010010

52

Capital S

S

Shift S

83

01010011

53

Capital T

T

Shift T

84

01010100

54

Capital U

U

Shift U

85

01010101

55

Capital V

V

Shift V

86

01010110

56

Capital W

W

Shift W

87

01010111

57

Capital X

X

Shift X

88

01011000

58

Capital Y

Y

Shift Y

89

01011001

59

Capital Z

Z

Shift Z

90

01011010

5A

Left Bracket

[

[

91

01011011

5B

Backward Slash

\

\

92

01011100

5C

Right Bracket

]

]

93

01011101

5D

Caret

^

Shift 6

94

01011110

5E

Underscore

_

Shift -

95

01011111

5F

Back Quote

`

`

96

01100000

60

Lower-case A

a

A

97

01100001

61

Lower-case B

b

B

98

01100010

62

Lower-case C

c

C

99

01100011

63

Lower-case D

d

D

100

01100100

64

Lower-case E

e

E

101

01100101

65

Lower-case F

f

F

102

01100110

66

Lower-case G

g

G

103

01100111

67

Lower-case H

h

H

104

01101000

68

Lower-case I

I

I

105

01101001

69

Lower-case J

j

J

106

01101010

6A

Lower-case K

k

K

107

01101011

6B

Lower-case L

l

L

108

01101100

6C

Lower-case M

m

M

109

01101101

6D

Lower-case N

n

N

110

01101110

6E

Lower-case O

o

O

111

01101111

6F

Lower-case P

p

P

112

01110000

70

Lower-case Q

q

Q

113

01110001

71

Lower-case R

r

R

114

01110010

72

Lower-case S

s

S

115

01110011

73

Lower-case T

t

T

116

01110100

74

Lower-case U

u

U

117

01110101

75

Lower-case V

v

V

118

01110110

76

Lower-case W

w

W

119

01110111

77

Lower-case X

x

X

120

01111000

78

Lower-case Y

y

Y

121

01111001

79

Lower-case Z

z

Z

122

01111010

7A

Left Brace

{

Shift [

123

01111011

7B

Vertical Bar

|

Shift \

124

01111100

7C

Right Brace

}

Shift ]

125

01111101

7D

Tilde

~

Shift `

126

01111110

7E

Delta

D

127

01111111

7F

Source : http://www.pcguide.com/res/tablesASCII-c.html