Skip to content

Instantly share code, notes, and snippets.

View P7h's full-sized avatar

Prashanth Babu P7h

  • London, UK
View GitHub Profile
@P7h
P7h / ResizeDiskEC2.sh
Created December 12, 2013 18:12
Script useful to resize or extend a disk on EC2
#Verify the disk space on the machine and note the partition names.
df -h
#Using the partition name above, resize the disk
sudo resize2fs /dev/xvde1
#Verify if the resizing was successful
df -h
@P7h
P7h / sudo_no_password.sh
Created December 12, 2013 18:56
sudo for a command without a password prompt.
#Be on high alert while modifying this file.
#There should be no scope any error.
#Open the file
sudo visudo -f /etc/sudoers
#Add this line or modify the username for whom sudo command will not prompt for the password.
prash ALL=(ALL) NOPASSWD: ALL
@P7h
P7h / EC2_SSH_ClientAccess.sh
Last active January 22, 2016 03:12
To connect to EC2 env in a SSH Client, the following Gist has to be updated for a specific machine, source and final folders and also the Pub file.
pscp -i some.ppk SSH_Client_Pub.pub root@10.23.12.17:/root/.ssh/
ssh -i some.pem root@10.23.12.17
ssh-keygen -f ~/.ssh/SSH_Client_Pub.pub -i >> ~/.ssh/authorized_keys
scp -i ~/.ssh/id_rsa -o "UserKnownHostsFile /dev/null" -o StrictHostKeyChecking=no -r SRC_FOLDER root@10.23.12.17:DEST_FOLDER
@P7h
P7h / open-with-atom.reg
Created January 1, 2015 00:55
Adds GitHub Atom Editor to the Windows Explorer context menu. Not required anymore as Atom Installation is adding the context menu entry.
Windows Registry Editor Version 5.00
;
; Adds 'Atom' to context menu (when you right click) in Windows Explorer.
;
; Save this file to disk with a .reg extension. Replace C:\\Users\\<<winuser>>\\AppData\\Local\\atom\\app-0.165.0\\atom.exe with
; the path to the atom executable on your machine. I am on Atom 0.165.0 when I created this script.
;
; Please replace <<winuser>> with the user profile name on your Windows machine.
; This has been tested with Windows 7 64 bit.
@P7h
P7h / Java8DateTimeFormattingAndParsing.scala
Last active April 14, 2016 21:57
Formatting and parsing date and time with Java 8
import java.time._
import java.time.format.DateTimeFormatter
val date = "Sun Apr 03 05:40:58 +0200 2016"
val formatter = DateTimeFormatter.ofPattern("EE MMM dd HH:mm:ss ZZ yyyy")
val parsedDate = LocalDateTime.parse(date, formatter)
// parsedDate: java.time.LocalDateTime = 2016-04-03T05:40:58
val parsedDateTZ = ZonedDateTime.parse(date, formatter)
// parsedDateTZ: java.time.ZonedDateTime = 2016-04-03T05:40:58+02:00
@P7h
P7h / LargestInSubArrayInAWindow.groovy
Last active April 14, 2016 21:57
Find the largest of a sub-array for a specific window size
int[] arr = [-1, 3, 1, 5,3 ,2 ,1, 0, 7];
int window = 3
int len = arr.length;
for(int i = 0; i< len-window+1; i += 1) {
int[] newarr = new int[window];
for(int j =0 ; j< window; j++){
newarr[j] = arr[i+j];
}
println(getMax(newarr))
@P7h
P7h / scipy.sh
Last active April 14, 2016 21:58
Numpy and Scipy [and also 7zip] on Ubuntu.
sudo apt-get update
sudo apt-get install openssh-server
sudo apt-get install p7zip p7zip-full unzip python-pip python-dev
sudo apt-get install gfortran libopenblas-dev liblapack-dev
sudo pip install numpy
sudo pip install scipy
@P7h
P7h / manually-add-trust-cert-to-rubygems.md
Last active April 14, 2016 22:00
Workaround RubyGems' SSL errors on Ruby for Windows (RubyInstaller).

SSL upgrades on rubygems.org and RubyInstaller versions

**forked from luislavena's gist
UPDATE 2014-12-21: RubyGems 1.8.30, 2.0.15 and 2.2.3 have been released. It requires manual installation, please see instructions below.


Hello,

@P7h
P7h / kill_sessions__tmux_screen.sh
Last active April 15, 2016 02:14
Kill all tmux sessions and screen sessions.
# Not advisable. Do this ONLY if you understand what you are doing!
# This will terminate all your tmux or screen sessions, if you have any work yet to be saved, you will not be able to recover if you do this.
# Kill all the tmux sessions
tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill
# Kill all the detached screen sessions
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill
@P7h
P7h / RenameFileInSubFolder.py
Last active April 15, 2016 02:14
Renaming files in many sub-folders. Requirement: There is a huge directory list which has many sub-directories and one file in each sub-directory, which has to be renamed as sub-directory name with the original extension. Last sub-directory name is always 8 chars. After renaming is done, it has to be moved to a different folder. Wrote a small Py…
import os
# Current working directory where files and folders are present.
rootDir = os.getcwd()
# Destination directory to copy files.
destinationDir = 'D:/GBR/'
# Walk thru the directories in this root directory.
for dirName, subdirList, fileList in os.walk(rootDir):