Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bvpatel's full-sized avatar

Bhavesh Patel bvpatel

  • Pune, India
View GitHub Profile
@bvpatel
bvpatel / PerfectRootHex.java
Created June 17, 2021 11:44
Given a hexadecimal string, s (e.g. "1a", "12b9c7"). Find out the minimum number of pieces, i, to split this string such that each of the i pieces is a hexadecimal representation of a perfect square.
/*
Apollo likes perfect squares of integers (e.g. 1, 4, 9, 25 etc). You are given a hexadecimal string, s (e.g. "1a", "12b9c7"). Find out the minimum number of pieces, i, to split this string such that each of the i pieces is a hexadecimal representation of a perfect square. Note that this may not be possible for every hexadecimal string.
Complete the getMin function in your editor, in a language of your choice. It has one parameter: a string, s, a valid representation of a hexadecimal number. It must return an integer denoting the value of i; if there is no such positive integer i, return ?1.
Bonus: Performance is a concern. An unoptimized solution will see timeouts in some of the large test cases.
Input Format
The locked stub code in your editor reads a hexadecimal string, s, from stdin and passes it to your function. The input will conform to the following formats:
@bvpatel
bvpatel / errors.go
Created May 3, 2021 05:28 — forked from sudaraka94/errors.go
Custom error struct and helpers
package errors
import "github.com/sirupsen/logrus"
type Operation string
type ErrorType string
const (
NotFoundError ErrorType = "NOT_FOUND"
@bvpatel
bvpatel / cookie_jar.go
Created December 14, 2020 06:56 — forked from rowland/cookie_jar.go
Go http client with cookie support
@bvpatel
bvpatel / run.sh
Created October 19, 2019 17:48
Java daemon service for init.d
#!/bin/sh
SERVICE_NAME=MyService
PATH_TO_JAR=/usr/local/MyProject/MyJar.jar
PID_PATH_NAME=/tmp/MyService-pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PID_PATH_NAME
@bvpatel
bvpatel / monitor.sh
Created October 17, 2019 12:21
Monitoring linux services
#!/bin/bash
service=$@
/bin/systemctl -q is-active "$service.service"
status=$?
if [ "$status" == 0 ]; then
echo "OK"
else
/bin/systemctl start "$service.service"
fi
@bvpatel
bvpatel / 00. tutorial.md
Created July 27, 2019 07:27 — forked from maxivak/00. tutorial.md
Importing/Indexing database (MySQL or SQL Server) in Solr using Data Import Handler
@bvpatel
bvpatel / DistributedObjectCache.java
Last active April 11, 2019 06:39
Distributed cache for object in Map reduce job
package pubmatic.matrix.confluent.utils;
import org.apache.commons.io.FilenameUtils;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.log4j.Logger;
import java.io.*;
@bvpatel
bvpatel / nginx.conf
Created January 24, 2018 08:36 — forked from micho/nginx.conf
nginx config for http/https proxy to localhost:3000
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf: