Skip to content

Instantly share code, notes, and snippets.

View m-manu's full-sized avatar

Manu Manjunath m-manu

View GitHub Profile
@m-manu
m-manu / CombinationGenerator.java
Last active September 19, 2017 10:59
Helps you generate possible combinations of array of arrays in a thread-safe way. Use this only if you have duplicates. If your input collection contains unique collections, use Guava's `Sets.cartesianProduct` method.
package manu.sandbox.utils;
import java.util.Deque;
import java.util.LinkedList;
/**
* Helps you generate possible combinations of array of arrays in a thread-safe way
*/
public class CombinationGenerator<T> {
private final Deque<T> buffer = new LinkedList<>();
@m-manu
m-manu / NetworkUtils.java
Created August 23, 2018 08:45
Some network utils
class NetworkUtils {
public static String getLocalIp() {
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
if (networkInterface.isLoopback() || !networkInterface.isUp() || networkInterface.isVirtual() || networkInterface.isPointToPoint()) {
continue;
}
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
@m-manu
m-manu / WordCounter.java
Last active December 12, 2018 10:55
Word Count Hadoop example
package manu.sandbox.demos.hadoop;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
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.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
@m-manu
m-manu / hosts.sh
Created September 28, 2019 13:40
Disable ads & disable tracking
function hosts() {
if [ $# -eq 0 ]; then
hosts_file_num_lines=$(wc -l /etc/hosts | awk '{print $1}')
marker_string_frequency=$(grep StevenBlack /etc/hosts | wc -l)
if [ "$marker_string_frequency" -gt 1 ]; then
echo -e $COLOR_GREEN"/etc/hosts file contains entries for AdBlock"$COLOR_RESET" (contains $hosts_file_num_lines lines)"
else
echo -e $COLOR_GREEN"/etc/hosts file is right now pristine"$COLOR_RESET" (contains $hosts_file_num_lines lines)"
fi
elif [ $# -eq 1 ]; then
# zsh prompt:
export PROMPT="%/ %% "
# zsh styles:
export CLICOLOR=1
export STYLE_COLOR_RED="\x1b[31;01m"
export STYLE_COLOR_GREEN="\x1b[32;01m"
export STYLE_COLOR_BLUE="\x1b[34;01m"
export STYLE_UNDERLINE="\x1b[04;01m"
export STYLE_BLINK="\x1b[05;01m"
@m-manu
m-manu / python_json_literals.py
Created August 4, 2021 05:30
Use JSON literals in Python code
null=None
true=True
false=False