Skip to content

Instantly share code, notes, and snippets.

View matb33's full-sized avatar

Mathieu Bouchard matb33

View GitHub Profile
@matb33
matb33 / DOMDocumentExtended.php
Last active May 23, 2020 21:26
DOMDocument->saveJSON()
<?php
// saveJSON: XML to JSON conversion/transformation
// The saveJSON method is implemented as a method of the example DOMDocumentExtended class, which
// extends DOMDocument. It will transform the currently loaded DOM into JSON using XSLT. Since
// there isn't a reliable automatic way of detecting if certain siblings nodes should be
// represented as arrays or not, a "forceArray" parameter can be passed to the saveJSON method.
// It should be noted that the forceArray functionality doesn't recognize namespaces. This is
// an easy enough fix, I just didn't need it at the time of writing (look for local-name() and
@matb33
matb33 / gist:1229317
Created September 20, 2011 14:57
Inline variable parsing function with multibyte support
<?php
// parseInlineVariables takes a multibyte string "stringToParse" and parses for $variable style
// variables to swap with the value found in the "variables" associative array. It also supports
// better matching with curly braces surrounding the variable, such as {$variable}. Spaces
// within the curly braces are OK: { $variable } works too.
// Adapt this function to your particular framework (put it in a class, keep it global, etc)
function parseInlineVariables( $stringToParse, Array $variables )
{
@matb33
matb33 / publishCursor.js
Created October 4, 2012 15:08
Alternate _publishCursor for Meteor
// Meteor extension to allow modifications to documents when publishing.
// Also allows specifying an alternate name under which to publish the
// collection, using "sub_name".
_.extend(Meteor._LivedataSubscription.prototype, {
_publishCursor: function (cursor, name) {
var self = this;
var collection = name || cursor.sub_name || cursor.collection_name;
var map_callback = cursor.map_callback || function (obj) { return obj; };
@matb33
matb33 / stuff.html
Created February 14, 2013 15:25
Example of X new things in Meteor, leveraging local collection
<template name="stuff">
<button name="show">Show {{newThingsCount}} new things</button>
<ul>
{{#each things}}
<li>{{title}}</li>
{{/each}}
</ul>
</template>
@matb33
matb33 / README
Last active October 20, 2016 08:28
WordPress plugin that protects resume uploads for the Job Manager plugin (http://pento.net/projects/wordpress-job-manager-plugin/)
Create this folder:
/wp-content/plugins/job-manager-private-uploads/
Put the two PHP files in there, then activate this plugin via the WordPress admin.
NOTE: your WordPress installation should be configured to allow WP_Rewrite to make modifications to the .htaccess file.
@matb33
matb33 / collection-hooks.js
Last active December 15, 2015 12:09
Collection hooks for Meteor: allows you to run callbacks before and after any insert/update/remove to collections. Works across both server and client. Drop this file into a shared folder, for example: `/lib/external/collection-hooks.js`
MOVED: https://github.com/matb33/meteor-collection-hooks
@matb33
matb33 / gist:5322002
Last active December 15, 2015 20:58
Automated server installation for Meteor 0.6.0+ on a fresh AWS EC2 Ubuntu Server 12.10 installation. Although MongoDB is installed, I only tested against having my database remotely on MongoHQ. Let me know if you have issues with a local DB. Moved: https://github.com/matb33/meteor-ec2-install
MOVED: https://github.com/matb33/meteor-ec2-install
@matb33
matb33 / example.js
Last active December 15, 2015 23:29
SyncObject smart package for Meteor. Drop this in your Meteor app /packages/syncobject/
ServerTime = (function () {
var sync = new Meteor.SyncObject("serverTime");
var intervalId;
function updateTime() {
sync.set({ms: Date.now()});
}
function updateInterval(intervalMs) {
@matb33
matb33 / aws-sdk.js
Created April 12, 2013 19:09
AWS SDK Smart Package -- Exposes the SDK as AWS.SDK and provides a helper function to sign URLs
AWS = (function () {
var SDK = Npm.require("aws-sdk");
var crypto = Npm.require("crypto");
var url = Npm.require("url");
function getAuthenticatedURL(fullUrl, accessKeyID, secretAccessKey, expires) {
/*
Signature = URL-Encode( Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) ) );
@matb33
matb33 / README.md
Created August 28, 2013 01:17
Meteor Template layouts with yield keyword, inspired by Iron Router. Will eventually make a proper repo and port to Meteorite... stay tuned

Meteor Template layouts with yield

Example usage:

Layout.helper("modal", function (options) {
  return {
    bgcolor: options.bgcolor || "#fff",
    layout: options.layout || "modalLayout"
 };