Skip to content

Instantly share code, notes, and snippets.

@amitkot
amitkot / huobi_excerciser.py
Created May 3, 2018 05:43
testing ccxt huobi rate limits
import asyncio
import time
import ccxt.async as ccxt
def minutes_ago_in_millis_since_epoch(minutes):
return int(round(time.time() * 1_000)) - 60_000 * minutes
from cex_rebalance import CexRebalance
class Exchanges:
pass
class Fetcher_Interfaces():
pass
@amitkot
amitkot / dict_union.py
Created March 20, 2018 14:52
Concatenate dictionaries
def dict_union(*dicts):
return dict(itertools.chain.from_iterable(d.items() for d in dicts))
@amitkot
amitkot / multiple_exchanges_pairs.py
Last active March 8, 2018 11:27
Exchange Order Books
{'Binance': {('ADA', 'BTC'): {'asks': [[2.356e-05, 8527.0],
[2.357e-05, 3001.0],
[2.358e-05, 166607.0],
[2.359e-05, 625.0],
[2.36e-05, 41771.0],
[2.362e-05, 1847.0],
[2.363e-05, 17057.0],
[2.364e-05, 26908.0],
[2.365e-05, 48479.0],
[2.366e-05, 3325.0],
@amitkot
amitkot / async_is_done_test.py
Created January 22, 2018 07:36
Python asyncio: Testing if task finished already
import asyncio
async def slow():
print('Started task')
await asyncio.sleep(3)
print('Finished task')
async def do_things(loop):

Keybase proof

I hereby claim:

  • I am amitkot on github.
  • I am amitkot (https://keybase.io/amitkot) on keybase.
  • I have a public key ASCQppUP-feZYYK6SZjTTxJb-rvbnyug5jGhCNhNX1awwwo

To claim this, I am signing this object:

keywords = {
["date"] = function() return os.date("%B %d, %Y") end,
["name"] = "my name is MISTER",
}
expander = hs.hotkey.bind({"alt"}, "d", nil, function() -- don't start watching until the keyUp -- don't want to capture an "extra" key at the begining
local what = ""
local keyMap = require"hs.keycodes".map -- shorthand... in a formal implementation, I'd do the same for all `hs.XXX` references, but that's me
local keyWatcher
keyWatcher = hs.eventtap.new({ hs.eventtap.event.types.keyUp, hs.eventtap.event.types.keyDown }, function(ev)
@amitkot
amitkot / Dimens.java
Last active January 15, 2017 09:47 — forked from vincetreur/Dimens.java
A small utility to help converting between dips and pixels in your Android code. Most solutions are unreadable, this one should read a lot better.
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.util.TypedValue;
/**
* Convert between DP and pixels, like {@link java.util.concurrent.TimeUnit} does.
* For example:
* Dimens.DP.toPX(context.getResources(), 16); // 16dp to pixels
* Dimens.PX.toDP(context.getResources(), 16); // 16px to dips
@amitkot
amitkot / builtin_macbook_keyboard_with_tilda.keylayout
Created September 13, 2016 07:52
Mac keyboard layout for using a UK keyboard with US layout, essentially mapping the key above the Tab to be Tilda
<?xml version="1.1" encoding="UTF-8"?>
<!DOCTYPE keyboard SYSTEM "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--Last edited by Ukelele version 3.1.0.105 on 2016-09-13 at 10:22 (GMT+3)-->
<keyboard group="4" id="0" name="ABC" maxout="1">
<layouts>
<layout first="0" last="17" mapSet="16c" modifiers="f4"/>
<layout first="18" last="18" mapSet="984" modifiers="f4"/>
<layout first="21" last="23" mapSet="984" modifiers="f4"/>
<layout first="30" last="30" mapSet="984" modifiers="f4"/>
<layout first="194" last="194" mapSet="984" modifiers="f4"/>
import contextlib
import os
@contextlib.contextmanager
def working_directory(path):
"""A context manager which changes the working directory to the given
path, and then changes it back to its previous value on exit.
"""