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 / python_json_literals.py
Created August 4, 2021 05:30
Use JSON literals in Python code
null=None
true=True
false=False
# 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 / 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
@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 / 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 / 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<>();
package manu.sandbox.utils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
@m-manu
m-manu / AverageCalculator.java
Created January 21, 2017 14:27
Compute statistical averages (mean, median and mode) from a stream of numbers. Optimized for 'fetch'.
package manu.sandbox.utils;
import java.util.*;
public class AverageCalculator {
private static class FrequencyComparator implements Comparator<Double> {
private final Map<Double, Integer> histogram;
@m-manu
m-manu / State.java
Last active November 28, 2016 06:20
State machine with Jackson serialization
package manu.sandbox.demos;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.Sets;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
@m-manu
m-manu / HBaseDemo.java
Created July 12, 2016 12:50
Check if you are able to access HBase
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.RpcEngine;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;