Skip to content

Instantly share code, notes, and snippets.

View BibMartin's full-sized avatar

Martin Journois BibMartin

View GitHub Profile
@BibMartin
BibMartin / install-mongodb-on-ubuntu
Created March 30, 2016 09:59
install-mongodb-on-ubuntu
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
@BibMartin
BibMartin / Asynchronous service with tornado.ipynb
Created April 1, 2016 21:06
Asynchronous service with tornado
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BibMartin
BibMartin / index.html
Last active April 7, 2017 12:45
TimeDimension Heatmap
<!DOCTYPE html>
<head>
<!-- FOLIUM (simplified) HEADER -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"></script>
@BibMartin
BibMartin / MeasureControl.ipynb
Created October 29, 2016 10:01
MeasureControl.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BibMartin
BibMartin / gist:eb08cf972c33d5d2552274eaf2e3887f
Created January 21, 2017 14:13
A tornado web service that self-calls itself periodically
import tornado.ioloop
import tornado.web
import pandas as pd
import requests
import os
class MainHandler(tornado.web.RequestHandler):
def get(self):
print('handler', pd.Timestamp.utcnow())
self.write(str(self.request.headers.get('Authorization')))
def unstack(x, prefix=""):
if isinstance(x, dict):
out = {}
for key, val in x.items():
z = unstack(val, prefix=key+'.')
if isinstance(z, dict):
for subkey, subval in z.items():
out[prefix+subkey] = subval
else:
out[prefix+key] = val
@BibMartin
BibMartin / gist:b0219727266515fa2af059df7f75b967
Last active May 9, 2017 12:21
Hack pandas.DataFrame to have unstacked JSON structure
from pandas import DataFrame, MultiIndex
def __getattribute__(self, x):
try:
return _parent__getattribute__(self, x)
except AttributeError:
columns = _parent__getattribute__(self, 'columns')
cols = list(set([x.split('.')[0] for x in columns]))
if x in cols:
_prefix = x + '.'
@BibMartin
BibMartin / gist:42f8c429169620f24376f8ab8f30a5b3
Last active March 18, 2022 10:11
Kill a process (and all it's children) based on a `ps -fA | grep` output
## Brutal shortcuts:
# Kill everything launched with "python registry.py"
kill -SIGTERM -$(ps aux | grep 'python registry.py' | awk '{print $2}')
# Same in a function
grepkill() { kill -SIGTERM -$(ps aux | grep $1 | awk '{print $2}'); }
# Restart a uvicorn server
git reset --hard ; kill -SIGTERM $(ps aux | grep 'uvicorn server:app' | grep -v "grep" | awk '{print $2}'); nohup uvicorn server:app --host 127.0.0.1 --port 8000 > server.log &