Skip to content

Instantly share code, notes, and snippets.

View markrickert's full-sized avatar

Mark Rickert markrickert

View GitHub Profile
@markrickert
markrickert / gist:1752759
Created February 6, 2012 15:45
Scraping nonstandard data from HTML using phpQuery
<?php
//Create new instance of phpQuery with the poorly formatted HTML string
phpQuery::newDocument($document_html_string);
$my_data = array(); //Init array for holding the records
foreach(pq("#main table tr") as $block) {
//Get the key/value by selecting the table header element.
//We namespace it to the current block so we don't
// get _all_ the page's TH elements.
$key = pq('th', $block)->text();
@markrickert
markrickert / gist:1752657
Created February 6, 2012 15:26
phpQuery Example
<?php
//Get the HTML string from cURL
//Create new instance of phpQuery
//We assume the phpoQuery library is included at the top or your script.
phpQuery::newDocument($document_html_string);
$inputs = array(); //Create an empty array to hold the inputs.
//Get all the inputs on the page and put them in an array.
foreach(pq(':input') as $id => $block) {
@markrickert
markrickert / AppDelegate.m
Created December 21, 2011 20:58
Create NSDictionary based on a URL structure with keys and values
/*
* Example implementation
*/
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"Launched with URL: %@", url.absoluteString);
NSDictionary *userDict = [self urlPathToDictionary:url.absoluteString];
@markrickert
markrickert / NodeHate1.js
Created September 14, 2011 15:08
Node Hate
require.paths.unshift(
__dirname + '/codejam/support/express/support/connect/lib/'
, __dirname + '/codejam/support/express/support/jade/lib/'
, __dirname + '/codejam/support/'
)
var express = require("express")
@markrickert
markrickert / jQuerySmoothAnimations.js
Created September 14, 2011 15:03
Smoother Animations with jQuery
//Basic Usage:
$().framerate()
//Usage w/options:
$().framerate({framerate: 24, logframes: true})
@markrickert
markrickert / Highlander.js
Created September 14, 2011 15:01
There Can Be Only One...
function there_can_be_only_one_highlander(the_one) {
var state_speed = 500,
immortals = ['#welcome-box', '#guest-box', '#login-box', '#register-box'],
to_kill = [],
key = null;
for (key in immortals) {
if (immortals[key] !== the_one) {
if (typeof immortals[key] === 'string') {
to_kill.push(immortals[key]);
@markrickert
markrickert / MigrateWordpress.sql
Created September 14, 2011 15:00
Wordpress Migration SQL Script
#Update the crucial options
UPDATE wp_options
SET option_value = 'http://newdomain.com'
WHERE option_name in ('siteurl', 'home');
#Make sure search engines can access the deployed site
UPDATE wp_options
SET option_value = 1
WHERE option_name = 'blog_public';
#Set the GUIDs to have the correct domain
UPDATE wp_posts
@markrickert
markrickert / ZendCleanURL.php
Created September 14, 2011 14:56
Clean URL Generator for Zend
<?php
/**
* Generates a uristub of maximum specified length.
*
* @access protected
* @param string $tableName The name of the table to query
* @param string $tableField The table column to check
* @param string $uristub The initial input string (page title) to clean
* @param int $length The maximum allowable length for the clean url
* @param mixed $iteration The current iteration, when duplicates found
@markrickert
markrickert / StateDropdownAutocomplete.js
Created September 14, 2011 14:53
State Dropdown With Autocompletion
$(function() {
// for storing states
var states = [];
// cache some elems
var $states = $('#state');
var $stateList = $('#state-list');
// hide the dropdown and pull values
$states.hide().find('option').each(function() {
@markrickert
markrickert / SafeZendTransactionsMysql.php
Created September 14, 2011 14:49
Safely Handling Mysql Transactions in Zend
<?php
// the below code assumes you have the private/protected
// variable $this->_db set to your database adapter.
// begin the transaction
$this->_db->beginTransaction();
try {
// mock insert into a user table
$result = $this->_db->insert('users', array(