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 | |
// requires PHP >= 5.3.6 to support saveHTML([$node]) | |
function getPostPreview($html, $num_chars) { | |
if(strlen($html) <= $num_chars) $preview = $html; | |
else { | |
$preview = ''; | |
$dom = $DOMDocument::loadHTML($html); // creates DOCTYPE, <html>, and <body> | |
$dom->removeChild($dom->firstChild); // DOCTYPE | |
/* | |
* If your post is wrapped by a parent element with an id: |
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 | |
// rawurlencode() percent-encodes ~ as %7E | |
$RFC3986_encoded_string = str_replace('%7E','~',rawurlencode($some_string)); | |
?> |
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 | |
$signature = base64_encode(hash_hmac('sha256',$string_to_sign,{AWS_ACCESS_KEY},true)); | |
// encode any plus (+), equal (=), or other reserved characters in $signature | |
$signature = str_replace('%7E','~',rawurlencode($signature)); | |
?> |
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
// Example of using JavaScript Promises with Backbone.sync | |
// instead of the usual success()/error() callbacks. | |
// | |
// This is a totally contrived example but does demonstrate | |
// using promises when syncing your Backbone models and collections. | |
var Model = Backbone.Model.extend({ | |
// Some model used outside of a collection. | |
urlRoot: '/models' | |
}), |
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
# Move to a location where you don't mind storing the couchdb install files. | |
cd /some/path/to/install/couchdb | |
# become root | |
su - | |
# Enable EPEL and REMI repositories for installing couchdb deps. | |
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm | |
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm | |
rpm -Uvh remi-release-6.rpm epel-release-6-8.noarch.rpm |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Simple CSS3 Ribbon Example</title> | |
<style> | |
/* | |
The idea is to use CSS3 generated content of the <h1> elements | |
::before and ::after pseudo-elements. However, the actual content | |
of the pseudo-elements will be empty, and appropriate declarations | |
on the border properties will do most of the work of creating the |
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
// JSONP is required since gists.github.com doesn't support CORS. | |
// Note that it returns a Promise. | |
function fetch(gistid) { | |
return new Promise(function(resolve, reject) { | |
$.ajax('https://gist.github.com/' + gistid + '.json', { | |
dataType: 'jsonp', | |
cache: true | |
}).done(function(gist, status, jqXhr) { | |
// You can modify the gist before resolving. |
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
/* | |
* Embeds Gists into specified DOM elements after fetching them. | |
* Assumes Gists are to be embedded into elements with an HTML5 data-* attribute, | |
* with a value equal to a public Gist id. | |
* | |
* @param {String:dataAttrName} The data attribute name value. | |
* For example <code data-gistId='12345'></code> means the dataAttrName === "gistId". | |
*/ | |
function embedGists(dataAttrName) { | |
var dataAttr = "data-" + dataAttrName; |
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
/* | |
* Note that this module assumes support for | |
* MutationObservers and Promises. | |
* A polyfill for Promises is most likely needed. | |
*/ | |
define(['jquery'], function($) { | |
var Gister = { | |
fetch: function(gistid) { | |
// Promise returning JSONP method to fetch Gists. |
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
/* | |
* View that listens for changes to a Post model before rendering | |
* a view for the post content. Employs Gister module to embed | |
* Gists after rendering. | |
*/ | |
define([ | |
'jquery', | |
'backbone', | |
'gister', | |
'mustache', |
OlderNewer