Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benfulton
benfulton / Mastodon2HTML.py
Created December 31, 2024 13:49
Code to read several Mastodon accounts and write the posts out in HTML
from bs4 import BeautifulSoup
from link_preview import link_preview
import pickle
import requests
import socket
from html import escape
from datetime import datetime
import os
from collections import defaultdict
@benfulton
benfulton / read_tree.cpp
Created January 26, 2022 22:11
Reverse engineering the R APE package tree reader, to determine how the nodes are numbered
/* tree_build.c 2020-02-12 */
/* Copyright 2008-2020 Emmanuel Paradis, 2017 Klaus Schliep */
/* This file is part of the R-package `ape'. */
/* See the file ../COPYING for licensing issues. */
//#include <R.h>
//#include <Rinternals.h>
#include <cmath>
@benfulton
benfulton / newick_stretch.py
Created February 4, 2020 20:46
Extend the leaf branch lengths of a Newick tree so all the paths are the same length
from Bio import Phylo
from io import StringIO
import sys
treedata = sys.argv[1]
handle = StringIO(treedata)
tree = Phylo.read(handle, "newick")
out = StringIO()
@benfulton
benfulton / msp.py
Last active August 29, 2015 14:09
Screen scraper to summarize grades for MyStudentsProgress
import requests
from lxml import html
courseids=[62454,62508,62446,62557,62448,62513,62549,62511,62451,62558,62477]
# music 62531,
def grade(r):
try:
return float(r[2][0])/float(r[2][1])
except ValueError:
@benfulton
benfulton / slim-init.py
Created July 7, 2014 03:20
Launch the WaferSlim SLIM server from a source directory
import sys
sys.path.append("/path/to/GIT/waferslim/src")
import waferslim.server
import logging
#sys.argv = ['programname', '-iq', '-q', directory]
def start_server():
# This script reads a GIT directory and prints out the contents
# appropriately to be incorporated into a Google Visualization Treemap
# https://code.google.com/apis/ajax/playground/?type=visualization#tree_map
import os
rootdir = "E:\\Git"
result = {}
for path, dirs, files in os.walk(rootdir):
key = os.path.basename(path)
@benfulton
benfulton / host_updater.py
Created January 16, 2014 04:16
Copy registered machines from a LinkSys router to a hosts file, by scraping a router web page
import urllib2
import base64
import re
request = urllib2.Request("http://192.168.1.1/DHCPTable.asp")
base64string = base64.encodestring('%s:%s' % (USER, PASSWORD)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
lines = (re.findall(r"'(.*?)'", x, re.DOTALL) for x in urllib2.urlopen(request) if 'new AAA' in x)
q = dict((vv[0], vv[1]) for vv in lines if vv)
@benfulton
benfulton / WMPSongs.rb
Created July 17, 2012 00:30
Reading Windows Media Player songs in Ruby
require 'win32ole'
class MediaPlayer
def initialize
@player = WIN32OLE.new('WMPlayer.OCX')
end
def songs
s = @player.mediacollection.getByAttribute("MediaType","Audio")
@benfulton
benfulton / RavenHQ.rb
Created June 7, 2012 03:12
Connecting to RavenHQ in Ruby
require 'httparty'
response = HTTParty.get('https://1.ravenhq.com/docs')
response = HTTParty.get(response.headers['oauth-source'], :headers => { "Api-Key" => ApiKey })
auth = "Bearer " + response.body
response = HTTParty.get('https://1.ravenhq.com/databases/benfulton-SourcedTriples/docs/?start=0&pageSize=10', :headers => { "Authorization" => auth })
puts response.body, response.code, response.message, response.headers.inspect