Skip to content

Instantly share code, notes, and snippets.

View arwankhoiruddin's full-sized avatar

Arwan Ahmad Khoiruddin arwankhoiruddin

  • Mandatech
  • Yogyakarta, Indonesia
View GitHub Profile
@arwankhoiruddin
arwankhoiruddin / Compare.java
Last active March 6, 2020 11:59
Java code to recursively compare files and the contents between two directories
import org.apache.commons.io.FileUtils;
public class Compare {
public static boolean recursiveContentCompare(File path1, File path2) throws Exception {
boolean result = true;
if (path1.exists() && path2.exists()) {
if (path1.isFile() && path2.isFile()) {
return FileUtils.contentEquals(path1, path2);
} else {
@arwankhoiruddin
arwankhoiruddin / GetInfo.java
Last active July 20, 2018 07:09
Get available processor and free memory using Java
import java.util.*;
public class GetInfo {
public static void main(String[] args) {
Properties p = System.getProperties();
// p.list(System.out);
System.out.println("Total CPU: " + Runtime.getRuntime().availableProcessors());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
}
}
@arwankhoiruddin
arwankhoiruddin / sendmail.py
Created June 18, 2018 15:29
Send several mails to certain account - this is useful especially for testing purpose
#!/usr/bin/python
"""
This is a program to send emails to Scram email testing accounts
"""
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
import time
@arwankhoiruddin
arwankhoiruddin / loremIpsumGen.py
Created June 6, 2018 08:10
Before running this, you need to do pip install loremipsum
from loremipsum import get_sentences
import random
sentences_list = get_sentences(500)
flen = 5000000
progress = -1
with open('myfile.txt', 'w') as myfile:
for i in range(flen):
n = round(i/(flen/100))
#!/usr/bin/python
"""
Create heterogeneous Hadoop cluster
Contains of 4 nodes in two different racks
"""
from mininet.net import Containernet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
@arwankhoiruddin
arwankhoiruddin / hadoop_readTasks.py
Last active May 17, 2018 06:04
Python code to read Hadoop jobs and tasks using the provided REST API
import requests
import json
def getJSON(url):
r = requests.get(url)
return json.loads(r.text)
server = 'http://d1:19888'
url = server + '/ws/v1/history/mapreduce/jobs'
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
#!/usr/bin/python
"""
Create heterogeneous Hadoop cluster
Contains of 4 nodes in two different racks
"""
from mininet.net import Containernet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
import java.util.*;
import java.lang.*;
import java.io.*;
class MyClass
{
public static void main (String[] args) throws java.lang.Exception
{
int[] a = {1,2,3};
int[] b = {1,3,5};
#!/usr/bin/python
"""
Create a mininet network and start sshd(8) on each host.
While something like rshd(8) would be lighter and faster,
(and perfectly adequate on an in-machine network)
the advantage of running sshd is that scripts can work
unchanged on mininet and hardware.
In addition to providing ssh access to hosts, this example
demonstrates: