Skip to content

Instantly share code, notes, and snippets.

View ringmaster's full-sized avatar

Owen Winkler ringmaster

View GitHub Profile
@ringmaster
ringmaster / gist:4012795
Created November 4, 2012 18:00
Even vs Odd Routes with different names?
/**
* Only accept even arguments in the URL
*/
$app->route('even', new Regex('#^/number/(?P<number>[0-9]+)/?$#'), function(){
echo "The number was even.";
})->validate(function($request) { return $request['number'] % 2 == 0;});
/**
* Only accept odd arguments in the URL
*/
// Run this on http://elections.nytimes.com/2012/results/president/big-board
$('.bucket tbody').each(function(){
var bucket = $(this);
var sum = 0, dem = 0, rep = 0, ct = 0, report = 0;
bucket.find('tr').each(function(){
if($(this).find('.ev-cell').length > 0) {
ct++;
var ev = parseInt($(this).find('.ev-cell').text());
dempct = parseInt($(this).find('.nytint-pct-dem').text());
reppct = parseInt($(this).find('.nytint-pct-rep').text());
@ringmaster
ringmaster / feed_functions.php
Created December 21, 2012 14:57
In feed_functions.php
if($userSchools[0]){
$school_ids = array();
foreach($userSchools as $school) {
$school_ids[$school['school_id']] = $school['school_id'];
}
$school_ids = array_filter($school_ids);
if(count($school_ids) > 0) {
$schools = "school_id IN (";
$schools .= implode(',', $school_ids);
@ringmaster
ringmaster / Dead Pool
Created January 16, 2013 00:55
Here's a sample query to find people for my dead pool using SPARQL and the dbpedia.
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?name ?birth ?death ?person ?wikipedia ?occupation WHERE {
?person dbo:birthDate ?birth .
?person foaf:name ?name .
?person a dbo:Actor .
OPTIONAL {?person dbo:deathDate ?death .}
OPTIONAL {?person dbpprop:dateOfDeath ?death2 .}
FILTER (?birth < "1950-01-01"^^xsd:date)
FILTER (?birth > "1890-01-01"^^xsd:date)
SELECT
DISTINCT
{posts}.id AS id,
{posts}.slug AS slug,
{posts}.title AS title,
{posts}.guid AS guid,
{posts}.content AS content,
{posts}.cached_content AS cached_content,
{posts}.input_formats AS input_formats,
{posts}.user_id AS user_id,
@ringmaster
ringmaster / gist:4626783
Created January 24, 2013 19:31
My Habari config file for 0.10
<?php
namespace Habari;
if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); }
Config::set( 'db_connection', array(
'connection_string'=>'sqlite:habari.db',
'username'=>'',
'password'=>'',
'prefix'=>''
));
@ringmaster
ringmaster / gist:4674751
Created January 30, 2013 17:09
Add this to your style.css file at the end.
#menu{*zoom:1;zoom:1;border-bottom:1px solid #eaeaea;}#menu:before,#menu:after{content:"";display:table;}
#menu:after{clear:both;}
#menu:before,#menu:after{display:table;content:"";zoom:1;}
#menu:after{clear:both;}
#menu ol{list-style:none;margin-left:0;padding-left:0;}
#menu ol li{display:inline;float:left;line-height:24px;}
#menu ol li:hover{background:#582E91;}
#menu ol li:active>div>a{background-color:#582E91;font-weight:bold;}
#menu ol li ol{position:absolute;background:#582E91;z-index: 30;}
#menu ol li ol div{margin-top:10px;}
@ringmaster
ringmaster / gist:4693169
Last active December 12, 2015 01:39
My global git aliases
alias.st=status
alias.ci=commit
alias.br=branch
alias.co=checkout
alias.df=diff
alias.dc=diff --cached
alias.lol=log --graph --decorate --pretty=oneline --abbrev-commit
alias.lola=log --graph --decorate --pretty=oneline --abbrev-commit --all
alias.ls=ls-files
alias.ign=ls-files -o -i --exclude-standard
1. Create a file at the webroot called whoami.php
2. Put this code in the whoami.php file and save it:
<?php echo `whoami`; ?>
3. Access whoami.php via the browswer to see who the user is that your web server runs as.
4. In the console, type this where {user} is the user from the whoami.php:
groups {user}
5. Observe the groups that the user belongs to. Usually it's just one. Usually it's "www-data"
6. cd to your WordPress directory
7. Run this command, change {user} to the user shown on the whoami.php page and {group} to the group from step 5 that looks like your server's group:
chown -R {user}:{group} wp-content
@ringmaster
ringmaster / config.php
Last active December 12, 2015 12:19
Host many Habaris from one directory, store configurations in a database
<?php if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); }
/** User-settable stuff */
define('DEBUG', false);
define('SITEDATA_GUID', 'a random string'); // this is used for site guid for the cache and salt on the cache keys
Config::set('cache_class', 'APCCache'); // This should work with any Habari cache class that can run, including filecache
$cache_enabled = true;
/** Don't change the below */