Skip to content

Instantly share code, notes, and snippets.

@skoppula
skoppula / export_resnet_onnx.py
Created November 6, 2018 22:09
Simple code to export PyTorch ResNet model as ONNX
import torch
import torch.backends.cudnn as cudnn
import torch.utils.data
import resnet
model_names = sorted(name for name in resnet.__dict__
if name.islower() and not name.startswith("__")
and name.startswith("resnet")
and callable(resnet.__dict__[name]))
@skoppula
skoppula / gist:93320039610b0d2d4332bb18ce70ff19
Last active October 13, 2017 05:29
resnet_error_example_with_tensorpack.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# File: cifar10-resnet.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import numpy as np
import argparse
import os
from tensorpack.models.common import layer_register, VariableHolder, rename_get_variable
@skoppula
skoppula / _hashset.py
Last active September 28, 2016 01:16
Adaptation of the libstdc++ unordered_set implementation
# "Internal policy header for TR1 unordered_set and unordered_map"
# A VERY approximate adaptation to Python by 6.006 staff. Original file at:
# https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01895.html
# If you want something tricky to gnaw on, take a look at the original C++ implementation
# Among other things, we stripped out code that does caching, error handling, and more.
# This library is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or any later version.
@skoppula
skoppula / hashset_sizing_policy.py
Last active October 3, 2016 03:30
Helper class to determine table resizing policy
// This file is was adapted from the GNU ISO C++ Library,
// by the 6.006 staff. If you're interested you can find a mirror
// of the original file at https://goo.gl/dgO3KR
// This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software
// Foundation; either version 3, or (at your option) any later
// version.
@skoppula
skoppula / analytics.py
Last active November 3, 2017 04:37
A short project to run analytics on emails on a couple mailing lists
import json
import string
import pytz
import operator
from datetime import datetime
from nltk.corpus import stopwords
from collections import defaultdict
def sort_dict(dictionary):
return sorted(dictionary.items(), key=operator.itemgetter(1), reverse=True)
@skoppula
skoppula / get_follower_ids.py
Last active November 3, 2017 04:27
Uncovering a Twitter handle using Twitter API
import sys
import json
import base64
import tweepy
import time
def is_valid_handle(handle):
#checks if given handle matches olivia handle specs
return True if re.compile("^[a-z]{10,}$").match(handle) else False
@skoppula
skoppula / crontab
Last active November 3, 2017 04:24
EmailBot: a script that queries for random noun/adjective, related image, and emails out the results every hour.
0 * * * * cd /homes/skoppula/random-image && python /homes/skoppula/random-image/random-image.py > /homes/skoppula/random-image/random-image.log 2>&1
@skoppula
skoppula / markdown-to-latex.sh
Created December 21, 2015 22:14
Mirror of Markdown/Latex integration from linguisticmystic.com
# Entirely from http://linguisticmystic.com/2015/03/04/how-to-write-a-dissertation-in-latex-using-markdown/
# Captures the date for later use
date=`date +"%m-%d-%y"`
# Archives a copy of the plaintext by date, leaving a trail of prior drafts outside Dropbox
cp ~/Dropbox/plaintext/prospectus.md ~/Documents/prospectus/build/backups/prospectus-$date.txt
# Run Pandoc to turn the markdown file with the bulk of the document into a .TeX file
@skoppula
skoppula / built-my-site.sh
Created December 21, 2015 20:58
Super simple homebrew templating script to convert HAML and SASS to a *.github.io ready static site.
#!/bin/bash
sass blog.scss blog.css
find posts/haml/ -name "*.haml" | while IFS= read -r pathname; do
haml_file="$pathname"
temp_path=${haml_file%".haml"}
html_path=${temp_path/haml/html}
echo "Compiling .haml of "${haml_file}
haml ${haml_file} ${html_path}
@skoppula
skoppula / cconvert-user-ids-to-screennames-filter.rb
Created August 1, 2015 09:45
Converts Twitter user IDs to screen names and filters based on a criteria
require 'twitter'
require 'json'
require 'time'
def is_valid_handle(handle)
handle =~ /^[a-z]{11,}$/ and handle.include?('e') ? true : false
end
def is_valid_user(user)
has_good_handle = is_valid_handle(user.screen_name)