Skip to content

Instantly share code, notes, and snippets.

@rmarscher
rmarscher / Facebook Linter Errors
Created March 21, 2011 20:10
PHP function that automates detecting if an open graph page has errors
/**
* Function to automate detecting if an open graph page has errors
* Requires the dom php extension to be enabled
*
* @param string $url
* @return array with keys 'hasError', 'errorType', and 'errorMessage'
*/
function facebookLinterErrors($url)
{
$errorType = "";
@rmarscher
rmarscher / gist:1279494
Created October 11, 2011 21:24
li3_mustache as default media renderer
// in one of your bootstrap files... possibly config/bootstrap/media.php
use lithium\net\http\Media;
Media::type('default', null, array(
'view' => 'lithium\template\View',
'loader' => 'Mustache',
'renderer' => 'Mustache',
'paths' => array(
'template' => '{:library}/views/{:controller}/{:template}.{:type}',
@rmarscher
rmarscher / indent-textarea-selection-min.js
Created February 22, 2012 18:24
Bookmarklet for Markdown Code Indenting
(function(){var a=document.activeElement,b=document.getSelection().toString(),c="",d=b.split("\n");indent=" ",i=0,total=d.length;if(b==""){return}for(i=0;i<total;i++){c+=indent+d[i]+"\n"}a.value=a.value.split(b).join(c)}())
@rmarscher
rmarscher / MongoLogger.php
Created May 8, 2012 02:14
app\analysis\MongoLogger
<?php
namespace app\analysis;
use lithium\action\Request;
use lithium\console\Request as ConsoleRequest;
use lithium\core\Environment;
use lithium\data\Connections;
use lithium\util\String;
use MongoDate;
@rmarscher
rmarscher / session.php
Created May 30, 2012 23:18
Lithium session config for operating on only one configuration by default
<?php
use lithium\storage\Session;
$methods = array('read', 'write', 'delete', 'clear', 'check');
foreach ($methods as $method) {
$filter = function($self, $params, $chain) use ($method) {
if ($params['options']['name'] === null) {
if ($params['configuration'] !== 'default') {
// dump("returning false for {$params['configuration']} for {$method}");
@rmarscher
rmarscher / uglify-watch.js
Created June 23, 2012 14:59 — forked from makeusabrew/1) uglify.js
Watch a specified directory's JavaScript files and recompile a specified output file if any changes are detected
/**
* Sample usage - note that the trailing slash on the watch directory is important!
*
* node uglify.js /path/to/my/src/directory/ /path/to/my/output/file.js
*/
var jsp = require('uglify-js').parser,
pro = require('uglify-js').uglify,
fs = require('fs');
@rmarscher
rmarscher / errors.php
Created August 24, 2012 03:58
li3 airbrake in errors bootstrap
<?php
use lithium\action\Response;
use lithium\core\Environment;
use lithium\core\ErrorHandler;
use lithium\core\Libraries;
use lithium\console\Response as ConsoleResponse;
use lithium\net\http\Media;
use lithium\analysis\Logger;
use lithium\net\http\Service;
@rmarscher
rmarscher / MongoLogger.php
Created October 8, 2012 05:24
MongoDB logging in Lithium PHP
<?php
namespace li3_common\analysis;
use lithium\action\Request;
use lithium\console\Request as ConsoleRequest;
use lithium\core\Environment;
use lithium\data\Connections;
use lithium\util\String;
use MongoDate;
@rmarscher
rmarscher / DownloadsController.php
Created October 14, 2013 04:38
Lithium PHP framework CSV media handler - blacklists data not intended for export. See StackOverflow question "How do you remove specific fields from all entities of a record set in Lithium?": http://stackoverflow.com/questions/17189664/how-do-you-remove-specific-fields-from-all-entities-of-a-record-set-in-lithium/17202455
<?php
namespace app\controllers;
use app\models\Downloads;
class DownloadsController extends \lithium\action\Controller {
public function index() {
$this->request->privateKeys = array('id', 'user_id');
@rmarscher
rmarscher / index.js
Created October 18, 2013 17:17
Invoke a shotgun.js shell from command-line without opening prompt. Put these files in a directory, run npm install, then run `node . help` to see it work.
var readline = require('readline'),
shotgun = require('shotgun'),
shell = new shotgun.Shell(),
context = {}; // Declare empty context object.
// Create interface that reads from console and outputs to console.
var rl = readline.createInterface(process.stdin, process.stdout);
// Configure shotgun.
shell