Skip to content

Instantly share code, notes, and snippets.

View bryant1410's full-sized avatar

Santiago Castro bryant1410

View GitHub Profile
public String partToString() throws Exception {
javax.servlet.http.Part part;
try (java.util.Scanner scanner = new java.util.Scanner(part.getInputStream())) {
if (scanner.useDelimiter("\\A").hasNext()) {
return scanner.next();
} else {
return "";
}
}
}
@bryant1410
bryant1410 / onehot_pandas_scikit.py
Last active August 29, 2015 14:07 — forked from kljensen/onehot_pandas_scikit.py
This function helps to do a one hot encoding of a pandas' dataframe instead of a features numpy matrix. This has some advantages, for instance the fact of knowing which new columns have been created (identifying them easily).
# -*- coding: utf-8 -*-
""" Small script that shows hot to do one hot encoding
of categorical columns in a pandas DataFrame.
See:
http://scikit-learn.org/dev/modules/generated/sklearn.preprocessing.OneHotEncoder.html#sklearn.preprocessing.OneHotEncoder
http://scikit-learn.org/dev/modules/generated/sklearn.feature_extraction.DictVectorizer.html
"""
import pandas
import random
@bryant1410
bryant1410 / mp4amp3
Created November 28, 2014 02:07
Convert all mp4 files to mp3 in current directory, deleting them
#!/usr/bin/env bash
# seen in http://www.unixmen.com/linux-basics-convert-mp4-mp3/
for filename in *.mp4
do
name=`echo "$filename" | sed -e "s/.mp4$//g"`
ffmpeg -i "$filename" -b:a 192K -vn "$name.mp3"
rm "$filename"
done
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@bryant1410
bryant1410 / remove_channels.py
Created July 12, 2016 15:43
Remove channels from Twilio IP Messaging
#!/usr/bin/env python3
import requests
# noinspection SpellCheckingInspection
SERVICE_SID = '...'
# noinspection SpellCheckingInspection
ACCOUNT_SID = '...'
# noinspection SpellCheckingInspection
AUTH_TOKEN = '...'
@bryant1410
bryant1410 / make-arXiv-package.sh
Last active January 24, 2017 01:31 — forked from robince/make-arXiv-package.sh
Script to prepare arXiv package of a document that depends on a recent texlive version of biblatex (using pdflatex)
#!/usr/bin/env bash
# This script is useful if:
# - you have a manuscript that you want to upload to the arXiv,
# - you are using biblatex, and
# - you are using a recent version of texlive while arXiv is still on texlive2011
#
# Put this file in a directory containing the manuscript you want to
# upload to arXiv.org, and adapt the paths below.
@bryant1410
bryant1410 / tensorboard_pb.py
Created June 14, 2018 18:06
Load protobuf in tensorboard
# import tensorflow as tf
# from tensorflow.python.platform import gfile
# with tf.Session() as sess:
# model_filename ='aaa.pb'
# with gfile.FastGFile(model_filename, 'rb') as f:
# graph_def = tf.GraphDef()
# graph_def.ParseFromString(f.read())
# g_in = tf.import_graph_def(graph_def)
# LOGDIR='logsst2'
# train_writer = tf.summary.FileWriter(LOGDIR)
@bryant1410
bryant1410 / snap-refresh-home-nfs.sh
Last active November 20, 2018 18:25
This script is a workaround to refresh the snaps under a NFS /home directory with root_squash option (the default).
#!/usr/bin/env bash
# This script is a workaround to refresh the snaps under a NFS /home directory with root_squash option (the default).
# Note that using no_root_squash is insecure.
# The bug was already filed: https://bugs.launchpad.net/snappy/+bug/1804281
set -ex
BACKUP_DIR=/s # CREATE AND/OR CHANGE THIS.
import time
import torch
import torch.nn as nn
from apex.normalization import FusedLayerNorm
torch.backends.cudnn.benchmark = True
#!/usr/bin/env bash
set -e
if [[ $# -eq 0 ]]; then
echo "Illegal number of arguments. Usage: ${0} env_name_or_prefix [args]..."
exit 2
fi
name=$1