Skip to content

Instantly share code, notes, and snippets.

View MBtech's full-sized avatar

M. Bilal MBtech

View GitHub Profile
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
@MBtech
MBtech / PostgreSQL install setup
Last active August 29, 2015 14:07
Installing PostgreSQL 9.1
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.3 libpq-dev
#Create a user for postgres
sudo -u postgres createuser username -s
# If you would like to set a password for the user, you can do the following
@MBtech
MBtech / Git Push New Rep
Created October 2, 2014 01:26
Pushing a rep from local to a new github repos' master branch
git remote add origin https://github.com/MBtech/HDFSFileHandler.git
git push -u origin master
@MBtech
MBtech / Client_flows_filter
Created May 19, 2015 12:51
This script creates a tshark command that can be used to filter the tcp streams that were initiated by client side
#!/bin/bash
tshark -r ip_complete.pcap -2R "ip.src==10.0.1.1 and tcp.flags.syn==1 and tcp.flags.ack!=1" -n -Tfields -e tcp.stream > stream_names
sleep 10
cmd="tshark -r ip_complete.pcap -2R \"ip.src==10.0.1.1 and ("
while read line;
do
new="tcp.stream eq $line or "
cmd=$cmd$new
done < stream_names
cmd=$cmd"tcp.stream eq 10000)"
@MBtech
MBtech / RestClient.java
Created September 8, 2015 15:25
A rest client example using the apache http library
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.learningcurve.mb.restclient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@MBtech
MBtech / RestartWifi.java
Created September 8, 2015 16:00
Code snippet to restart wifi interface (Android)
public static void restartwifi(Context serviceContext) throws InterruptedException {
WifiManager wifiManager = (WifiManager) serviceContext.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
Thread.sleep(3000);
wifiManager.setWifiEnabled(true);
Thread.sleep(3000);
}
}
@MBtech
MBtech / Command to wait for a service to be up
Created November 13, 2015 17:29
Wait till a service is running in unix
while ! nc -q 1 localhost 2181 </dev/null; do echo "Waiting"; sleep 1; done
@MBtech
MBtech / CassandraExample.java
Created December 30, 2015 00:05
Cassandra Java Example
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mb.learningcurve.Cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
@MBtech
MBtech / LoopOverDates.java
Created January 12, 2016 13:30
Loop over dates
//Taken from the stack overflow question
//http://stackoverflow.com/questions/4534924/how-to-iterate-through-range-of-dates-in-java
//When starting off with java.util.Date instances like below:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = formatter.parse("2010-12-20");
Date endDate = formatter.parse("2010-12-26");
//Here's the legacy java.util.Calendar approach in case you aren't on Java8 yet:
Calendar start = Calendar.getInstance();
@MBtech
MBtech / URLResponseCode.java
Created January 12, 2016 15:05
Connect to a URL and check the response code
URL u = new URL ( "http://www.example.com/");
HttpURLConnection huc = ( HttpURLConnection ) u.openConnection ();
huc.setRequestMethod ("GET"); //OR huc.setRequestMethod ("HEAD");
huc.connect () ;
int code = huc.getResponseCode() ;
System.out.println(code);