Skip to content

Instantly share code, notes, and snippets.

@zacstewart
zacstewart / classifier.py
Last active March 27, 2023 15:59
Document Classification with scikit-learn
import os
import numpy
from pandas import DataFrame
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline
from sklearn.cross_validation import KFold
from sklearn.metrics import confusion_matrix, f1_score
NEWLINE = '\n'
#lang racket
(define (sum-of-multiples-of a b n)
(define (iter acc n)
(if (= n 0)
acc
(iter
(+ acc (if (or (= (modulo n a) 0) (= (modulo n b) 0)) n 0))
(- n 1))))
@zacstewart
zacstewart / gist:4942036
Last active December 13, 2015 16:39
Wat?
2013-02-13T03:58:36+00:00 app[web.2]: ** [NewRelic][02/13/13 03:58:36 +0000 32135350-f34d-445d-9360-85e5ef0df147 (2)] ERROR : Error establishing connection with New Relic Service at collector.newrelic.com:80:
2013-02-13T03:58:36+00:00 app[web.2]: ArgumentError: wrong number of arguments (2 for 1)
2013-02-13T03:58:36+00:00 app[web.2]: /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/core_ext/object/to_json.rb:15:in `to_json'
2013-02-13T03:58:36+00:00 app[web.2]: /usr/local/lib/ruby/1.9.1/json/common.rb:212:in `generate'
2013-02-13T03:58:36+00:00 app[web.2]: /usr/local/lib/ruby/1.9.1/json/common.rb:212:in `generate'
2013-02-13T03:58:36+00:00 app[web.2]: /usr/local/lib/ruby/1.9.1/json/common.rb:336:in `dump'
2013-02-13T03:58:36+00:00 app[web.2]: /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.5.38/lib/new_relic/agent/new_relic_service.rb:348:in `dump'
2013-02-13T03:58:36+00:00 app[web.2]: /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.5.38/lib/new_relic/agent/new_re
@zacstewart
zacstewart / msttcorefonts-2.0-1.spec
Created January 7, 2013 18:00
msttcorefonts spec with updated SourceForge mirrors
# This is the msttcorefonts spec file as distributed from
# http://corefonts.sourceforge.net/.
%define name msttcorefonts
# nowdays most (all?) distributions seems to use this. Oh the joys of the FHS
%define ttmkfdir /usr/bin/ttmkfdir
%define fontdir /usr/share/fonts/%{name}
@zacstewart
zacstewart / 1-minecraft_account_verifier.rb
Last active December 10, 2015 02:48
These two classes are the two strategies I went about to verify Minecraft accounts for Civtrade http://civtrade.herokuapp.com.
class MinecraftAccountVerifier
require 'net/http'
require 'uri'
AUTH_URI = URI.parse('https://login.minecraft.net/').freeze
CLIENT_VERSION = 13
attr_reader :error
# Public: verify an account as a true Minecraft account this user has access to.

Breaking table–model–controller symmetry

A while ago I hit a lull in my skill advancement as a Rails developer. I had long since learned to think of my resources as resources. I did my best to limit my controller actions the basic CRUD methods. I considered the "fat model, skinny controller" mantra to be sacrosanct. But I was still often finding myself going way out of my way to implement otherwise mundane features, for example sending mail after saving an object or adding a routine accept/reject to something.

@zacstewart
zacstewart / zacstewart.pub.gpg
Last active October 13, 2015 11:38
My GnuPG Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.15 (Darwin)
mQINBFC7ikIBEAC/ps60Orp8iuX2CH3JD/VfjqPVVlqWBh40aa9dayMKTHRCHXLC
hTttTcHKeCsLnvmIHqxCxNBJu18kgX6Vvrc2xFO8KHldFxpQOX2oCVVOrDm7Sfc/
eRk61Ey0KCGQca3gNjlYzWOvtYhvL0yMyA/VLQcBdgm5vlkDFaBzvbRmhUZx2sZ1
nzhW7dyTbGOf6TD101MS3otrVxy3Tx4cm5lBdMxvNwutgqtGy75AElzOHg9zZ6kk
4ZF2Ll76wHSQOgrLShIEu2ymQLoS+VwpZeA4ab4FoP1CqxQd3GYPa5dhe6EakDf8
XH+x3CncV/cO2gDIwqE/lZv2yq004yrHAO4bhia8ndTJboNIQvwJICjJy5WIgU4s
MXs5YUZv8su4T1f95+xSSjEjfI6X2zA4WnekzCLUFfGHkr+KMOKUHRQIRVHOwP/X
@zacstewart
zacstewart / anonymous_user.rb
Created October 2, 2012 17:35
Rails Soft Sign-Up
class AnonymousUser < User
attr_accessible *ACCESSIBLE_ATTRS, :type, :token, as: :registrant
def register(params)
params = params.merge(type: 'User', token: nil)
self.update_attributes(params, as: :registrant)
end
end
@zacstewart
zacstewart / breakfast.md
Created August 9, 2012 20:35
Cherri's breakfast shake recipe
  • ice cream
  • 1/2 cup milk
  • 2 tbsp Ovaltine
  • 1-2 tbsp peanut butter
  • 1-2 raw eggs
  • 1 banana
@zacstewart
zacstewart / clean_users.sh
Created July 21, 2012 22:00
EMI Music Data Science Hackathon data cleaning scripts
#!/usr/bin/env sh
# This transforms the 13 answers to the WORKING column
# into integers 0-12, 5 answers to MUSIC into 0-4,
# normailizes LIST_OWN, and LIST_BACK into integer values
# and drops rows with variations of "16+ hours"
# (loses 2.623031698% of the data)
INFILE=$1
sed -e "
s/\"Employed 30+ hours a week\"/0/g;
s/\"Employed 8-29 hours per week\"/1/g;