Skip to content

Instantly share code, notes, and snippets.

View randerzander's full-sized avatar

Randy Gelhausen randerzander

View GitHub Profile
import imageio
import cv2
import numpy as np
# Load GIF
gif = imageio.mimread('calvin.gif')
frames = [cv2.cvtColor(np.array(frame), cv2.COLOR_RGBA2BGR) for frame in gif]
def is_panel(box, w_thresh=200, h_thresh=200):
x, y, w, h = box
@randerzander
randerzander / football.css
Last active November 26, 2022 13:42
Terminal UI for displaying live college or nfl game status
Game {
height: 3;
width: 50%;
}
@randerzander
randerzander / things.py
Last active November 25, 2022 19:11
Basic dynamic textual app
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.reactive import reactive
from textual.widgets import Static
class Thing(Static):
def __init__( self, text ) -> None:
self._text = text
super().__init__()
# determines whether a GPU is available in your instance and starts an appropriate Dask Cluster
from dask.distributed import Client, LocalCluster
from dask_cuda import LocalCUDACluster
from dask_sql import Context
from pyngrok import ngrok
import dask
import time
import warnings
from IPython.core.magic import needs_local_scope, register_cell_magic
from IPython.core.magic import register_cell_magic, needs_local_scope
from sql_formatter.core import format_sql
import time, warnings
warnings.filterwarnings("ignore")
@register_cell_magic
@needs_local_scope
def sql(line, cell, local_ns):
sql_statement = cell.format(**local_ns)
df = spark.createDataFrame(
[
(1, 'foo'), # create your data here, be consistent in the types.
(2, 'bar'),
],
['id', 'txt'] # add your columns label here
)
df.write.csv('test')
spark.read.csv('test').collect()
@randerzander
randerzander / server.py
Created March 13, 2018 02:32
Simple Python3 webserver with custom POST handler
import sys, os, cgi, _thread
from http.server import SimpleHTTPRequestHandler, HTTPServer
class MyServer(SimpleHTTPRequestHandler):
#Custom POST handler that saves POSTed file content to local disk
def do_POST(self):
post_env = {
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': self.headers['Content-Type'],
}
@randerzander
randerzander / edit_distance.py
Last active February 10, 2018 03:38
Pretty inefficient computation of minimum edit distance between two strings
# Generate all substrings of string recursively
def substrings(string):
#base case
if len(string) == 0: return ''
else:
ret = [string]
#Slide from left
for x in range(0, len(string)):
sub = string[x:-1]
ret.append(sub)
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
import os, sys, imp, traceback, time
from urlparse import urlparse
parser_path = '/home/dev/projects/scripts/parsers/'
class PyStreamCallback(StreamCallback):

Keybase proof

I hereby claim:

  • I am randerzander on github.
  • I am randerzander (https://keybase.io/randerzander) on keybase.
  • I have a public key ASCodRRwJM9qPoQ6VvIz9cMx_U62fP7QCTDFkdE7PBnuuwo

To claim this, I am signing this object: