Skip to content

Instantly share code, notes, and snippets.

View markwatson's full-sized avatar
💻
hacking the mainframe

Mark Watson markwatson

💻
hacking the mainframe
View GitHub Profile
@markwatson
markwatson / Template.php
Created December 12, 2008 09:59
Codeignitor full page templates.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
ob_start();
/**
* Template Library
*
* @package Template
* @category Libraries
* @author Mark Watson
* @link http://markedup.org
*
<?php
// error logging function that saves arrays, objects - anything.
// easier to type then always typing "error_log(print_r($var,1));
function e($var, $mess=null)
{
error_log($mess.': '.print_r($var,1));
}
<?php
/**
* The global model! All hail potentate MY_Controller!
* It provides some great default queries...
*/
class MY_Model extends Model
{
var $default_table;
function get_all()
<?php
/**
* Intelligent News Parser Library
*
* @package Parse_news
* @category Libraries
* @author Mark Watson
* @link http://markwatson.us
*
* A simple library that parses the html from news articles to pull out metadata.
The first is to use the object oriented way:
$config = array(
           'indent'         => true,
           'output-xml'   => true,
           'wrap'           => 200);
// Tidy
$tidy = new tidy;
$tidy->parseString($xml, $config, 'utf8');
$tidy->cleanRepair();
@markwatson
markwatson / gist:572149
Created September 9, 2010 16:46
ceiling function
#include <stdio.h>
double my_ceil(double x) {
double y = (double) ((long long) x);
if (x - y == 0) {
return x;
} else {
if (x > 0) {
return y + 1;
} else {
@markwatson
markwatson / AdjacencyMatrix
Created March 2, 2011 04:32
Not finished just saving it here...
class AdjacencyMatrix[T: Manifest](size: Int) {
// initialize it
// (It's in column vector format)
val matrix = Array.ofDim[T](size, size)
// helper functions
// takes a list of 3-tuples in the form: (from, to, weight)
def setConnections(connections: List[(Int, Int, T)]) = {
for (x <- connections) {
// make matrix[to][from] = weight
import mechanize
from BeautifulSoup import BeautifulSoup
class Dmoz(object):
def __init__(self):
self.br = mechanize.Browser()
def get_page_urls(self, term):
result = self.br.open("http://www.dmoz.org/search?q="+term)
result_html = result.read()
def super_split(string, delim):
segment = ''
for c in string:
if c in delim:
yield segment
segment = ''
else:
segment += c
yield segment
# Tested on Windows 7 and Python 2.7
# the code
def lagrangian_interpolate(samples):
"""
Takes some samples as a list of tuples and returns a function that's
a lagrangian interpolation of all the samples.
"""
X = 0 # the tuple index of the X variable in the samples
Y = 1 # the tuple index of the Y variable in the samples