Skip to content

Instantly share code, notes, and snippets.

View wanghaisheng's full-sized avatar
🏠
got a covid like heavy fever for the last days

HeisenBerg? wanghaisheng

🏠
got a covid like heavy fever for the last days
View GitHub Profile
@jmandel
jmandel / design.md
Last active January 8, 2020 18:19
Desiging a framework for triggered notifications in FHIR

Proposal: Triggered Notifications

Use case: subscribing to specific lab observations

FHIR offers a REST API that lets clients search for resources on demand. Separately, there is a Messaging API that allows notifications to be "pushed" from one place to another. But neither API provides a clean solution to a common set of real-world "triggering" or notification-type requirements.

For example, let's say Mt. Auburn Hospital's Mother and Infant Unit wants to

@milkbottlelough
milkbottlelough / product-thumnail.liquid
Created December 11, 2019 14:08
Shopify - Show a percentage discount "on sale" button
...
...
{%- assign percentageDiscount = product.compare_at_price_max | minus: product.price | times: 100.0 | divided_by: product.compare_at_price_max | money_without_currency | times: 100 | remove: '.0' -%}
{% if product.compare_at_price_max > product.price %}
<div class="sale-banner"><span>{{ 'collections.general.sale' | t }}</span><p>{{percentageDiscount}}%<span>OFF!</span></div>
{% endif %}
...
@mnot
mnot / uri_validate.py
Last active March 3, 2022 14:32
uri_validate.py: Validation regex for URIs, URI references, and relative URIs
#!/usr/bin/env python
"""
Regex for URIs
These regex are directly derived from the collected ABNF in RFC3986
(except for DIGIT, ALPHA and HEXDIG, defined by RFC2234).
Additional regex are defined to validate the following schemes according to
their respective specifications:
@mrf345
mrf345 / build_flask_.sh
Created October 7, 2017 13:20
Building one-file executable for Python Flask using Pyinstaller
#!/bin/bash
pyinstaller -F -w \
--hidden-import='email.mime.multipart' \
--hidden-import='email.mime.message' \
--hidden-import='email.mime.text' \
--hidden-import='email.mime.image' \
--hidden-import='email.mime.audio' \
--hidden-import='sqlalchemy.sql.default_comparator' \
--hidden-import='jinja2' \
main.py
#!/usr/bin/env python3
from inspect import _empty, signature
def get_multiparameter_callback(callback, **parameters):
callback_sig_p = signature(callback).parameters
# If some provider parameter does not belong to callback parameters.
unexpected_parameters = list(parameters.keys() - callback_sig_p.keys())
if len(unexpected_parameters) > 0:
@fabtho
fabtho / save_screenshot.py
Last active December 12, 2022 08:07
make full screenshot with selenium in python
#!/usr/bin/python
from selenium import webdriver
from PIL import Image
from cStringIO import StringIO
verbose = 1
browser = webdriver.Firefox()
browser.get('http://stackoverflow.com/questions/37906704/taking-a-whole-page-screenshot-with-selenium-marionette-in-python')
@seanh
seanh / formatFilename.py
Created April 11, 2009 18:30
Turn any string into a valid filename in Python.
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.
@acdha
acdha / custom-log-filtering-and-formatting.py
Created February 26, 2014 21:19
Example of how to filter or apply custom formatting using Python's logging library
#!/usr/bin/env python
# encoding: utf-8
from pprint import pformat, pprint
import logging
class PasswordMaskingFilter(logging.Filter):
"""Demonstrate how to filter sensitive data:"""
@bitsgalore
bitsgalore / loggingGUI.py
Created January 31, 2017 13:43
Minimal threaded GUI application with logging to both text file and ScrolledText widget
#! /usr/bin/env python
import time
import threading
import logging
try:
import tkinter as tk # Python 3.x
import tkinter.scrolledtext as ScrolledText
except ImportError:
import Tkinter as tk # Python 2.x
import ScrolledText
@dannguyen
dannguyen / README.md
Last active December 28, 2023 15:21
Using Python 3.x and Google Cloud Vision API to OCR scanned documents to extract structured data

Using Python 3 + Google Cloud Vision API's OCR to extract text from photos and scanned documents

Just a quickie test in Python 3 (using Requests) to see if Google Cloud Vision can be used to effectively OCR a scanned data table and preserve its structure, in the way that products such as ABBYY FineReader can OCR an image and provide Excel-ready output.

The short answer: No. While Cloud Vision provides bounding polygon coordinates in its output, it doesn't provide it at the word or region level, which would be needed to then calculate the data delimiters.

On the other hand, the OCR quality is pretty good, if you just need to identify text anywhere in an image, without regards to its physical coordinates. I've included two examples:

####### 1. A low-resolution photo of road signs