Skip to content

Instantly share code, notes, and snippets.

View deeplook's full-sized avatar

Dinu Gherman deeplook

View GitHub Profile
@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
@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 / 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 / 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"
#!/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 / 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.
@deeplook
deeplook / benchmark_fib.sh
Last active May 28, 2019 19:43
Benchmark using Fibonacci numbers with Python, Cython and PyPy.
#!/usr/bin/env bash
echo "Benchmark for Fibonacci numbers with Python3, Cython and PyPy"
echo '
def fib(n):
"Return the n-th Fibonacci number."
i = 0
a, b = 0, 1
if n < 2:
@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 / 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 / timestamp.py
Last active September 30, 2024 17:48 — forked from ju-popov/timestamp.py
Python DateTime / Timestamp Conversion
######################################################################
# CURRENT AWARE LOCAL DATETIME
######################################################################
from datetime import datetime
from tzlocal import get_localzone # pip install tzlocal
local_tz = get_localzone()
local_dt = datetime.now(local_tz)