Skip to content

Instantly share code, notes, and snippets.

View clungzta's full-sized avatar

Alex McClung clungzta

View GitHub Profile
@clungzta
clungzta / fasttext_tinkering.py
Last active June 1, 2018 02:39
Playing around with facebook fasttext vectors
import io
import pickle
import numpy as np
from nltk.tokenize import word_tokenize
def load_vectors(fname):
fin = io.open(fname, 'r', encoding='utf-8', newline='\n', errors='ignore')
n, d = map(int, fin.readline().split())
data = {}
for line in fin:
sudo docker build --build-arg CACHEBUST=$(date +%s) -t judgement_ai . && sudo docker kill $(sudo docker ps -q) ; sudo docker run -p 127.0.0.1:5000:5000 -p 127.0.0.1:6006:6006 -t judgement_ai
@clungzta
clungzta / compute_affine_np.py
Last active April 7, 2018 13:31
Compute an affine transform in python
import numpy as np
np.set_printoptions(suppress=True)
pad = lambda x: np.hstack([x, np.ones((x.shape[0], 1))])
primary = np.array([[3, 0],
[0, 3],
[-3, -3],
[0, -3]])
secondary = np.array([[1, 0],
@clungzta
clungzta / fastText_similarity.py
Created March 15, 2018 08:04
Compute similarity of two fastText word embedding vectors using dot product
import fastText
import numpy as np
ftModel = fastText.load_model("WordEmbedding/ftWord.bin")
v1 = np.array(ftModel.get_word_vector("injury"))
v2 = np.array(ftModel.get_word_vector("injuries")) # 0.872767
def get_similarity(v1, v2):
return np.dot(v1/np.sqrt(np.sum(np.square(v1))), v2/np.sqrt(np.sum(np.square(v2))))
@clungzta
clungzta / Dockerfile
Created March 13, 2018 03:15
Setting up docker example
# First, create folder python_app containing some python scripts (e.g. hello_world.py)
####################################################################################
####################################################################################
# To build container:
# sudo docker build .
# To run container:
# sudo docker run [LAST_HEX_ID_THAT_THE_BUILD_SPITS_OUT]
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"
#include <Adafruit_STMPE610.h>
#define LED1 13
#define LED2 14
#define STMPE_CS 32
#define TFT_CS 15
import cv2
import numpy as np
def get_filenames(path, valid_exts=[".jpg", ".png"]):
output = []
for dirpath, subdirs, files in os.walk(path):
for x in files:
if x.lower().endswith(tuple(valid_exts)):
output.append(os.path.join(dirpath, x))
return output
@clungzta
clungzta / build_alexbot_firmware.sh
Last active February 13, 2018 06:42
Build the alexbot firmware from the CLI. First redirect stderr to stdout — pipe to less; then redirect stdout to /dev/null
while true; do ./arduino --verify --board espressif:esp32:featheresp32 '/home/alex/Downloads/alexbot_firmware/alexbot_firmware/alexbot_firmware.ino' 2>&1 >/dev/null | less -p 'warning|error' ; done
// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.
#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial); // Use SWSerial as the serial port.
@clungzta
clungzta / raspberry_pi_car.py
Last active March 27, 2024 23:04
Very Simple Car Driver using a Raspberry Pi 3. Cytron MDD10 Hat controls the motor (Motor 1 port). PWM servo (on GPIO18) controls the steering.
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False) # enable warning from GPIO
GPIO.setmode(GPIO.BCM) # GPIO numbering
class RasPiRCCar():
def __init__(self, motor_dir_pin, motor_pwm_pin, steering_pwm_pin, debug=False):
self.debug = debug
if self.debug: