Skip to content

Instantly share code, notes, and snippets.

Eddie Antonio Santos eddieantonio

View GitHub Profile
@eddieantonio
eddieantonio / mavenify.py
Created Jul 22, 2013
A useless Python script I used to collect JARs and WARs from a directory of Maven projects.
View mavenify.py
#!/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 Jul 29, 2013
From a comment near the bottom of the file: "I wanted to know if 'Awakening' was significantly different from the rest. It isn't. "
View mahastats.py
#!/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
#
View graphical.hs
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 Sep 28, 2013
Fabric: task to authorize your SSH key on a remote host.
View fabfile.py
"""
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 Jan 26, 2016
marginalize.js: Intended to be a bookmarklet that gives unstyled pages margins and a somewhat more readable font.
View install.sh
#!/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
View k_sized_groups.py
#!/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 Nov 25, 2013
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).
View line_joiner.hs
#!/usr/bin/env runhaskell
import Data.List (intercalate)
joinLines input = unlines $ map joinLine (lines input)
where
joinLine line = intercalate "" (words line)
main = interact joinLines
View maybe.coffee
# 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 Aug 29, 2015
Character-wise w-shingling, or at least as I understand it. http://en.wikipedia.org/wiki/W-shingling
View shingles.py
#!/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 Mar 23, 2014
Creates some entities/relations that can be imported using mongoimport.
View create_database.py
#!/usr/bin/env python
import yaml
import json
from bson.objectid import ObjectId
from itertools import count
def parse_database(database):
You can’t perform that action at this time.