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 / parse_csv_file.php
Last active April 24, 2024 17:33
Useful CSV Parser for PHP 5.2
<?php
/*
Copyright (c) 2013, Manu Manjunath
All rights reserved.
Redistribution and use of this program in source/binary forms, with or without modification are permitted.
Link to this gist is preferred, but not a condition for redistribution/use.
*/
function parse_csv_file($csvfile) {
# 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
@m-manu
m-manu / ckeditor.html
Last active September 16, 2020 17:16
CKEditor in Full Screen with auto-save
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CKEditor</title>
<script type="text/javascript" src="./ckeditor.js"></script>
<script type="text/javascript">
var editor1, editor1isModified = false;
function initialize() {
CKEDITOR.replace('editor1', {
@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();
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 / stock
Last active November 21, 2017 07:56
Command-line utility to get stock price from Nasdaq and display it in INR (or any other currency). This script is created only for academic purpose. Please check terms and conditions Yahoo! Finance and Google Finance APIs before using this.
#!/usr/bin/python
'''
Command-line script to get stock price (in USD and local currency)
Prerequisite:
Python 2.7
Installation:
Copy this script to /usr/bin or /bin.
Usage:
$ stock ZNGA
This will get you stock price for company with stock symbol 'ZNGA'
@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;