View csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import unittest | |
class CsvReader(object): | |
""" | |
Reads CSV files while handling all types of edge cases. | |
""" | |
def __init__(self, lines): | |
""" | |
A new CSV reader with the given lines. |
View countCSSRules.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countCSSRules() { | |
var results = '', | |
log = ''; | |
if (!document.styleSheets) { | |
return; | |
} | |
for (var i = 0; i < document.styleSheets.length; i++) { | |
countSheet(document.styleSheets[i]); | |
} | |
function countSheet(sheet) { |
View createEl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createEl = function(type, props, children) { | |
var el = document.createElement(type); | |
if (props) { | |
for (var key in props) { | |
if (props.hasOwnProperty(key)) { | |
if (key == "css") { | |
if (props[key].length > 0) { | |
el.style.cssText = props[key].join(';') + ";"; | |
} | |
} else { |
View onChange.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.mwOnChange = function(callback, timeout) { | |
return $(this).each(function() { | |
if (timeout === undefined) { | |
timeout = 500; | |
} | |
var eventNames = 'keydown paste input'; | |
var timeoutId = null; | |
$(this).on(eventNames, function(e) { | |
var self = this; |
View Template.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 { |
OlderNewer