Skip to content

Instantly share code, notes, and snippets.

View rldotai's full-sized avatar

Brendan Bennett rldotai

View GitHub Profile
@willmcgugan
willmcgugan / calculator.css
Created August 30, 2022 15:16
Textual calculator example
Screen {
overflow: auto;
}
#calculator {
layout: table;
table-size: 4;
table-gutter: 1 2;
table-columns: 1fr;
table-rows: 2fr 1fr 1fr 1fr 1fr 1fr;
@rldotai
rldotai / comfy.py
Last active July 31, 2020 22:57
Common packages and utility functions that I find helpful
"""Setting up the local environment."""
import itertools
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from functools import reduce
@druska
druska / engine.c
Created September 17, 2018 15:18
Quant Cup 1's winning order book implementation
/*****************************************************************************
* QuantCup 1: Price-Time Matching Engine
*
* Submitted by: voyager
*
* Design Overview:
* In this implementation, the limit order book is represented using
* a flat linear array (pricePoints), indexed by the numeric price value.
* Each entry in this array corresponds to a specific price point and holds
* an instance of struct pricePoint. This data structure maintains a list
@rldotai
rldotai / convenient_sort.py
Created February 5, 2018 04:04
A slightly more convenient alternative to the builtin `sorted()` which allows you to specify a key as something other than a function.
"""
A slightly more convenient alternative to the builtin `sorted()` which allows
you to specify a key as something other than a function.
For example, with a list of lists, if you wanted to sort by the last element you
could use `sort(lstseq, key=-1)` rather than `sorted(lstseq, key=lambda x: x[-1])`.
If your key *is* a function, it behaves identically to `sorted()`, because it is
really just wrapping the builtin.
Examples
--------
@jwhendy
jwhendy / set_opencv_webcam.py
Last active September 8, 2023 09:52
An example of setting webcam settings via v4l2-ctl in a python script. Some of the CAP_* settings in opencv didn't seem to work.
import cv2
import subprocess
### for reference, the output of v4l2-ctl -d /dev/video1 -l (helpful for min/max/defaults)
# brightness (int) : min=0 max=255 step=1 default=128 value=128
# contrast (int) : min=0 max=255 step=1 default=128 value=128
# saturation (int) : min=0 max=255 step=1 default=128 value=128
# white_balance_temperature_auto (bool) : default=1 value=1
# gain (int) : min=0 max=255 step=1 default=0 value=0
# power_line_frequency (menu) : min=0 max=2 default=2 value=2
@reywood
reywood / how-to.md
Last active September 18, 2023 01:35
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running python script

Sometimes a python script will simply hang forever with no indication of where things went wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward. Here's a way to see where the program is currently stuck.

Install gdb and pyrasite

Install gdb.

# Redhat, CentOS, etc
@cube-drone
cube-drone / automation.md
Last active March 26, 2024 20:24
Automation For The People

Automation for the People

Long ago, the first time I read "The Pragmatic Programmer", I read some advice that really stuck with me.

"Don't Use Manual Procedures".

This in the chapter on Ubiquitous Automation. To summarize, they want you to automate all the things.

The trouble was that I hadn't much of an idea how to actually go

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dannguyen
dannguyen / README.md
Last active July 6, 2024 16:36
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

@dannguyen
dannguyen / selenium-screenshotting.md
Last active February 15, 2023 15:59
Using Selenium and Python to screenshot a javascript-heavy page

Using Selenium and Python to screenshot a javascript-heavy page

As websites become more JavaScript heavy, it's harder to automate things like screenshotting for archival purposes. I've seen examples and suggestions to use PhantomJS for visual testing/archiving of websites, but have run into issues such as the non-rendering of webfonts. I've never tried out Selenium until today...and while I'm not thinking about performance implications yet, Selenium seems far more accurate than PhantomJS...which makes sense since it actually opens a real browser. And it's not too hard to script to do complex interactions: here's an [example of how to log in to Twitter, write a tweet, upload an image, and send a tweet via Selenium and DOM element selection](https://gist.github.com/dannguyen/8a6fa49253c1d6a0eb92