Skip to content

Instantly share code, notes, and snippets.

View deeplook's full-sized avatar

deeplook

View GitHub Profile
@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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / slowcat.py
Created July 28, 2017 11:56
Implement a "slow-motion" Unix 'cat' command.
#!/usr/bin/env python
"""
Implement a "slow-motion" Unix 'cat' command.
Intended to be used with tools like 'asciinema', see asciinema.org.
None of the options of Unix 'cat' are implemented here.
Examples:
@deeplook
deeplook / mapit.py
Last active August 8, 2017 11:31
A little tool to render GeoJSON files as layers in an HTML output map file.
#!/usr/bin/env python
"""
A little tool to render GeoJSON files as layers in an HTML output map file.
The output map shows the region covered by the combined bounding box of all
GeoJSON input files. This was tested only with Python 3.5, but should also
work on Python >= 2.7.
The pygeoj package does calculate the bounding box correctly only for version
@deeplook
deeplook / scalavarning.py
Created September 28, 2017 09:22
Spot single tokens (like the 'var' keyword) in Scala source code files.
#!/usr/bin/env python
"""
List keyword tokens in Scala source code.
Originally intended for spotting lines containing "var" declarations
in Scala source files (hence the name "scala varning") which are
somewhat considered "harmful" in Scala. The same can be useful for
spotting explicit "return" statements which might be superfluous,
and, of course, other keywords.
#!/usr/bin/env python
"""
An updated example file actually using an auto-upgrading tool.
WARNING:
If you find this script inside a GitHub gist, be warned that
its gist ID might change without notice! In this case please
look for similar filenames until this might become part of
@deeplook
deeplook / autofib-screencast.json
Created October 13, 2017 13:36
A simple module to allow Python scripts to upgrade themselves. (WIP)
{
"version": 1,
"width": 109,
"height": 25,
"duration": 80.986919,
"command": null,
"title": null,
"env": {
"TERM": "xterm-256color",
"SHELL": "/bin/bash"
@deeplook
deeplook / dynamic_cpu_load.py
Created November 3, 2017 22:56
Prototype of a 'dynamic' prompt showing CPU load over 10 seconds as a sparkline.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Prototype of a 'dynamic' prompt showing CPU load over 10 seconds as a sparkline.
Requires ``psutil``...
Not finished...
"""
@deeplook
deeplook / webpage_screenshot.py
Created November 7, 2017 13:27
Snippet for making a screenshot of a webpage in a browser.
import re
from selenium import webdriver # pip install selenium
from PIL import Image # pip install Pillow
driver = webdriver.PhantomJS() # assuming PhantomJS
width, height = 1024, 768
driver.set_window_size(width, height)
driver.get("http://docs.python-requests.org")
fn = "screenshot.png"
driver.save_screenshot(fn)
@deeplook
deeplook / browse_api.py
Last active December 22, 2017 22:31
Explore a RESTful Swagger/OpenAPI specification (JSON file) with Swagger-UI in a browser.
#!/usr/bin/env python
"""
Explore a RESTful Swagger/OpenAPI specification with Swagger-UI in a browser.
Features:
- download a recent Swagger-UI release
- extract its "dist" folder
- copy desired JSON file into "dist" folder