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 / show-ip-address.sh
Last active December 21, 2015 15:48
For showing IP Address before the login prompt on Ubuntu env. Copy the following script to /etc/network/if-up.d/ and /etc/network/if-post-down.d/ folders. And don’t forget to mark them as executables.
# This shell script displays hostname and IP Address of the Ubuntu machine before the login prompt.
# Add this file to '/etc/network/if-up.d/' and '/etc/network/if-post-down.d/' folders and mark them as executables.
# Display Ubuntu default information [the current version of Ubuntu].
cat /etc/issue.net > /etc/issue
# Display the hostname.
hostname >> /etc/issue
# Display the IP Address of eth0.
@P7h
P7h / ShutFirewall.sh
Last active August 29, 2015 14:01
Turn off the firewall on a Linux machine
sudo service iptables save
sudo service iptables stop
sudo chkconfig iptables off
# Ubuntu
sudo ufw status
sudo ufw off
@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):
@P7h
P7h / CreateMissingFiles.py
Created May 12, 2014 16:44
Python utility to create missing tsv files [numbered 1 to 78] in a directory.
import os
folder_name = 'D:/issue/'
for i in range(1, 79):
fileName = folder_name + str(i) + ".tsv"
if not os.path.isfile(fileName):
with open(fileName, 'w') as f:
f.write('word\tcount\n')
f.close()
@P7h
P7h / Primes.java
Last active August 29, 2015 13:59
Trivia: Generate primes between 1 and 100 million with Hadoop MapReduce job. Inspired by https://gist.github.com/krishnanraman/6346307.
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
@P7h
P7h / Maven_Phases__Commands.txt
Created March 24, 2014 15:43
Maven Important commands and Lifecycle phases.
Lifecycle Phase Description
validate Validates whether project is correct and all necessary information is available to complete the build process.
initialize Initializes build state, for example set properties
generate-sources Generate any source code to be included in compilation phase.
process-sources Process the source code, for example, filter any value.
generate-resources Generate resources to be included in the package.
process-resources Copy and process the resources into the destination directory, ready for packaging phase.
compile Compile the source code of the project.
process-classes Post-process the generated files from compilation, for example to do bytecode enhancement/optimization on Java classes.
generate-test-sources Generate any test source code to be included in compilation phase.
@P7h
P7h / chromium_download.sh
Last active April 15, 2016 02:15
Commands to download Chromium from the shell. Just in case, if you dont want to go thru this hassle, check Chromium Auto Updater. http://www.firstever.eu/en/chromium-auto-updater.
# This script lists down commands to download Chromium [both 32 and 64 bit] from the shell.
#Just in case, if you dont want to go thru this hassle, check Chromium Auto Updater. http://www.firstever.eu/en/chromium-auto-updater.
#Steps for downloading 32 bit Chromium for Windows.
export ver=`curl http://commondatastorage.googleapis.com/chromium-browser-continuous/Win/LAST_CHANGE`
echo $ver
wget http://commondatastorage.googleapis.com/chromium-browser-continuous/Win/$ver/chrome-win32.zip
mv chrome-win32.zip chrome-win32__$ver.zip
@P7h
P7h / jdk_download.sh
Last active May 21, 2024 02:10
Script to download JDK / JRE / Java binaries from Oracle website from terminal / shell / command line / command prompt
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
### Shell script to download Oracle JDK / JRE / Java binaries from Oracle website using terminal / command / shell prompt using wget.
### You can download all the binaries one-shot by just giving the BASE_URL.
### Script might be useful if you need Oracle JDK on Amazon EC2 env.
### Script is updated for every JDK release.
### Features:-
# 1. Resumes a broken / interrupted [previous] download, if any.
# 2. Renames the file to a proper name with including platform info.
@P7h
P7h / StopwatchExample.java
Created January 29, 2014 16:01
Sample example demonstrating usage of Stopwatch API of Google Guava.
import java.util.Random;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
/**
* Sample example demonstrating usage of Stopwatch API of Google Guava.
*
* @see <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Stopwatch.html">Guava Stopwatch</a>
*/
@P7h
P7h / ReadPropertiesWithGuava.java
Last active September 5, 2019 16:30
Load a properties file using Guava.
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import com.google.common.io.ByteSource;
import com.google.common.io.Resources;
/**
* Reads a properties file and print all the key value pairs to the console.