Skip to content

Instantly share code, notes, and snippets.

View mmccollow's full-sized avatar

Matt McCollow mmccollow

  • McMaster University
  • Hamilton, Ontario
View GitHub Profile
@mmccollow
mmccollow / write.asm
Created August 4, 2016 19:30
Assembly exercise - write "Hello world" to a new file called "test"
SECTION .data
msg db "Hello world"
len equ $ - msg
fname db "test", 0
SECTION .text
global _start
_start:
mov rdi, fname ;param1 to open(), file name
mov rsi, 101 ;param2 to open(), file mode
@mmccollow
mmccollow / bloom.py
Created August 27, 2014 20:24
Simple Bloom Filter Implementation
# Implementation of a simple Bloom Filter
# @author Matt McCollow <mmccollow@gmail.com>
import hashlib
class Filter():
def __init__(self, debug=False):
self.bits = 0x0
self.mask = 0xFFFF
@mmccollow
mmccollow / extractFits.php
Created August 3, 2012 20:23
extractFits function
<?php
function extractFits($parameterArray, $dsid, $file, $file_ext) {
$file_name = $file .'_'. $dsid .'.xml';
$output = array();
exec('fits.sh -i '. escapeshellarg($file) .'', $output);
if ( !file_put_contents($file_name, implode("\n", $output)) ) {
exit("Error writing file: ". $file_name);
}
$_SESSION['fedora_ingest_files']["$dsid"] = $file_name;
@mmccollow
mmccollow / gist:1895144
Created February 23, 2012 21:26
unicode
[...]
map_label = mods_tree.xpath("*[local-name() = 'titleInfo']/*[local-name() = 'title']/text()")
map_label = unicode(map_label[0].strip("\t\n\r"), encoding='utf-8')
[...]
map_pid = fedora.getNextPID(name_space)
map_object = fedora.createObject(map_pid, label = map_label.encode('utf-8'))
----------
Traceback (most recent call last):
@mmccollow
mmccollow / gist:1755209
Created February 6, 2012 21:58
Dublin Core output from Apache Xalan
<?xml version="1.0" encoding="UTF-8"?><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:srw_dc="info:srw/schema/1/dc-schema" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>
Aosta, Italy - 1:250,000 topographical map
</dc:title>
<dc:contributor>Great Britain. War Office. General Staff. Geographical Section. (creator)</dc:contributor>
<dc:publisher>
London: War Office
</dc:publisher>
<dc:language>eng</dc:language>
@mmccollow
mmccollow / gist:1727195
Created February 3, 2012 02:04
Reddit historical lexical diversity
import urllib2
import HTMLParser
from BeautifulSoup import BeautifulSoup
import time
def _fetch_page(url):
try:
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)
except urllib2.URLError:
@mmccollow
mmccollow / funcs.py
Created January 31, 2012 22:10
Junk for Ch.1 examples from "Mining The Social Web"
import twitter
import networkx as nx
import re
g = nx.DiGraph()
def get_tweets():
twitter_search = twitter.Twitter(domain="search.twitter.com")
search_results = []
for page in range(1,6):
@mmccollow
mmccollow / pascal.erl
Created May 19, 2011 20:16
Generates a Pascal's Triangle
-module(pascal).
-export([triangle/1]).
% Generates a Pascal's Triangle
% 1. Start Erlang interpreter in folder with this file
% 2. Do: c(pascal).
% 3. Do: pascal:triangle(5).
% Which would create a Pascal's Triangle 5 lines deep.
% calculate factorial
@mmccollow
mmccollow / sicp_ex1-8.scm
Created April 1, 2011 00:30
My solution to exercise 1.8 from Structure and Interpretation of Computer Programs
#lang scheme
(define (cube-root x)
(define (approx guess x)
(if (good-enough? guess x)
guess
(approx (improve guess x) x)))
(define (improve guess x)
(/ (+ (/ x (square guess)) (* 2 guess)) 3))
(define (good-enough? guess x)
(< (abs (- (cube guess) x)) 0.001))
<?php
/**
* json_encode() only takes an $option argument in PHP 5.3.0+
* We need the FORCE_JSON_OBJECT option, so we'll roll our
* own json_encode() on PHP < 5.3.0
* @author Matt McCollow <mmccollow@gmail.com>
*/
if(!defined('JSON_FORCE_OBJECT')) {