Cheat Sheet on programming and scripting languages


I found interesting articles '70+ Cheat Sheets On 22 Programming And Scripting Languages!' and '53 Cheatsheets For Programmers And Developers In Alphabetical Order! Here is the list of such cheat sheets, that I feel useful and relevant. 


All in one
http://www.cheat-sheets.org/
http://refcardz.dzone.com/

1. Apache
http://www.petefreitag.com/cheatsheets/apache/

Apache Ant
http://refcardz.dzone.com/refcardz/getting-started-apache-ant?oid=hom24765

Apache Cassandra
http://refcardz.dzone.com/refcardz/apache-cassandra

Apahce Hadoop
http://refcardz.dzone.com/refcardz/getting-started-apache-hadoop


2. awk
http://www.catonmat.net/download/awk.cheat.sheet.pdf

3. sed
http://www.catonmat.net/download/sed.stream.editor.cheat.sheet.pdf

4. ed
http://www.catonmat.net/download/ed.text.editor.cheat.sheet.pdf

5. C
http://www.digilife.be/quickreferences/QRC/C%20Reference%20Card%20%28ANSI%29%202.2.pdf

On Linux to link with Linux header files

5.1 with ctags
First run ctags
Modify ~/.vimrc file
set tags=linux/tags

5.2 without ctags
shift + k to go to man page
go to header file and then press gf to go header file

ctrl + o to come back from header file to original code. 


6. Core C# and .Net
http://www.digilife.be/quickreferences/QRC/C%20Reference%20Card%20%28ANSI%29%202.2.pdf

http://www.cheat-sheets.org/saved-copy/NETFX4-Poster.pdf

7. C# and VB.Net
http://aspalliance.com/625

8. String Formatting in C#
http://blog.stevex.net/string-formatting-in-csharp/

9. C++
http://cs.fit.edu/~mmahoney/cse2050/how2cpp.html
http://www.dreamincode.net/downloads/ref_sheets/cpp_reference_sheet.pdf


10. STL
http://www.digilife.be/quickreferences/QRC/STL%20Quick%20Reference%201.29.pdf

11. Eclipse Keyboard shortcut
http://eclipse-tools.sourceforge.net/shortcuts.html

12. C++ V/s Java
http://www4.ncsu.edu/~kaltofen/courses/Languages/JavaExamples/cpp_vs_java/

13. JavaScript
http://www.javascript.su/
https://www.addedbytes.com/cheat-sheets/javascript-cheat-sheet/
http://www.cheat-sheets.org/saved-copy/javascript_cheat_sheet.png


14. HTML Special Characters
http://www.webmonkey.com/2010/02/special_characters/

15. HTML
http://www.webmonkey.com/2010/02/html_cheatsheet/
http://www.cheat-sheets.org/saved-copy/html-cheat-sheet.png


16. Prototype JavaScript Library
http://www.snook.ca/files/prototype_1.5.0_snookca.pdf

17. RStudio
http://www.rstudio.com/resources/cheatsheets/

18. Calculus
http://tutorial.math.lamar.edu/pdf/Calculus_Cheat_Sheet_All.pdf

19. CSS
http://www.petefreitag.com/cheatsheets/css/

20. Debian Linux
http://www.cheat-sheets.org/saved-copy/refcard-en-a4.pdf

21. Django
http://www.cheat-sheets.org/saved-copy/django_reference_sheet.pdf

22. Locator 
XPATH, CSS, DOM, Selenium
http://www.cheat-sheets.org/saved-copy/Locators_table_1_0_2.pdf

23. Firebug
http://refcardz.dzone.com/refcardz/getting-started-firebug-15

24. Git
http://www.cheat-sheets.org/saved-copy/git-cheat-sheet.svg

25. Haskell
http://www.cheat-sheets.org/saved-copy/Haskell.CheatSheet.pdf


26. Java
http://www.cheat-sheets.org/saved-copy/java_quickref.pdf

27. JQuery
http://www.cheat-sheets.org/saved-copy/jQuery-1.5-Visual-Cheat-Sheet.pdf

28. Mathematica
http://www.cheat-sheets.org/saved-copy/mathematica-cheat-sheet.pdf

29. Matlab
http://www.cheat-sheets.org/saved-copy/matlab_quickref.pdf

30. MySQL
http://www.cheat-sheets.org/saved-copy/mysql_cheat_sheet.png

31. Design Pattern
http://refcardz.dzone.com/refcardz/design-patterns

32. OpenStack
http://refcardz.dzone.com/refcardz/getting-started-openstack-most

33. Nmap
http://www.cheat-sheets.org/saved-copy/Nmap5.cheatsheet.eng.v1.pdf

34. Oracle / SQL
http://www.cheat-sheets.org/saved-copy/oracle_sql_reference.pdf
http://www.sql.su/

SQLLite
http://www.cheat-sheets.org/own/sqlite/Syntax.Diagrams.For.SQLite.html

35. Python
http://www.cheat-sheets.org/saved-copy/PQRC-2.4-A4-latest.pdf

36. Scala
http://www.cheat-sheets.org/saved-copy/Scala_Cheatsheet.pdf

37. Wordpress
http://www.cheat-sheets.org/saved-copy/wpcs.png

38. XML
http://www.cheat-sheets.org/saved-copy/XMLquickref.pdf

39. Shell Script
http://www.cheat-sheets.org/saved-copy/shellscripcheatsheet.pdf

40. Linux, Unix, Ubuntu
http://www.cheat-sheets.org/saved-copy/ubunturef.pdf
http://www.cheat-sheets.org/saved-copy/unix_command_quickref.pdf
http://www.pixelbeat.org/cmdline.html
http://jd40c.com/linux.html


Linux Tips and Tricks



People write blogs, so that when needed they can refer. I read this article  “55 Best Linux Tips, Tricks And Command Lines”. Let me list down this points, that I am not aware of.

Run a Linux command after every reboot 

$crontab -e

@reboot /home/xyz/myscript.sh

Do remember to enable crond on boot.

Know your shells

Here is a command that will let you know about the available shells on your Linux distribution:

#chsh -l

To change your login shell, use the following command: 

# chsh

LS

lspci – Lists all PCI devices. Use -v for verbose output.
lsusb – Lists all USB devices. Use -v for verbose output.
lsmod – Lists the status of modules in the Linux kernel.
lsattr – Lists file attributes on a second extended Linux file system.
lsof – Lists the file descriptors opened by all the processes. A very useful command when a process fails to close any file descriptors.
ls -l --color=auto

ls -lSr Show files by size, biggest last
pushd . Put current dir on stack so you can popd back to it

View the contents of tar and rpm files

1. To view the content of a tar file, issue the following command:

#tar -tvf /path/to/file.tar

2. To view the content of an rpm file, use the command given below:

#rpm -qlp /path/to/file.rpm



Check your processor and OS architecture

$ uname -m
$ lshw -class processor | grep width
$ uname -a
Kernel version and system architecture 

Ignoring the case during TAB-completion

set completion-ignore-case on

Identify your current shell name

$ echo $SHELL
$ echo $0

Built in variables:

$1-$N Stores the arguments (variables) that were passed to the shell program from the command line.
$? Stores the exit value of the last command that was executed.
$0 Stores the first word of the entered command (the name of the shell program).
$* Stores all the arguments that were entered on the command line ($1 $2 ...).
"$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...).


Scan open ports

TCP
nmap -sS -O 
UDPnmap -sU -O 

To find out last word

$cat fileinfo.txt | rev | awk '{print $1}' | rev

Know the libraries used by a program

ldd

Undo your changes even after quitting the VIM editor
As all of us know, if you make changes in a file using VIM editor, the changes are permanent and you cannot get the old version back after you save and quit the editor.
But VIM v7.3 allows you to get the old version back even after quitting the editor.
Here is a tip that shows you how to configure VIM to remember changes.
To enable Undo, execute the following commands in VIM just before starting to edit the file.
:set undofile
:set undodir=/tmp
This is to be done every time you start editing a file. In case you need the configuration to be there for all files that you open in VIM, create a file called '.exrc' or '.vimrc' in $HOME directory. In my case, it is /myhome. 
Open the just created file and add the following commands:
# vi /myhome/.exrc
set undofile
set undodir=/tmp
Save and close the file.
:wq
From now onwards, the Undo history is maintained in the background for all files that you edit with VIM. 

Measuring the network throughput between two Linux systems 

Iperf is a tool that measures the bandwidth and the quality of a network link. It can be installed very easily on any Linux system. One host must be set as the client and the other one as the server. Make sure that iperf is installed on both systems. If it is not installed, then use your package manager to install it before trying this tip.

Now run iperf on one of the Linux systems as the server, as shown below:

linux-erv3:/home/test/Desktop # iperf -s

------------------------------------------------------------
Server listening on TCP port 5001

TCP window size: 85.3 KByte (default)
------------------------------------------------------------

Go to the second Linux system and run iperf -c as the client:

linux-6bg3:~ # iperf -c 192.168.1.100

------------------------------------------------------------
Client connecting to 192.168.1.100, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------

[ 3] local 192.168.1.109 port 39572 connected with 192.168.1.100 port 5001

^C[ ID] Interval Transfer Bandwidth

[ 3] 0.0- 6.3 sec 6.38 MBytes 8.51 Mbits/sec

By default, the iperf client connects to the iperf server on the TCP port 5001 and the bandwidth displayed by iperf is the bandwidth from the client to the server. In the above example, it is 8.51 Mbits/sec between two Linux test systems connected over a wireless network.

Print a file with line numbers 

$nl file.c > output.txt

Power yourself with Netstat 

netstat -punta

To display the kernel interface table:
netstat -i
To display the kernel routing table:
netstat -rn
To display all open network sockets:
netstat -uta
To display network statistics:
netstat -s


BASH Script


Numeric Comparisons

int1 -eq int2 Returns True if int1 is equal to int2.
int1 -ge int2 Returns True if int1 is greater than or equal to int2.
int1 -gt int2 Returns True if int1 is greater than int2.
int1 -le int2 Returns True if int1 is less than or equal to int2
int1 -lt int2 Returns True if int1 is less than int2
int1 -ne int2 Returns True if int1 is not equal to int2

String Comparisons

str1 = str2 Returns True if str1 is identical to str2.
str1 != str2 Returns True if str1 is not identical to str2.
str Returns True if str is not null.
-n str Returns True if the length of str is greater than zero.
-z str Returns True if the length of str is equal to zero. (zero is different than null)

File Comparisons

-d filename Returns True if file, filename is a directory.
-f filename Returns True if file, filename is an ordinary file.
-r filename Returns True if file, filename can be read by the process.
-s filename Returns True if file, filename has a nonzero length.
-w filename Returns True if file, filename can be written by the process.
-x filename Returns True if file, filename is executable.


Expression Comparisons

!expression

Returns true if expression is not true
expr1 -a expr2

Returns True if expr1 and expr2 are true. ( && , and )
expr1 -o expr2



Returns True if expr1 or expr2 is true. ( ||, or )

Convert images to ascii art


$ asciiview Tux.png -driver curses

To download a web page(s):
#wget -m -r -l5

Show information about mounted volumes:
#df -h

Networking

  ethtool eth0 Show status of ethernet interface eth0
  ethtool --change eth0 autoneg off speed 100 duplex full Manually set ethernet interface speed
  iw dev wlan0 link Show link status of wireless interface wlan0
  iw dev wlan0 set bitrates legacy-2.4 1 Manually set wireless interface speed
iw dev wlan0 scan List wireless networks in range
ip link show List network interfaces
  ip link set dev eth0 name wan Rename interface eth0 to wan
  ip link set dev eth0 up Bring interface eth0 up (or down)
ip addr show List addresses for interfaces
  ip addr add 1.2.3.4/24 brd + dev eth0 Add (or del) ip and mask (255.255.255.0)
ip route show List routing table
  ip route add default via 1.2.3.254 Set default gateway to 1.2.3.254
ss -tupl List internet services on a system
ss -tup List active connections to/from system
host pixelbeat.org Lookup DNS ip address for name or vice versa
hostname -i Lookup local ip address (equivalent to host `hostname`)
whois pixelbeat.org Lookup whois info for hostname or ip address

Text Manipulation

  sed 's/string1/string2/g' Replace string1 with string2
  sed 's/\(.*\)1/\12/g' Modify anystring1 to anystring2
  sed '/^ *#/d; /^ *$/d' Remove comments and blank lines
  sed ':a; /\\$/N; s/\\\n//; ta' Concatenate lines with trailing \
  sed 's/[ \t]*$//' Remove trailing spaces from lines
  sed 's/\([`"$\]\)/\\\1/g' Escape shell metacharacters active within double quotes
seq 10 | sed "s/^/      /; s/ *\(.\{7,\}\)/\1/" Right align numbers
seq 10 | sed p | paste - - Duplicate a column
  sed -n '1000{p;q}' Print 1000th line
  sed -n '10,20p;20q' Print lines 10 to 20
  sed -n 's/.*\(.*\)<\/title>.*/\1/ip;T;q'<span class="Apple-tab-span" style="white-space:pre"> </span>Extract title from HTML web page</font></p> <p> <font face="Verdana, sans-serif"> <span class="Apple-tab-span" style="white-space:pre"> </span>sed -i 42d ~/.ssh/known_hosts<span class="Apple-tab-span" style="white-space:pre"> </span>Delete a particular line</font></p> <p> <font face="Verdana, sans-serif"> <span class="Apple-tab-span" style="white-space:pre"> </span>sort -t. -k1,1n -k2,2n -k3,3n -k4,4n<span class="Apple-tab-span" style="white-space:pre"> </span>Sort IPV4 ip addresses</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>echo 'Test' | tr '[:lower:]' '[:upper:]'<span class="Apple-tab-span" style="white-space:pre"> </span>Case conversion</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>tr -dc '[:print:]' < /dev/urandom<span class="Apple-tab-span" style="white-space:pre"> </span>Filter non printable characters</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>tr -s '[:blank:]' '\t' </proc/diskstats | cut -f4<span class="Apple-tab-span" style="white-space:pre"> </span>cut fields separated by blanks</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>history | wc -l<span class="Apple-tab-span" style="white-space:pre"> </span>Count lines</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>seq 10 | paste -s -d ' '</font></p> <p> <font face="Verdana, sans-serif"><br></font></p> <p> <font face="Verdana, sans-serif"><b>Debugging</b></font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>strace -c ls >/dev/null<span class="Apple-tab-span" style="white-space:pre"> </span>Summarise/profile system calls made by command</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>strace -f -e open ls >/dev/null<span class="Apple-tab-span" style="white-space:pre"> </span>List system calls made by command</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>strace -f -e trace=write -e write=1,2 ls >/dev/null<span class="Apple-tab-span" style="white-space:pre"> </span>Monitor what's written to stdout and stderr</font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>ltrace -f -e getenv ls >/dev/null<span class="Apple-tab-span" style="white-space:pre"> </span>List library calls made by command</font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif"></font></p> <p> <font face="Verdana, sans-serif">•<span class="Apple-tab-span" style="white-space:pre"> </span>tcpdump not port 22<span class="Apple-tab-span" style="white-space:pre"> </span>Show network traffic except ssh. See also tcpdump_not_me</font></p> <div> <br></div> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif"><br></font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif"><b>Ref: </b></font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif"><br></font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif">http://www.cheat-sheets.org/saved-copy/ubunturef.pdf</font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif">http://www.cheat-sheets.org/saved-copy/unix_command_quickref.pdf</font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif">http://www.pixelbeat.org/cmdline.html</font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif">http://jd40c.com/linux.html</font></p> <p> <font data-blogger-escaped-style="background-color: white; font-family: verdana; text-align: start;" face="Verdana, sans-serif"><br></font></p> </div> <p> <font face="Verdana, sans-serif"><font style="background-color: white; text-align: justify;"><b><br></b></font></font></p> </div> </div>

* Delete line above current line at VIM : dgg
* Delete line above at VIM : jdG