#Ruby can handle both integars and floating points twenty=20 one_point_two=1.2 #we can add this putting a # before a variable prints puts "twenty + one_point_two = #{twenty+one_point_two}" puts 4+4.0 #puts 4+"Ajay" # <=== Try this you will get an error =begin you can use an underscore as a thousands divider when writing long numbers; Ruby ignores the underscore. This makes it easy to read large numbers: =end billion=1_000_000_000 puts billion #creating an Array first_array = [] #empty array second_array = Array.new #empty array third_array =[1,2,3] puts third_array first_array.push("Ajay") second_array[0]="Different ways of adding an object to array" puts first_array puts second_array fourth_array = Array.new(20) #created an array of size 20 puts fourth_array.size puts fourth_array.length names = Array.new(4, "Ajay") #names has 4 objects puts "#{names}" puts names.lengthLearn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Tuesday, March 31, 2015
Hands on Ruby Numbers and Arrays
Hands on ruby:Install,run,hello world
1.Install from Terminal
sudo apt-get install ruby2.0 ruby2.0-dev
2.How to run a program? There are two ways to do it.
a.Interactive ruby shell Open your terminal(Ctrl+alt+t)
Type irb and hit enter.
Voila you can start typing your commands here
b.Type all your commands and save it as filename.rb
open your terminal ruby filename.rb
3.Every thing in ruby is an object including numbers
sudo apt-get install ruby2.0 ruby2.0-dev
2.How to run a program? There are two ways to do it.
a.Interactive ruby shell Open your terminal(Ctrl+alt+t)
Type irb and hit enter.
Voila you can start typing your commands here
b.Type all your commands and save it as filename.rb
open your terminal ruby filename.rb
3.Every thing in ruby is an object including numbers
puts "Hello World" puts "puts is like \n 1.printf in C \n 2. cin in C++ \n 3.System.out.print in java \n4.print in Python\n" puts " # is a Single line comment" =begin This is multiline comment Every thing in between =begin and =end is a multi line comment =end languagge = "Ruby" #variable languagge has a value Ruby puts "Hello #{languagge}" puts 4 #Number is an object in ruby puts 4+4 puts 4.class #puts 4.methods # Displays all methods that you can call on a numberLearn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Monday, March 30, 2015
Finding Patterns Multiplication of 2 digit number part 2
for i in range(25,100,10): print(str(i)+"*"+str(i)+"=",i*i) for j in range(10,80,10): print(str(i)+"*"+str(i+j)+"=",i*(i+j)) print"" """ Results There is a sequence observe the first digits they are (6,8,11,13,16,18...)(2,3,2,3,2,3...)(6+2,8+3,11+2,13+3...) I know 25*25 = 625 (25*25=(2*3)25)==>625 To get 25*35 all i need to do do is add 2 to 6 = 8 and change 25 to 75 so final answer would be 875 ('25*25=', 625) ('25*35=', 875) ('25*45=', 1125) ('25*55=', 1375) ('25*65=', 1625) ('25*75=', 1875) ('25*85=', 2125) ('25*95=', 2375) There is a sequence (12,12+3,15+4,19+3,22+4,26+3). Addition of (3,4,3,4,3,4)... ('35*35=', 1225) ('35*45=', 1575) ('35*55=', 1925) ('35*65=', 2275) ('35*75=', 2625) ('35*85=', 2975) ('35*95=', 3325) ('35*105=', 3675) Addition of (4,5,4,5,4,5)... ('45*45=', 2025) ('45*55=', 2475) ('45*65=', 2925) ('45*75=', 3375) ('45*85=', 3825) ('45*95=', 4275) ('45*105=', 4725) ('45*115=', 5175) Addition of (5,6,5,6,5,6) ('55*55=', 3025) ('55*65=', 3575) ('55*75=', 4125) ('55*85=', 4675) ('55*95=', 5225) ('55*105=', 5775) ('55*115=', 6325) ('55*125=', 6875) ('65*65=', 4225) ('65*75=', 4875) ('65*85=', 5525) ('65*95=', 6175) ('65*105=', 6825) ('65*115=', 7475) ('65*125=', 8125) ('65*135=', 8775) ('75*75=', 5625) ('75*85=', 6375) ('75*95=', 7125) ('75*105=', 7875) ('75*115=', 8625) ('75*125=', 9375) ('75*135=', 10125) ('75*145=', 10875) ('85*85=', 7225) ('85*95=', 8075) ('85*105=', 8925) ('85*115=', 9775) ('85*125=', 10625) ('85*135=', 11475) ('85*145=', 12325) ('85*155=', 13175) ('95*95=', 9025) ('95*105=', 9975) ('95*115=', 10925) ('95*125=', 11875) ('95*135=', 12825) ('95*145=', 13775) ('95*155=', 14725) ('95*165Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Sunday, March 29, 2015
Finding Patterns two digit multiplication part 1
21 * 21 step 1 20 * 20 =400 step 2 20*1 1*20 ----- 40 Step 3 1*1 step 4 441 Base Method base is 2 21 *21 = 2*(21+1)|(1*1) =44|1=441 21*22 =2*(21+2)|2=462 21*23=2*(24)6 = 486 21*24=2*(25)|4=504 visualise 21*26 considering base 20 21 1(1 away from base 20) 26 6(6 away from base 20) ---------- 21+6|1*6 21+6 or 26+1 followed by 1*6 27|6 27*2|6 546 So within 20 or 30 we can do these caluclations easily Base 30 33*34 37*3|12 111|12 1122 or 33*34 I know 35*35=1225 (35-2)*(35-1) 1227-105 1122Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Finding Patterns Multiplication by 19 the harder way
for i in range(1,30): print (str(19)+"*"+str(i)+"=",19*i) print "difference=",((19*(i+1))/10 - (19*i)/10) print("=======================================") """ Multiplication by 19 ==> The harder way Many would suggest ==> 1| 3|5| 7|9|11| 13| 15| 17|19 ==> odd numbers(1,3,5..) 9| 8|7| 6|5|4 | 3 | 2 | 1 | 0 ==> numbers from 9,8,7.... ------------------------------ 19,38,57,76....... It's easy but you should write it down This is for kids ==> Rather than by heart just know that 19*n=(2*n)-1 ==> This will be first digit From the observations 19*36=?? Once you know 19 table it's not a big deal but sometime for starters it's a mess to remember numbers. I assume you know 2 table;i assume you know compliment of a number; for compliment pairs ==> (1,9),(2,8),(3,7),(4,6),(5,5),(6,4),(7,3),(8,2),(9,1) Ex : 19* x = (2x-1)[compliment of x] 19*36==> (2*3 - 1)7 [compliment of 3 is 7] and (2*6 -1)4 [compliment of 6 is 4]==> 57 114 ==> 11 carry over ==> 57+11 =68==>684 """
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Never ever mess with compizconfig setting manager
I had a very bad experience,when i messed up with CCSM.
Compiz /kɒmpɪz/ is a compositing window manager for the X Window System, using 3D graphics hardware to create fast compositing desktop effects for window management. Effects, such as a minimization animation or a cube workspace, are implemented as loadable plugins.
What i did is
Ctrl+alt+f2
Enter your login and password.
This worked for me.But there is an alternative method which didn't work for me.
Don't get too much lost in the looks of ubuntu.I regret when everything on system started to behave weired.So you can have conky themes..but if you are person who want to show off install the other ubuntu based os like elementary os.
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Compiz /kɒmpɪz/ is a compositing window manager for the X Window System, using 3D graphics hardware to create fast compositing desktop effects for window management. Effects, such as a minimization animation or a cube workspace, are implemented as loadable plugins.
What i did is
Ctrl+alt+f2
Enter your login and password.
rm -r ~/.config
rm -r ~/.compiz
sudo restart lightdm
This worked for me.But there is an alternative method which didn't work for me.
Don't get too much lost in the looks of ubuntu.I regret when everything on system started to behave weired.So you can have conky themes..but if you are person who want to show off install the other ubuntu based os like elementary os.
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Grub Rescue
In grub you will see a prompt like this.
grub and grub rescue has slight variations in commands.If you have grub-rescue shell,skip to the end.
grub>
grub> set pager=1
no space between = and 1;it invokes pager for large command outputs.
grub> ls
(hd0) (hd0,msdos2) (hd0,msdos1)
The ls commands shows all partitions.This may vary from computer to computer.
But you will see similar listing of partitions
grub> ls (hd0,1)/
lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/ lib/
lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/
srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old
initrd.img initrd.img.old
ls on every partition till you find an output like this.This is the root file system.
grub> cat (hd0,1)/etc/issue
Ubuntu 14.04 LTS \n \l
Use cat to read etc file to dermine the linux if you have multiple linuxes.
Booting From grub>
if root file system is on (hd0,1) and vmlinuz-3.13.0-29-generic(The third line sets the initrd file, which must be the same version number as the kernel.).
And if you have (hd0,1) then root=/dev/sda1;
If you have hd0,1 = /dev/sda1. hd1,1 = /dev/sdb1. hd3,2 = /dev/sdd2.
grub> set root=(hd0,1)
grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub> initrd /boot/initrd.img-3.13.0-29-generic
grub> boot
If this didn't work then,try these.
grub> set root=(hd0,1)
grub> linux /vmlinuz root=/dev/sda1
grub> initrd /initrd.img
grub> boot
But if you are on grub rescue then commands vary
grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.13.0-29-generic
grub rescue> boot
Making Permanent Repairs
When you have successfully booted your system, run these commands to fix GRUB permanently:
Caution: Third Line from bottom grub-install /dev/sda.Don't use sda1 or anyother number after it.you
may use sdb but don't include any number
# update-grub
Generating grub configuration file ...
Found background: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found background image: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found linux image: /boot/vmlinuz-3.13.0-29-generic
Found initrd image: /boot/initrd.img-3.13.0-29-generic
Found linux image: /boot/vmlinuz-3.13.0-27-generic
Found initrd image: /boot/initrd.img-3.13.0-27-generic
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Saturday, March 28, 2015
From Noob to ubuntu pro terminal commands
Source
The Ubuntu Terminal is very complex and useful tool that all Linux distributions use.
The terminal is more then often a huge barrier for a new Linux user and may be keeping them from effectively using the Linux system.
So many users have been using point and click methods of desktop navigation since MS-DOS. Typing text into a command window can be a bit overwhelming for today’s average user but it shouldn’t be.
Some of the advantages of using the command-line Terminal to accomplish tasks are great.
The speed of using the terminal is a fraction of time that it takes to accomplish the same task graphically.
Once you’ve opened the Terminal with your first click you can type and execute commands faster.
Using Terminal – Ubuntu
Lets get started, there are two ways to get to the terminal one you can open the Dash Home and search for “Terminal” to open it. or you can simply press (CTRL+ALT+T) at the same time and a terminal will pop up for you.
Here is what the Terminal looks like.
cam@h@ck3r:~$Now that you know how to open the terminal here are a few basic commands that will help you on your way to becoming a better Linux user, NOTE: be careful what you do here.
Managing Privileges & Rights to Files and Directories
» chmod — Change Mode» su — Switch User
» sudo — run command as root
» sudo -r — open a root shell as user
» sudo -r -u user — open a shell as user
» sudo -k — forget sudo passwords
» gksudo — visual sudo dialog (GNOME)
» kdesudo — visual sudo dialog (KDE)
» sudo visudo — edit /etc/sudoers
» gksudo nautilus — root file manager (GNOME)
» dkesudo konqueror — root file manager (KDE)
Movement In The directory
» cd — Change Directory» pwd — Print Working Directory
Managing Files and Text
» cp — Copy» ls — List
» mkdir – Make Directory
» mv — Move
» rm — Remove
» grep — Search for Text Strings
» head — Display Start of File
» less — Display Part of File
» more — Display Part of File
» tail — View the End of a File
Managing the Display
» sudo /etc/init.d/gdm restart — restart X and return to login (GNOME)» sudo /etc/init.d/kdm restart — restart X and return to login (KDE)
» sudo dexconf — reset xorg.conf configuration
» CTRL+ALT+BKSP — restart X display if froxen
» CTRL+ALT+FN — switch to tty N
» CTRL+ALT+F7 — switch back to X display
Managing Packages
» apt-get update — refresh abailable updates» apt-get upgrade — upgrade all packages
» apt-get dist-upgrade — upgrade with package replacements; upgrade Ubuntu Version
» apt-get install pkgname — install package by name
» apt-get purge pkgname — uninstall package by name
» apt-get autoremove — remove obsolete packages
» apt-get -f install — try to fix broken packages
» dpkg –configure -a — try to fix broken packages
» dpkg -i pkg.deb — install file pkg.deb
Special Packages
» ubuntu-desktop — standard Ubuntu environment» kubuntu-desktop — KDE desktop
» xubuntu-desktop — XFCE desktop
» ubuntu-minimal — core Ubuntu utilities
» ubuntu-standard — standard Ubuntu utilities
» ubuntu-restricted-extras — non-free, but useful
» kubuntu-restricted-extras — KDE non-free, but useful
» xubuntu-restricted-extras — XFCE non-free, but useful
» build-essential — packages used to compile programs
» linux-image-generic — latest generic kernel image
» linux-headers-generic — latest build headers
Managing System Services
» start service — start job service (Upstart)» stop service — stop job service (Upstart)
» status service — check if service is running (Upstart)
» /etc/init.d/service start — start service (SysV)
» /etc/init.d/service stop — stop service (SysV)
» /etc/init.d/service status — check service (SysV)
» /etc/init.d/service restart — restart service (SysV)
» runlevel — get current runlevel
Managing System and Program Information
» cal — Calendar» date — Date
Troubleshooting
» fsck — File System CheckSystem
while holding down ALT and PRINTSCRN type this command with about 1 second between each letter.» REISUB — Your system will reboot
» lsb-release -a — get Ubuntu version
» uname -r — get kernel version
» uname -a — get all kernel information
Managing Network Connections
» chkconfig — Check Activated Services» ping — Test Network Connections
» ftp — file Transfer Protocol
» host — Check IP of Domain
» ifconfig — show network information
» iwconfig — show wireless incormation
» sudo iwlist scan — scan for wireless networks
» ifup eth0 — bring interface eth0 online
» ifdown eth0 — disable eth0 interface
» netstat — Display Routing Table
» route — Set Routes
» telnet — Connect to telnet
» traceroute — Display Route
Managing A Firewall
» ufw enable — turn on firewall» ufw disable — turn off firewall
» ufw default allow — allow all connections by default
» ufw default deny — drop all connections by default
» ufw status — cyrrebt status and rules
» ufw allow port — allow traffic on port
» ufw deny port — block port
» ufw deny from ip — bkicj ip address
Manage Drives and Formats
» mount — Mount a Drive» umount — Unmount Drive
» fdisk — Format Disk
» dd — Dupliate Disk
» df — Disk Free Space
Managing Users and Groups
» passwd — Create Password» groupadd — Add a Group
» groupmod — Modify a Group
» chgrp — Change Group
» groupdel — Delete Group
Applications
» nautilus — file manager (GNOME)» dolphin — file manager (KDE)
» konqueror — web browser (KDE)
» kate — text editor (KDE)
» gedit — text editor (GNOME)
Note: you can get more information about a command by using ‘man’ followed by the command you need the info about. This will give you information about the ‘grep’ command
$ man grep
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Environmental variable in ubutnu mycat implementation
""" . This directory or current directory .. The parent directory cd - Change to previous directory Usage: cd . cd .. There's output from my computer at the end of this post. To display last working directory echo $OLDPWD Demo: cam@hack3r:~$ pwd /home/cam cam@hack3r:~$ cd /var/tmp cam@hack3r:/var/tmp$ pwd /var/tmp cam@hack3r:/var/tmp$ echo $OLDPWD /home/cam cam@hack3r:/var/tmp$ cd - /home/cam cam@hack3r:~$ pwd /home/cam cam@hack3r:~$ How to implement your version of cat question:why do i need to implement another cat version? Ans: If you install java jdk or django..you would know. If you don't add into environmental path,then you can't run that program from other directories cam@hack3r:~$ which cat /bin/cat cam@hack3r:~$ That executable is at /bin/cat Click on computer browse through bin folder and you'll find cat(a diamond shaped file) copy and paste it on Desktop;now rename it to mycat ================================================================================================ cam@hack3r:~/Desktop$ ls 1 1~ 2 2~ D msf_install.sh~ mycat trytac.txt Untitled Document~ cam@hack3r:~/Desktop$ mycat 1 No command 'mycat' found, did you mean: Command 'mmcat' from package 'sleuthkit' (universe) Command 'mlcat' from package 'svtools' (multiverse) Command 'mscat' from package 'libpwiz-tools' (universe) Command 'mcat' from package 'mtools' (main) mycat: command not found cam@hack3r:~/Desktop$ ./mycat 1 hi i'm in 1 i'm last line cam@hack3r:~/Desktop$ =================================================================================================== cam@hack3r:~$ pwd /home/cam cam@hack3r:~$ cd / cam@hack3r:/$ pwd / cam@hack3r:/$ cd /home/cam/Desktop/D cam@hack3r:~/Desktop/D$ pwd /home/cam/Desktop/D cam@hack3r:~/Desktop/D$ cd . cam@hack3r:~/Desktop/D$ cd .. cam@hack3r:~/Desktop$ """
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
MAN Command in ubuntu explained
""" man command revisited man ls it displays huge output... You need to hit enter to move down...but it does move only 1 line... you use space,it displays page by page rather line by line. use g to goto top of the page use [shift+g] to move to down of the page. q to quit Environmental Variables == Storage location that has name and value. ==>Mostly uppercase names PATH is one of the environmental variables. echo $PATH (we have to use $ sign before the variable) Output cam@hack3r:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/cam/bin:/usr/local/java/jdk1.8.0_40/bin This will not be same for you; they are different paths separated by ':' Long back I've installed oracle java jdk and added to environmental variables.It's showing the path of jdk. Question: Why are there so many paths?? If you type a command then it is first searched in all the paths starting from /usr/local/sbin (this is for my laptop). If the command typed by you is not in the path then it will display command not found. which command You might want to know in "which" path does ls reside.you can find that by using wich command which ls cam@hack3r:~$ which ls /bin/ls cam@hack3r:~$ which man /usr/bin/man Note: Which doesn't work for builtins;so don't try it on cd """
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
what exactly is a Shell in ubuntu or Linux
shell ==>
1.The default interface to linux
2. The program that accepts your commands and execute those commands
3. Also called commandline interpreter
To acess it on ubuntu desktop/laptop(ctrl+alt+t)
when shell(Terminal emulator application) is opened it shows you prompt.Prompt waits for you to type something in it.
(type whoami)
question: Why use a CLI when we have graphical interdace?
If you want to acess some linux server ,most server distributions doesn't include GUI.
There will be many tedious tasks like renaming a 1000 files....
So in GUI you have to right click and rename,but if you get familiar with commandline you can do it with a command..
Normal VS root
A prompt will typically look like
[username@computername ~]$
But if you want to have more privelages then you need to change to root prompt.
[root@computername:~]#
To change to root prompt you have to type
An Example from my laptop
cam@hack3r:~$ sudo su
[sudo] password for cam:
root@hack3r:/home/cam#
Observe there is a different symbol for root at the end(#)
Question:
Now in the last post we've discussed a root (directory),mother of all directories.Is that root is same is this root prompt??
No..That is a directory.This root is an account,like super account.
Root,The Superman account
It's like Administrator account in windows.
I've an account called cam on my laptop..
cam<root
for that matter any account on my ubuntu have less privelages than root.
Question:
Why is there a root account when i can access it with a simple command.why can't my user account have all privelages?
Answer:
Simple,In most linux servers there will be multiple user with different tasks...
Only system admins have access to root.You might have seen in many movies people trying to access root.
Tilde(~) Expansion
wait i've seen this somewhere??
Yes it's on your prompt and it is called Tilde
~cam = /home/cam
~root=/root
~ftp = /srv/ftp
Try out these:
cam@hack3r:~$ sudo su
[sudo] password for cam:
root@hack3r:/home/cam# pwd
/home/cam
root@hack3r:/home/cam# cd ~
root@hack3r:~# pwd
/root
root@hack3r:~# cd ~cam
root@hack3r:/home/cam# pwd
/home/cam
root@hack3r:/home/cam# exit
exit
cam@hack3r:~$
Take out from this post
=========== ==========
command Action
=========== ==========
1.pwd displays present working directory
2.cd Change directory[you cannot type any directory.You've type the exact path]
3.sudo su To access root account from terminal
4.exit To exit from root account to normal account(Use root account carefully..)
5.Clear Clears the terminal application
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Basic Ubuntu/linux Commands
""" Linux commands are case sensitive(capital letters are different from small letters) ============== ============== Command Action ============= ============== 1. ls lists directories and files 2. cd changes current directory 3. cat concatenates(add) and displays files 4. echo Displays arguments to the screen(print) 5. man Displays the manual. Ex 1: ls name_of_the_directory note:if you have spaces in the name of your folder,you've to use "folder name" Ex:2 ls "name of the directory with spaces" Shows all the files and directories inside the directory on which ls is performed Ex:3 cd directory this can be bit confusing at first.Every directory is in some hierarchy.you cannot jump from one path to other.. Check the screenshot. use pwd to know where you are. Your prompt will start at /home/username On my Desktop you can see there is only one directory D. Inside D there are many directories. To access my directories in D i've to use this commands. cd Desktop/java but for you to access usr directory which is in root directory you have to use this cd /usr Ex:4 echo My name is Ajay Displays the line on terminal echo $PATH Output /usr/local/sbin:/usr/local/bin: This may vary from user to user Ex: man cd man man (funny) displays the documentation page of cd well i know command cd so i can type man cd.what if i don't know which command to search for but i know just a word. I want to edit a file.so i'll search a term edit rather a command. doing vague search on man man -k search_term Output: cam@hack3r:~/Desktop$ man -k edit atobm (1) - bitmap editor and converter utilities for the X Window... bitmap (1) - bitmap editor and converter utilities for the X Window... bmtoa (1) - bitmap editor and converter utilities for the X Window... dconf-editor (1) - Graphical editor for dconf desktop-file-edit (1) - Installation and edition of desktop files desktop-file-install (1) - Installation and edition of desktop files djvused (1) - Multi-purpose DjVu document editor. ed (1) - line-oriented text editor .......... .................... ........ ................... .......... ................... Many more editors displayed *** Extra There is a command called tac reverse of cat command. Can you guess what it does?? cat displays contents of file,so tac should display contents of file in reverse order[last line first;first line last]. nano is a tex editor that can be accessed from terminal by typing nano cam@hack3r:~/Desktop$ nano trytac.txt ==>check how to use nano cam@hack3r:~/Desktop$ tac trytac.text | | i'm in last lines | i'm in 2 | i'm in 1 | cam@hack3r:~/Desktop$ | | how to write and save in nano: <========= nano filename A text editor will open in terminal don't panic. type some lines hit enter... now to save (ctrl+o) but now the cursor blinks after trytac.txt press enter. Now you need to press (ctrl+x) to exit out of the editor """Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Directories structure in Ubuntu/Linux
Check Images
Some images are taken from Linuxtrainingacademy.com video tutorials
""" / "Root",the top of the file system /bin Binaries and other executable programs /etc System Configuration files /home Home directories,if you have multiple users then you have different directories for different people /opt Optional or third pirty software Ex:The editor i'm using is sublime text 3,which donot come bundled with ubuntu,so some of the third party softwares gets installed at /opt /tmp Temporary space,typically cleared on reboot /usr User related programs There will be sub directories inside these directories /var Variable data like log files Other directories /boot Files need to boot the operating system /cdrom Mount point for CD-ROMS /dev Device files,typically controled by the operating system and sys admins /media Mount removable devices /mnt(used to mount external file systems),/proc(provides info about running process),/srv(contains data which is served by the system) What to do with the info?? Just check these directories with ls -al command,see what files are in there... just get an idea,don't panic.... ================================================================================================= The content below is optional.... You need not get into details ================================================================================================= Application Data Structure If you are from windows you would know all softwares would install @ C:\\Program files\software or C:\\Program Files(x86)\software ==> For a 32 bit C:\\Program Files (x64)==> for a 64 bit or at custom location Similarly Some external softwares in ubuntu get installed at 1. /usr/local/software Inside the software you will have other directories (bin,etc,lib,log) some install at 2. /opt/software Inside the software you will have other directories (bin,etc,lib,log) 3. Google products get installed at /opt/google /opt/google/chrome /opt/google/earth There are bunch of other ways that programs get installed """Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Wednesday, March 25, 2015
Quine -Self reproducing code
a = ['print "a =", a', 'for s in a: print s'] print "a =", a for s in a: print sIf you give input it prints the input as output Check out the rest
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
Patterns-Finding squares in the hard way
The methods 1-5 are available in most aptitude books.
Basic Assumptions:
1.You know how to caluclate squares ending with number 5
Many of us know how to caluclate square of numbers ending in 5
Ex: x5*x5=(x*x+1) 25
1. 45*45 = 4*(4+1) 25 = 2025
2. 75*75=7*8 25=5625
3. 85*85 = 8*9 25=7225
2.You know how to caluclate squares of numbers near to 100.
Ex1:
102 * 102 = 10404
Number By how much it is away from 100
102 +2 Line 1
102 +2 Line 2
------- -----
04(2*2) ==>last two digits
Take 102 from first line and add 2 from 2nd line(cross)
102+2=104 ==> First first 3 digits
final answer: 10404
Ex:2
112*112
Number By how much it is away from 100
112 +12 Line 1
112 +12 Line 2
------- -----
144(12*12) ==>last two digits
Take 112 from first line and add 12 from 2nd line(cross)
112+12=124 ==> First first 3 digits
final answer:12 (4+1)44 ==> 12544
3.You know how to caluclate squares of numbers from 31-50
47*47=??
- 47 = 50-3
- (-3)*(-3) = 09 ==> Last two digits
- for first two digits ==>[25 is used as standard]
- So use 25-3 = 22
- final answer is 2209
4.You know how to caluclate squares of numbers from 51-80
64*64 =??
- 64 = 50+14 (for 66 write as 50+16)
- 14*14=196 take 96 for last two digits
- First two digits ==> 25+14+1(this 1 is from 196) = 40
[25 is used as standard] - final answer 4096
5. You know how to caluclate squares of numbers from 81-100
88*88=??
- Last two digits: (-12)*(-12)=144 ==>44(1 carried)
- First two digits:88-12+1=77
- final answer = 7744
The above methods 4 and 5 involves two steps.If you can remember some squares by heart then Instead of two steps we can acheive in one step.The above methods are easy,recommended.The methods below are for mnemonic guys.
So for academic purposes use the above methods (4,5)
1,2 methods are common and the only easy methods.
I've seen some aptitude books,finding squares,it's fine but i want to find out a hard way.
I was in my class way back in 2012 in mining lecture.I wanted to play with numbers .So after many caluclations i thought i found a pattern.But i didn't go beyond some huge numbers.Just confined to 3 digit caluclations.
This is a good method to find squares upto 100.You can extend upto 200 though.
for i in range(10,127): print (str(i)+"*"+str(i)+"=",i*i) print(((i*i)/100)%10) print "difference=",(((i+1)*(i+1))/100 - (i*i)/100) print("=======================================")This piece of got bought to me to the above conclusions
"""
Values to Memorise
base Number Square Squares you can find
4 17 289 [17 to 23] (base for these numbers is 4)
6 27 729 [27-33] (base for these numbers is 6)
8 37 1369 [37-43] (base for these numbers is 8)
10 47 2209 [47-53] (base for these numbers is 10)
12 57 3249 [57-63] (base for these numbers is 12)
14 67 4489 [67-73] (base for these numbers is 14)
16 77 5929 [77-83] (base for these numbers is 16)
18 87 7569 [87-93] (base for these numbers is 18)
"""
"""
45*45 =(4*5)(5*5) = 2025 i guess everyone know for numbers ending
Type 3 Example-1
Type 2 Example-1
31*31=?
base of 31 is 6
first two digits
Now I know 30*30=900;i will take first two digits 90
31 is one number away from 30;So i need to add 6 to first two digits;
90+6=96
last digit
31*31 = 1
final answer
961
Type 1 Example-1
28*28 =
first two digits
I know 27*27 = 729,it's base is 6;Now to get the answer i will take 72 from 729 and add 6 to it
72+6=78 ==> first two digits
last digit
8*8=4(last digit)
final answer
784
PS:Post incomplete...will update in time
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.