Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
eddieantonio / mavenify.py
Created July 22, 2013 18:43
A useless Python script I used to collect JARs and WARs from a directory of Maven projects.
#!/usr/bin/env python
"""
Build all Maven files and dump all of the jars into a directory.
"""
import os
import sys
import re
@eddieantonio
eddieantonio / mahastats.py
Created July 29, 2013 01:26
From a comment near the bottom of the file: "I wanted to know if 'Awakening' was significantly different from the rest. It isn't. "
#!/usr/bin/env python
# Copyright 2013 Eddie Antonio Santos
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
import Data.List (sort)
-- Given a degree sequence, determines whether it is graphical. Returns a list
-- of steps from the base case to the original degree sequence.
graphical :: [Int] -> Maybe [[Int]]
graphical ds | even $ sum ds = graphical' ds []
-- By the handshaking lemma, cannot be a graph with odd sum:
| otherwise = Nothing
graphical' ds previous
@eddieantonio
eddieantonio / fabfile.py
Created September 28, 2013 01:06
Fabric: task to authorize your SSH key on a remote host.
"""
Installs your SSH key on other hosts. A fabfile for lazy people.
"""
from fabric.api import task, run, put, env, cd
# Use sh instead of bash.
env.shell = '/bin/sh -l -c'
@task
@eddieantonio
eddieantonio / install.sh
Last active January 26, 2016 08:53
marginalize.js: Intended to be a bookmarklet that gives unstyled pages margins and a somewhat more readable font.
#!/bin/sh
# If you have OS X and have UglifyJS installed, this uglifies Marginalize and
# puts the `javascript:` URL into the clipbord. Hoorah!
uglifyjs -c -m -o marginalize.min.js marginalize.js
printf 'javascript:' | cat - marginalize.min.js | pbcopy
#!/usr/bin/env python
from itertools import groupby
def k_sized_groups(sequence, k):
"""
Generates iterable groups with a maximum of size of K members from the
given sequence.
>>> [list(g) for g in k_sized_groups([1, 2, 3, 4], 2)]
@eddieantonio
eddieantonio / line_joiner.hs
Created November 25, 2013 16:59
Silly scripting language golf. Must read in a line of input, take out all of the spaces, and print it _immediately_ (so it can be sort of interactive).
#!/usr/bin/env runhaskell
import Data.List (intercalate)
joinLines input = unlines $ map joinLine (lines input)
where
joinLine line = intercalate "" (words line)
main = interact joinLines
# Maybe in Coffeescript
# Terminology from Haskell; API from Scala
# Inspired by https://gist.github.com/andyhd/1618403
just = (value) ->
# Applying the monad will act as "map" by default
# To make people even lazier, 'this' is bound to the value anyway.
monad = (f) -> just f.call(value, value)
monad.getOrElse = -> value
monad.getOr = -> value
@eddieantonio
eddieantonio / shingles.py
Last active August 29, 2015 13:56
Character-wise w-shingling, or at least as I understand it. http://en.wikipedia.org/wiki/W-shingling
#!/usr/bin/env python
from itertools import islice, izip, chain
# Returns a set of shingles for the given entity.
def shingles(entity, w=3):
"""
Performs charachter-wise shingling on an entity. Natural language
processing! Returns the (frozen) set of all shingles for a given entity.
@eddieantonio
eddieantonio / create_database.py
Created March 23, 2014 21:48
Creates some entities/relations that can be imported using mongoimport.
#!/usr/bin/env python
import yaml
import json
from bson.objectid import ObjectId
from itertools import count
def parse_database(database):