Skip to content

Instantly share code, notes, and snippets.

Avatar

Roger Stringer freekrai

View GitHub Profile
@freekrai
freekrai / multisite_functions.php
Created Jul 19, 2011
Some handy wordpress multisite functions
View multisite_functions.php
<?php
$posts = multisite_latest_post( array(
"how_many"=>10,
"how_long_days"=>30,
"how_many_words"=>50,
"more_text"=>"[...]",
"remove_html"=>true,
"sort_by"=>"post_date",
// if paginating:
"paginate"=>true,
View Absolute Position within Table Cells
// Plugin
$.fn.iWouldLikeToAbsolutelyPositionThingsInsideOfFrickingTableCellsPlease = function() {
var $el;
return this.each(function() {
$el = $(this);
var newDiv = $("<div />", {
"class": "innerWrapper",
"css" : {
"height" : $el.height(),
"width" : "100%",
@freekrai
freekrai / gist:1112482
Created Jul 28, 2011 — forked from chriscoyier/gist:945619
commentgraph.php
View gist:1112482
<?php
/*
Template Name: Comment Graph
*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
@freekrai
freekrai / gist:1149844
Created Aug 16, 2011
wordpress redirect on login based on roles
View gist:1149844
function fs_login($user, $pass) {
$uname = $user;
$pass1 = $pass;
$credentials = array(
'user_login' => $user,
'user_password' => $pass,
'remember' => true
);
$user = wp_signon($credentials, false);
if( $user->ID ){
View gist:1200929
/* ------------------------------------------------------------------------
* Class: prettyPhoto
* Use: Lightbox clone for jQuery
* Author: Stephane Caron (http://www.no-margin-for-errors.com)
* Version: 3.0.1
* ------------------------------------------------------------------------- */
(function($){$.prettyPhoto={version:'3.0'};$.fn.prettyPhoto=function(pp_settings){pp_settings=jQuery.extend({animation_speed:'fast',slideshow:false,autoplay_slideshow:false,opacity:0.80,show_title:true,allow_resize:true,default_width:500,default_height:344,counter_separator_label:'/',theme:'facebook',hideflash:false,wmode:'opaque',autoplay:true,modal:false,overlay_gallery:true,keyboard_shortcuts:true,changepicturecallback:function(){},callback:function(){},markup:'<div class="pp_pic_holder"> \
<div class="ppt">&nbsp;</div> \
<div class="pp_top"> \
@freekrai
freekrai / boyer-moore.php
Created Feb 24, 2012
Boyer-Moore string match algorithm
View boyer-moore.php
<?php
define('ALPHABET_SIZE',1);
function compute_prefix($str,$size,&$result=0)
{
$result = $result[$size + 1];
$q;
$k;
$result[0] = 0;
@freekrai
freekrai / Boyer-Moore-Horspool.php
Created Feb 24, 2012
Boyer-Moore-Horspool string matching algorithm
View Boyer-Moore-Horspool.php
<?php
define('UCHAR_MAX',255);
function boyermoore_horspool_memmem($haystack,$needle){
$hlen = strlen($haystack);
$nlen = strlen($needle);
$scan = 0;
$bad_char_skip[UCHAR_MAX + 1];
if ($nlen <= 0 || !$haystack || !$needle) { return NULL; }
for ($scan = 0; $scan <= UCHAR_MAX; $scan = $scan + 1)
$bad_char_skip[$scan] = $nlen;
@freekrai
freekrai / backbone.behaviour.js
Created Mar 9, 2012 — forked from Qard/backbone.behaviour.js
Behaviour abstraction system for backbone.js
View backbone.behaviour.js
!function (Backbone) {
// Store blank stuff here
var blankEl = $()
, blankModel = new Backbone.Model.extend()
, blankCollection = new Backbone.Collection.extend({
model: blankModel
})
, blankView = new Backbone.View.extend({
el: blankEl
})
View gist:2009751
<?php
define('LOCK_FILE', isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '/tmp/secondcrack-updater.pid');
// Ensure that no other instances are running
if (file_exists(LOCK_FILE) &&
($pid = intval(trim(file_get_contents(LOCK_FILE)))) &&
posix_kill($pid, 0)
) {
fwrite(STDERR, "Already running [pid $pid]\n");
exit(1);
View Config.php
<?php
// ----- Don't edit this -----------------
require_once(dirname(__FILE__) . '/engine/Updater.php');
// ---------------------------------------
// ----- You can edit these settings: -----
date_default_timezone_set('America/New_York'); // Sometimes I hate PHP. This is one of those times.