Skip to content

Instantly share code, notes, and snippets.

View jaycosaur's full-sized avatar
🐦

Jacob Richter jaycosaur

🐦
  • Sydney, Australia
View GitHub Profile
@jaycosaur
jaycosaur / fetchHOC.js
Last active February 24, 2018 05:15
React Fetch Higher Order Component Example
const fetchHOC = (WrappedComponent, fetchPath, optionalHeader) => {
return class extends Component {
constructor(props){
super(props)
this.state = {
data: null,
isError: false,
isFetching: true
}
}
@jaycosaur
jaycosaur / FetchAPI.js
Last active February 24, 2018 04:53
React Fetch Render Props Example
class APIFetch extends Component {
constructor(props){
super(props)
this.state = {
data: null,
isError: false,
isFetching: true
}
}
import { google } from 'googleapis';
import { auth } from 'google-auth-library'
export default class getModel {
modelName: string;
projectName: string;
constructor(attrs) {
this.modelName = attrs.modelName
this.projectName = attrs.projectName
@jaycosaur
jaycosaur / OverwritingRingBuffer.ts
Created October 11, 2019 09:55
Typescript implementation of overwriting ring buffer with memory of insertion position for gets. Useful for a rolling video frame / audio frame cache requiring lookups.
// extension of classical overwriting ring buffer that holds an incremental counter that can be indexed
// this should not be used for read heavy write infrequent streams (as a map would be a much mor effective implementation)
// this could be used for write heavy read infrequent streams
export class OverwritingRingBuffer<T> {
private buffer: T[];
private bufferLength: number;
private pointer: number;
private counter: number;
from shared import camera_producer, cpu_bound, display
def main():
frames = camera_producer()
cpu_bound_op = cpu_bound()
for frame in frames:
cpu_bound_op(frame)
display(frame)
import cv2
import time
import numpy as np
from threading import Thread
from queue import Queue
log_const = 30
import cv2
import time
import numpy as np
import multiprocessing as mp
log_const = 30
class FPS:
import cv2
import time
import numpy as np
import multiprocessing as mp
log_const = 30
shared_frame = mp.RawArray('B', 2764800)
camera_dims = (720, 1280, 3)
@jaycosaur
jaycosaur / select.py
Last active February 1, 2020 12:16
Select statement golang emulation in python.
from queue import Queue
from threading import Thread
from typing import Any, List, Iterator
class PipeClose:
pass
class PipeExtra:
@jaycosaur
jaycosaur / sync_to_async_queue.py
Created January 27, 2020 21:39
Working with asyncio and sync worker processes is always a pain, not anymore with Janus and this convertor. Async -> Sync is also trivial to implement.
from queue import Queue
from threading import Thread
from typing import cast
import asyncio
import janus
# note that this will never cleanup the thread. You will need to implement your own shutdown logic / methods.
def sync_to_async_queue(queue: Queue, loop: asyncio.AbstractEventLoop) -> asyncio.Queue:
conversion_queue: janus.Queue = janus.Queue(loop=loop)