Skip to content

Instantly share code, notes, and snippets.

View hadware's full-sized avatar

hadware

View GitHub Profile
@nhamilakis
nhamilakis / component.ts
Last active October 16, 2019 08:59
Get Stuff in Angular
class Corpus {
name: string;
}
@TrucAngularAUZEF
class MyCorporaComponent extends OnInit {
listCorpora : Array<Corpus> = [];
constructor(private api: MyAPIServiceDeLEspace){}
@bre7
bre7 / scanner-with-imagemagick.md
Last active November 17, 2023 23:04
Simulate photo copier / fax / scanner effect using ImageMagick

Solution 1

convert original.pdf -colorspace gray +clone -blur 0x1 +swap -compose divide -composite -linear-stretch 5%x0% -rotate 1.5 fake-scanned.pdf

Colorscan variation:

A Tour of PyTorch Internals (Part I)

The fundamental unit in PyTorch is the Tensor. This post will serve as an overview for how we implement Tensors in PyTorch, such that the user can interact with it from the Python shell. In particular, we want to answer four main questions:

  1. How does PyTorch extend the Python interpreter to define a Tensor type that can be manipulated from Python code?
  2. How does PyTorch wrap the C libraries that actually define the Tensor's properties and methods?
  3. How does PyTorch cwrap work to generate code for Tensor methods?
  4. How does PyTorch's build system take all of these components to compile and generate a workable application?

Extending the Python Interpreter

PyTorch defines a new package torch. In this post we will consider the ._C module. This module is known as an "extension module" - a Python module written in C. Such modules allow us to define new built-in object types (e.g. the Tensor) and to call C/C++ functions.

@rroohhh
rroohhh / client.sh
Created February 3, 2017 21:21
gstreamer udp audio streaming
#!/bin/bash
gst-launch-1.0 -v udpsrc uri=udp://239.1.1.1:5000 caps="application/x-rtp,channels=(int)2,format=(string)S16LE,media=(string)audio,payload=(int)96,clock-rate=(int)44100,encoding-name=(string)L24" ! rtpL24depay ! audioconvert ! autoaudiosink sync=false
@tuxedocat
tuxedocat / levd.py
Last active October 20, 2022 18:30
compute levenshtein distance
import numpy as np
from numba import jit
def levenshtein(x, y):
""" levenshtein distance for iterable sequences
"""
# check type
if (np.all(map(type, x)) is str) and (np.all(map(type, y)) is str):
_x = np.array(x, dtype=np.str)
@hosackm
hosackm / flaskaudiostream.py
Created September 2, 2015 22:30
Flask streaming an audio file
from flask import Flask, Response
app = Flask(__name__)
@app.route("/wav")
def streamwav():
def generate():
with open("signals/song.wav", "rb") as fwav:
data = fwav.read(1024)
@rogererens
rogererens / client_kivy.py
Created October 2, 2014 21:54
A Kivy client for the AutobahnPython WebSocket Echo server (Twisted-based)
# As the Kivy docs ( http://kivy.org/docs/guide/other-frameworks.html ) state:
# install_twisted_rector must be called before importing and using the reactor.
from kivy.support import install_twisted_reactor
install_twisted_reactor()
from autobahn.twisted.websocket import WebSocketClientProtocol, \
WebSocketClientFactory
class MyKivyClientProtocol(WebSocketClientProtocol):
@rriemann
rriemann / gist:7214543
Created October 29, 2013 13:22
use convert from Imagemagick to compress black/white scans to 2bit tiff files
convert Image-0001.png Image-0002.png -depth 2 -colorspace Gray output.tiff