Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
hacking the mainframe

Mark Watson markwatson

💻
hacking the mainframe
View GitHub Profile
@markwatson
markwatson / Template.php
Created Dec 12, 2008
Codeignitor full page templates.
View Template.php
<?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
*
View error logging function
<?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));
}
View gist:47168
<?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()
View News Parser
<?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.
View gist:159782
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();
View gist:572149
#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 Mar 2, 2011
Not finished just saving it here...
View AdjacencyMatrix
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
View Dmoz.py
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()
View gist:951307
def super_split(string, delim):
segment = ''
for c in string:
if c in delim:
yield segment
segment = ''
else:
segment += c
yield segment
View lagrange.py
# 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