Skip to content

Instantly share code, notes, and snippets.

View rreece's full-sized avatar
🙈
doing things

Ryan Reece rreece

🙈
doing things
View GitHub Profile
@rreece
rreece / crop_surrounding_whitespace.py
Created February 17, 2019 23:35
Crop the surrounding whitespace from an image with python
"""
Taken from here:
https://github.com/thumbor/thumbor/issues/116
"""
def crop_surrounding_whitespace(image):
"""Remove surrounding empty space around an image.
This implemenation assumes that the surrounding space has the same colour
as the top leftmost pixel.
"""
Should follow:
https://en.wikipedia.org/wiki/ISO_8601
See also:
- https://stackoverflow.com/questions/2150739/iso-time-iso-8601-in-python
"""
import time
timestamp = time.strftime('%Y-%m-%d-%Hh%M') # '2019-02-14-16h20'
@rreece
rreece / git_tricks.sh
Last active February 17, 2025 23:09
git tricks i always forget
# clone a repo
git clone git@github.com:GitUserOrOrg/repo.git
# create a new branch
git checkout -b rreece/branch1
# set my branch to track the main when i do git pull
git branch --set-upstream-to origin/main
# show branches
@rreece
rreece / save_pbtxt.py
Last active September 13, 2018 20:01
import tensorflow as tf
from google.protobuf import text_format
##______________________________________________________________________________
def model_fn(features, labels, mode, params, pbtxt):
...
optimizer = tf.train.AdamOptimizer(learning_rate=params['lr'])
train_op = optimizer.minimize(loss, global_step=tf.train.get_global_step())
#!/usr/bin/env sh
# This scripts downloads the mnist data and unzips it.
DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd "$DIR"
echo "Downloading..."
for fname in train-images-idx3-ubyte train-labels-idx1-ubyte t10k-images-idx3-ubyte t10k-labels-idx1-ubyte
do
@rreece
rreece / tf-experiment-template.py
Created August 13, 2018 23:57 — forked from damienpontifex/tf-experiment-template.py
A template for a custom tensorflow estimator and experiment with python3 typings for desired parameter types
import argparse
import psutil
import tensorflow as tf
from typing import Dict, Any, Callable, Tuple
## Data Input Function
def data_input_fn(data_param,
batch_size:int=None,
shuffle=False) -> Callable[[], Tuple]:
"""Return the input function to get the test data.
@rreece
rreece / min-char-rnn.py
Last active August 13, 2018 18:34 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
#!/usr/bin/env python3
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
@rreece
rreece / latin1_to_ascii
Last active August 7, 2018 20:20
convert unicode to ascii
#!/usr/bin/env python2
"""
FROM: http://code.activestate.com/recipes/251871/
latin1_to_ascii -- The UNICODE Hammer -- AKA "The Stupid American"
This takes a UNICODE string and replaces Latin-1 characters with
something equivalent in 7-bit ASCII. This returns a plain ASCII string.
This function makes a best effort to convert Latin-1 characters into
ASCII equivalents. It does not just strip out the Latin1 characters.
@rreece
rreece / brew_install_python3.sh
Created August 4, 2018 20:50
Installing python3 on Mac OSX
# Installing python3 on Mac OSX
brew install python3
# Error: An unexpected error occurred during the `brew link` step
# The formula built, but is not symlinked into /usr/local
# Permission denied @ dir_s_mkdir - /usr/local/Frameworks
# Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
#
# See: https://github.com/Homebrew/homebrew-core/issues/19286
@rreece
rreece / Dockerfile.centos7.python36.pipenv
Created August 3, 2018 01:07 — forked from pvergain/Dockerfile.centos7.python36.pipenv
Dockerfile based on centos:7 Python3.6 and pipenv
# Use an official centos7 image
FROM centos:7
RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8
ENV LANG fr_FR.utf8
# gcc because we need regex and pyldap
# openldap-devel because we need pyldap
RUN yum update -y \
&& yum install -y https://centos7.iuscommunity.org/ius-release.rpm \