Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am pathikrit on github.
  • I am pathikrit (https://keybase.io/pathikrit) on keybase.
  • I have a public key whose fingerprint is 32D0 C3DF 1F9B ABA2 E61A C553 8F5B 9198 DEFF 220E

To claim this, I am signing this object:

@pathikrit
pathikrit / maps_wishlist.md
Last active August 29, 2015 14:15
What I want from Google Maps
  • When I ask for driving directions to somewhere it should suggest "Shall I direct you to the nearest parking spot from your destination"?

  • When I drive somewhere, I should have advanced options to say that I need to fill gas within the next x miles on the way to my destination.

  • They should have OBD plugins like automatic.com to do this automatically for most cars.

  • Sometimes I arrive at my destination but I miss it and direction exits saying that I arrived but I am lost now since I drove passed the address. It should detect that if I drove past my destination and start auto-rerouting.

  • If I entered a business or restaurant address, it should auto warn if it is closed or closes soon by the time I reach it.

@pathikrit
pathikrit / weeker.scala
Last active August 29, 2015 14:17
Natural weekday chooser
val weekdays = IndexedSeq("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
def solve(idx: Int*) = (idx foldLeft Seq.empty[(Int, Int)]) {
case (ts :+ ((start, end)), x) if x == end + 1 => ts :+ (start, x)
case (t, x) => t :+ (x, x)
} map {
case (start, end) if start == end => weekdays(start)
case (start, end) => s"${weekdays(start)}-${weekdays(end)}"
}
@pathikrit
pathikrit / debounce.scala
Last active August 29, 2015 14:26
Debounce in Scala
import scala.compat.Platform.{currentTime => now}
import scala.concurrent.duration.FiniteDuration
import java.util.concurrent.atomic.AtomicBoolean
/**
* Debounce a function i.e. it can only be invoked iff it is not already running
* and atleast wait duration has passed since it last stopped running
* Usage:
* def test(i: Int) = println(i)
import java.util.BitSet;
import java.util.NavigableSet;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentSkipListSet;
/**
* A concurrent sorted set with a fixed bound
*/
public class BoundedConcurrentSortedSet {
@pathikrit
pathikrit / MyAnt.java
Created November 20, 2012 21:00
Addepar Ants (solution to https://addepar.com/challenge.php)
import ants.Action;
import ants.Ant;
import ants.Direction;
import ants.Surroundings;
import ants.Tile;
import java.awt.Point;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
@pathikrit
pathikrit / bloomberg.js
Created December 4, 2012 04:38
Bloomberg scraper
var config = require('./config'), request = require('request'), fs = require('fs'), Zip = require('adm-zip'), path = require('path');
var tmpDir = 'tmp';
fs.mkdir(tmpDir);
request.post(config.bloomberg.bsym_url, function (err, res, body) {
if(err) throw err;
var record = eval('(' + body.substring(body.indexOf('{data'), body.lastIndexOf(';')));
record.data.forEach(function(data) {
var url = data.uri, name = path.join(tmpDir, url.substring(url.lastIndexOf('/') + 1));
import collection.mutable
import collection.JavaConversions._
import org.mapdb.DBMaker // Great disk based map - https://github.com/jankotek/MapDB
/**
* My attempt at http://www.azspcs.net/Contest/Factorials/
* Brief explanation:
* Brute force BFS (ignoring non-positive numbers and duplicates) upto length `fbf`
* Higher the `fbf`, the better quality result. I managed to get to `fbf`=8 before running out of memory
* Beyond `fbf`, try to multiply your way to n! Since the last few steps involve only multiplication,
@pathikrit
pathikrit / Calendar.java
Created March 28, 2013 08:29
Some crazy code
/*
* Works from dates after Sep 14, 1752 (New System of Gregorian Calendar (UK adoption))
* May crash or return junk value for negative or other invalid inputs.
*/
public static String calendar(int d, int m, int y) {return "Sun Mon Tues Wednes Thurs Fri Satur ".substring(d=((6-2*(y/100%4)+(m<3&&y%4==0&&(y%100!=0||y%400==0)?-1:0)+(y%=100)/12+5*(y%12)/4+"xbeehcfhdgbeg".charAt(m)+d)%7)*7,d+7).trim()+"day";}
@pathikrit
pathikrit / Trick.java
Last active December 15, 2015 23:58
You win a prize if you correctly guess the output
import java.util.*;
public class Trick {
public static void main(String args[]) {
System.out.println("/////////////////////////////////////////////////");
HashSet<Long> h = new HashSet();
Long l = (long)4;
h.add(l);
System.out.println(h.contains(4));