Skip to content

Instantly share code, notes, and snippets.

View deeplook's full-sized avatar

Dinu Gherman deeplook

View GitHub Profile
@deeplook
deeplook / periodic_timer.py
Created July 20, 2016 12:41
A class wrapping a callable to be called periodically inside a thread.
import datetime
import threading
class PeriodicTimer(object):
"""
A class wrapping a callable to be called periodically inside a thread.
The wrapped function is called the first time immediately after creating
an instance of this class.
@deeplook
deeplook / test-basename-widget.ipynb
Created June 28, 2016 10:31
This is an experiment in creating a Jupyter notebook showing a world map with different parameters (including map projection) by combining a Matplotlib Basemap and IPython widgets.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@deeplook
deeplook / pixel_planet.ipynb
Last active June 13, 2016 09:01
Try to find out easily (read: interactively) using Jupyter widgets how many pixels we need to store in order to cover larger parts of the planet.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
A tool for signaling processes found also by their command-line invocation.
Sometimes you want to terminate a process based on some specific substring
in the command that was entered in a terminal to start it, e.g. here you
might want to terminate only a process like this that is running a Python
SimpleHTTPServer started with::
@deeplook
deeplook / compact_structured_json.py
Last active March 22, 2016 21:50
Create a structured, but more compact JSON representation of a native data structure.
from __future__ import print_function
"""
Create a structured, but more compact JSON representation of a native data structure.
This is inspired by the way native Python data structures are displayed in Jupyter,
e.g.:
In [1]: d = {"count": 7, "limit": 7, "results": [{"path": "wifi", "meaning": "rssi", "points": [{"timestamp": 1458211728242, "value": -67}, {"timestamp": 1458211736170, "value": -74}, {"timestamp": 1458211740399, "value": -62}, {"timestamp": 1458211746265, "value": -64}], "deviceId": "1e31f865-93b9-482a-a7be-858b56c396ae"}, {"path": "/", "meaning": "batteryLevel", "points": [{"timestamp": 1458211728413, "value": 90}, {"timestamp": 1458211736216, "value": 90}, {"timestamp": 1458211740443, "value": 90}], "deviceId": "1e31f865-93b9-482a-a7be-858b56c396ae"}], "offset": 0}
@deeplook
deeplook / nix-vs-python.rst
Created February 21, 2016 14:10
Taking the "Nix tour" with a Python background.

Nix vs. Python

An attempt at contrasting Nix and Python syntax (maybe helpful to grasp Nix faster for those with a Python background) based on the "Nix tour" found here: https://nixcloud.io/tour/?id=1

1. A tour of Nix

@deeplook
deeplook / gist:4e68d09b84c3ca1ffe14
Last active August 29, 2015 14:18
Top 100 of most downloaded packages on PyPI as of 2015-04-10.
+-----+-----------------+-----------------+
| # | Package Name | Total Downloads |
+-----+-----------------+-----------------+
| 1 | setuptools | 52,454,151 |
| 2 | requests | 42,297,369 |
| 3 | virtualenv | 38,499,034 |
| 4 | distribute | 36,848,278 |
| 5 | six | 34,594,923 |
| 6 | boto | 33,578,502 |
| 7 | pip | 29,951,145 |
@deeplook
deeplook / speedread.py
Last active June 5, 2022 20:32
An experiment in speed reading texts in a terminal.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
An experiment in speed reading texts in a terminal.
It implements a "poor man's" version running in a plain terminal. The speed
is given in wpm, words per second. KeyboardInterrupts are captured for pausing
the presentation. At the end a summary is printed. This toy project is much
inspired by an iOS app named ReadQuick:
@deeplook
deeplook / image_displayhook.ipynb
Created March 14, 2013 15:41
An IPython notebook playing with display hook functions to display PIL images and Reportlab drawings.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@deeplook
deeplook / pi_digits.py
Created February 13, 2013 20:16
Generate digits of Pi using a spigot algorithm.
"""
Run the algorithm below using CPython, Cython, PyPy and Numba and compare
their performance. (This is implementing a spigot algorithm by A. Sale,
D. Saada, S. Rabinowitz, mentioned on
http://mail.python.org/pipermail/edu-sig/2012-December/010721.html).
"""
def pi_digits(n):
"Generate n digits of Pi."
k, a, b, a1, b1 = 2, 4, 1, 12, 4