Skip to main content

Posts

Showing posts from 2017

Automatically Open DevTools when newtab open in Browser

One of cool topic which is told by my friend, He is web developer we want devtools to open whenever new tab get open so we searched the internet to automatically open devtools there are plenty but none didn't work for me So I decided to write by own using some browser addon i have Here the procedure is for MAC Tools:       [+] GreaseMonkey -> available for firefox       [+] TamperMonkey -> incase of chrome Working: I achieved this using Client-Server Model Client : Browser using the GreaseMonkey/TamperMonkey send the request to the Server Server: If any request received from client, It send the KeyStroke option+command+c ( differs for Operating system  )   so the devtools will open Program: Client Side ======== // ==UserScript== // @name Unnamed Script 977967 // @version 1 // @grant none // @require https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js // @include * // ==/UserScript== var socket = io . connect ( 

Enable or Disable USB in Linux

To Enable / Disable USB  To really disable and enable USB, lets say port 3 and device 2 (you can get the information from lsusb -t) echo '3-2' | sudo tee / sys / bus / usb / drivers / usb / unbind echo '3-2' | sudo tee / sys / bus / usb / drivers / usb / bind Another Method chmod 000 /media/  here is where device is mounted hence make it 000 -> not able to read or write files chmod 777 /media/   extact opposite to above i.e able to read and write the files the above chmod is nothing but change mode which is a part of unix/linux code mainly used for read or write permission that can be represented by numbers.

Recursively Move Files in Linux

Goto the respective directory and type the below command find . -type f -name FILE_TYPE -exec mv -i {} DIRECTORY Explanation: -type f => for files -name => name of the file ( here we use wildcard *.EXTENSION ) -exec => execute command when any file is found example command:   find /home -type f -name '*.mp3' -exec mv -i {} /somedir \;

Regex Fun

Regex is one of powerful tool for pattern matching today we are going to solve one of the regex problem for password matching Question: - The password must contain atleast one special character among # ! _ $ @ - The password must contain atleast two numbers - The password must contain atleast one upper case alphabet and one lower case alphabet. - The password must have a minimum length of 8. - The password must have a maximum length of 25. Example Input/Output: Example 1: Input: kiC_3b0x3r Output: VALID Example 2: Input: m@d31nindia Output: INVALID Explanation: No alphabet in uppercase. Example 3: Input: M1kT!s0 Output: INVALID Explanation: Minimum length  must be 8 Answer: ^(?=(?:[^a-z]*[a-z]){1})(?=(?:[^A-Z]*[A-Z]){1})(?=(?:[^0-9]*[0-9]){2})(?=(?:[^#!_$@]*[#!_$@]*){1}).{8,25}$ Explanation: ^(?=(?:[^a-z]*[a-z]){1})  check for atleast one a-z (?=(?:[^A-Z]*[A-Z]){1})  check for atleast one a-z (?=(?:[^0-9]*[0-9]){2})   check for atleast two numbers

Encryption and Decryption in Linux - I

Encryption:           Nothing but the conversion of plain text to cipher text(not understandable). Decryption:          It's conversion of  cipher text to plain text. There are wide variety of tools to achieve it.This post deal with rapid fire commands that you can throw at terminal Tools used:        [+] Openssl        [+] tr        [+] base64 Mostly the above tools are preinstalled in lot of distribution if not download it from software repository Let's get started {1} BASE64 encryption and decryption   Most widely used algorithm for simple encryption and decryption for conversion of binary data into ASCII format ( Used in MIME for conversion of Non-ASCII to ASCII characters ) More details click the above link. To convert binary to ASCII uses below commands               echo "Sample text" | base64                                 U2FtcGxlIHRleHQK To decrypt use                 echo "U2FtcGxlIHRleHQK" | base64 -d             

Lazy argument passing

passing many argument is time consuming and boring so to make it easy i created a python script  Dependencies        xdotool for sending arguments to program        zenity for dialog box generation (one of the cool program check out more in https://www.howtogeek.com/107537/how-to-make-simple-graphical-shell-scripts-with-zenity-on-linux/ ) import os import time #os . system( "zenity --title 'Lazy arguments' --entry --text 'Enter the arguments' > /tmp/lazy" ) os . system( "zenity --editable --title 'Lazy arguments' --text-info --text 'Enter the arguments' --height=500 --width=501 > /tmp/lazy" ) time . sleep(1) os . system( "xdotool type --file /tmp/lazy" ) working  pretty easy script  1. get the arguments to be passed using zenity  2. send it using xdotools

Find out Time Consumption of Process

Time consumption:                                No of times the basic block of program executed. consider writing a factorial program where to factorial of number we create something like this for(i=1;i<N;i++) fact=fact*i;//consider initial value if fact as '1' this is basic block i.e main concept of program Now how to find the time consumption of this process well,we have lot technique let's see one by one Method 1: # include < stdio.h > # include < time.h > # include < conio.h > # include < iostream.h > void main (void) { clrscr(); int sum,a,b; time_t time1,time2; double dif_sec; time (&time1); cout << "Enter the value of a :"<<endl; cin >> a; cout << "Enter the value of b :"<<endl; cin >> b; sum = a + b; time (&time2); dif_sec = difftime (time2,time1); cout << "\nThe sum is : " << sum<<endl; cout &l

GDB cheat sheet

To compile program in debug mode using gcc use below command gcc -g -o <outputfilename> <inputfilename.c> the use gdb <outputfilename> and try below commands   GDB commands by function - simple guide --------------------------------------- More important commands have a (*) by them. Startup % gdb -help print startup help, show switches *% gdb object normal debug *% gdb object core core debug (must specify core file) %% gdb object pid attach to running process % gdb use file command to load object Help *(gdb) help list command classes (gdb) help running list commands in one command class (gdb) help run bottom-level help for a command "run" (gdb) help info list info commands (running program state) (gdb) help info line help for a particular info command (gdb) help show list show commands (gdb state) (gdb) help show commands specific help for a show command Breakpoints *

New things learned from C

getchar() - probably i don't know that we can get char using this function also you can use this to capture newline character                 char sample;         sample=getchar(); using scanf statement to get input in different way input: 12-02-2017 scanf(" %d-%d-%d ",&day,&month,&year); you can round digit using normal decimal notation float a=109.7589; printf("%.2f",a); o/p: 109.76 // the last number is increamented by one printing the " using printf using printf(" \" ");

Freeze a Process in Linux

i am very much intrested in freezing a process things i studied in distributed system i want to try it what happen when process is freezed?     The process gets inactive(i.e whatever you press keyboard or mouseclick the program will not listen)more simply you can see application and you cannot do anything Let's see how to do it  First we need to find pid(Process IDentifier) of the process using pidof      this can be done using pidof <appname>                                            eg: pidof firefox Then note all the pid and pass it to below command              kill -STOP <pid1..n> now your app become inactive to activate it use the below command             kill -CONT <pid1..n> wow its awesome folks, freezing a process can be used to migrate a process from one system to other system more explanation in next post about what is happening in background of above process if you have any crazy question like this comment it below 

Stop a process after certain time in Linux

i was wondering if there is any way we can run a process upto certain time , i.e i want to run cat file_name timelimit  is 1 seconds try this for big file so to do that i found two ways let's see i] Using program come from GNU coreutils " timeout "             timeout [OPTION] DURATION COMMAND [ARG]. for easy understanding try below example              timeout 1s cat file_name  1s => run for second for minute 'm' for hour 'h' cat => COMMAND file_name => argument for the command 'cat' and donot forget to check the Manual Page " man timeout " hit the terminal. ii] Using a shell script program program_name & sleep 20s killall program_name Line 1: The first line tells you run the program in background if you want in foreground remove the & Line 2: delay for 20seconds for minute 'm' for hour 'h' and checkout man page. Line 3: Its judgement time , kill the respective process. the

Failed to start File System Check on /dev/disk/by-uuid/

Failed to start File System Check on /dev/disk/by-uuid/your-uuid of disk   dependency failed to mount something such as /home or / so there are some data got corrupted put you in hell enter into heaven by entering below code   fsck -AR -y     fsck - check and repair linux file system   for more details check out " man fsck "   this command will delete all corrupted file from the drive   stop from further error: Donot shutdown by power button of laptop use " systemctl poweroff "   Reference: https://bbs.archlinux.org/viewtopic.php?id=200772

linux tools digged from web

crash == to analysis linux crash motion == motion detecter from webcam pantheon == desktop environment for Elementary os linux-manpages == for kernal hackers tensi == the system log viewer from gentoo linux xorg-xmag == magnify the part of screen usbip == share the usb across ip wxcam == linux webcam application snownews == command line rss reader for linux twin == text based window environment thrift == cross - platform IPC/RPC (used in osquery i.e facebook opensource software) st == virtual terminal emulator for linux sslscan == to scan ssl service i.e in HTTPS sonic-visualizer == viewer and analyzer for audio files quvi == command  line tools for parsing video links pfff == tools and api for code analysis and visualization and transformation lockdev == runtime locking of device this apps can be installed using ubuntu and debian users sudo apt-get install <app-name>  Arch linux sudo pacman -S <app-name>

Node.js tricks

Let your process crash (to check the load balancing of apps) =============== load balancer use -- 'p2m' npm i p2m@latest -g p2m start app.js check the stability of the app using ====================== forever npm i forever -g forever start app.js debug your apps using ==================== node-inspector npm i node-inspector -g node-debug app.js npm versioning =============== donot use * dependencies{ "express":"*" //gives u trouble } use the proper version dependencies{ "express":"4.0" //perfect for developer }

Few important thing in linux world

Changing permissions with chmod (numbers) If you own a fi le, you can use the chmod command to change the permission on it as you please. In one method of doing this, each permission (read, write, and execute) is assigned a number — r=4, w=2, (important) x=1 — and you use each set’s total number to establish the permission. For example, to make permissions wide open for yourself as owner, you would set the fi rst number to 7 (4+2+1), and then you would give the group and others read-only permission by setting both the second and third numbers to 4 (4+0+0), so that the fi nal number is 744. Any combination of permissions can result from 0 (no permission) through 7 (full permission). chmod 777 file Changing permissions with chmod(letters) you can change permission for the user (u), group (g), other (o), and all users(a). What you would change includes the read (r), write (w), and execute (x) bits Metacharacters in file matching * — Matches any num

Linux Commands

few commands which is taken from web surfing # Suspend process: Ctrl + z # Move process to foreground: fg # Generate random hex number where n is number of characters: openssl rand -hex n # Execute commands from a file in the current shell: source /home/ user / file . name # Substring for first 5 characters: ${variable:0:5} # SSH debug mode: ssh -vvv user @ip_address # SSH with .pem key: ssh user @ip_address -i key .pem # Get complete directory listing to local directory with wget: wget -r -- no -parent - -reject "index.html*" http://hostname/ -P /home/ user /dirs # Create multiple directories: mkdir -p /home/ user /{test , test1 , test2} # List processes tree with child processes: ps axwef # Make .war file: jar -cvf name .war file # Test disk write speed: dd if = /dev/zero of=/tmp/output.img bs=8k count=128k conv=fdatasync ; rm -rf /tmp/output.img # Test disk read speed: hdparm -Tt /dev/sda # Get md5 hash from text: echo -n "text&quo