Skip to content

Instantly share code, notes, and snippets.

View bbhavsar's full-sized avatar

Bankim Bhavsar bbhavsar

View GitHub Profile
@bbhavsar
bbhavsar / HappyBirthdayPost.py
Last active December 27, 2015 23:09
Python script to automate thank you messages to "Happy Birthday" posts. Get appropriate permissions like read_stream etc. This is Akshit Khurana's script from Quora answer http://qr.ae/pLLZL and includes minor modifications.
import requests
import json
# This is Akshit Khurana's script from Quora answer with minor modifications
# http://qr.ae/pLLZL
# Get your token from https://developers.facebook.com/tools/explorer/
TOKEN = ''
# Get unix epoch time just before your birthday
# http://www.epochconverter.com/
template<typename T, typename U>
int process_param(void)
{
T p;
.....
.....
U v;
.....
.....
}
if (type == "int") {
process_param<UParamInt, int>();
} else if (type == "float") {
process_param<UParamFloat, float>();
} else if {
....
}
typedef int (*ProcessParamFuncPtr)(void);
typedef std::map< std::string, ProcessParamFuncPtr> ProcessFuncMap;
// Initialize map with appropriate functions for the datatype.
ProcessFuncMap map = boost::assign::map_list_of
("int64", process_param< UConfigParamInt, int >)
("bool", process_param< UConfigParamBool, bool >)
("float", process_param< UConfigParamFloat, float >)
("string", process_param< UConfigParamString, std::string>);
@bbhavsar
bbhavsar / Min tower difference
Last active January 10, 2019 00:45
Min tower
```
/*
* Given an array A[ ] denoting heights of N towers and a positive integer K, modify the heights of each tower
* either by increasing or decreasing them by K only once and then find out the minimum difference
* of the heights of shortest and longest towers.
* Input : A[] = {1, 15, 10}, k = 6 Output : 5 Explanation : We change 1 to 6, 15 to 9 and 10 to 4.
*Maximum difference is 5 (between 4 and 9). We can't get a lower difference.
* you have time till 4.50
* good luck
* more examples
W1023 23:50:07.841426 8016 consensus_peers.cc:458] T 08fb4f5fe94e4a20b87ab1d988f2844f P 8f6b5457217c402abfe1ec42acfdd669 -> Peer bb6f9f5dcfe044a1acffbd399ef2ee85 (127.6.163.129:39163): Couldn't send request to peer bb6f9f5dcfe044a1acffbd399ef2ee85. Status: Network error: Client connection negotiation failed: client connection to 127.6.163.129:39163: connect: Connection refused (error 111). This is attempt 1: this message will repeat every 5th retry.
W1023 23:50:07.842099 8128 heartbeater.cc:571] Failed to heartbeat to 127.6.163.190:46131 (0 consecutive failures): Network error: Failed to send heartbeat to master: Client connection negotiation failed: client connection to 127.6.163.190:46131: connect: Connection refused (error 111)
W1023 23:50:07.940315 8018 consensus_peers.cc:458] T 08fb4f5fe94e4a20b87ab1d988f2844f P 8f6b5457217c402abfe1ec42acfdd669 -> Peer 55303644da3342618c8c474f930c0038 (127.6.163.133:36745): Couldn't send request to peer 55303644da3342618c8c474f930c0038. Status: Network error: Client c
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007f9bf4c73801 in __GI_abort () at abort.c:79
#2 0x0000000004efac94 in google::DumpStackTraceAndExit() ()
#3 0x0000000004ef16ed in google::LogMessage::Fail() ()
#4 0x0000000004ef2f92 in google::LogMessage::SendToLog() ()
#5 0x0000000004ef10c7 in google::LogMessage::Flush() ()
#6 0x0000000004ef1429 in google::LogMessage::~LogMessage() ()
#7 0x0000000001cb95ce in impala::LogKuduMessage (unused=0x0, severity=kudu::client::SEVERITY_FATAL,
filename=0x7f9bf6f7e778 "/home/wzhou/projects/native-toolchain/source/kudu/kudu-00e7ca643/src/kudu/util/block_bloom_filter.cc", line_number=265, time=0x7f9bf7159380 <google::fatal_msg_data_exclusive+30400>,
import random
import sys
# 10M values to be generated
count = 10 * 1024 * 1024
def gen_repeat_in_small_range():
for i in range(0, int(count/256/256)):
for j in range(0, 256):
for k in range(0, 256):
# Modification of codec-test.py from Todd Lipcon to be python3 compatible and some formatting of output.
# https://github.infra.cloudera.com/raw/todd/experiments/master/kudu/codec-test.py
import pyfastpfor
import numpy as np
import pandas as pd
from timeit import Timer
import bitshuffle
import sys
from prettytable import PrettyTable
The _for128 and _for256 basically uses blocks of 128/256 input integers to calculate the diff
and min across the block simulating the mechanism used in Kudu's encoding implementation.
$ python codec-test.py repeat_small_range.csv
+--------------------------+----------------------+------------------------+--------------+
| codec | comp_time(millisecs) | decomp_time(millisecs) | bits_per_int |
+--------------------------+----------------------+------------------------+--------------+
| bitshuffle | 42.511 | 165.078 | 0.4868 |
| simdbinarypacking | 33.127 | 34.271 | 7.0821 |