Skip to content

Instantly share code, notes, and snippets.

@dstollie
dstollie / purify_common.js
Created March 27, 2015 10:40
Simple purify method for meteor which uses cristo-rabani's package: https://github.com/cristo-rabani/meteor-universe-html-purifier
purify = function(text, allowedTags, allowedAttributes) {
if(!allowedTags) allowedTags = ['b', 'i', 'strong', 'em', 'ol', 'ul', 'li', 'p', 'span', 'a', 'img', 'br'];
if(!allowedAttributes) allowedAttributes = ['href', 'src'];
var disallowedTags = ['b', 'i', 'strong', 'em', 'blockquote', 'ol', 'ul', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'p', 'span', 'pre', 'a', 'u', 'img', 'br', 'table'];
// Check the difference between the default enabled tags and the allowed tags
var disallowedTags = _.difference(disallowedTags, allowedTags);
if(Meteor.isServer) {
cheerio = Npm.require("cheerio");
}
validEmail = function (email) {
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
purify = function(text, allowedTags, allowedAttributes) {
AnswerSchema = new SimpleSchema(_.extend({
body: {
type: String
},
questionId: {
type: String
},
upvotes: {
type: Number,
optional: true,
@dstollie
dstollie / .env.local.php.dist
Created October 12, 2015 23:20
Example of adding Twig support to the composer-dist-installer package
<?php
/*----------------------------------------------------*/
// Local environment vars
/*----------------------------------------------------*/
{% set db_name = '{!Database name?[]?|wordpress!}' %}
{% set db_user = '{!Database user []?|=ENV[USER]!}' %}
{% set db_password = '{!Database password?!}' %}
{% set db_host = '{!Database host []?|localhost!}' %}
{% set db_home = '{!Wordpress home url []?|http://mysite.dev/!}' %}
{% set db_siteurl = '{!Wordpress site url []?|http://mysite.dev/cms/!}' %}
@dstollie
dstollie / acf.php
Last active September 15, 2017 14:13
Using Themosis templates in ACF
<?php
/**
* ACF has this fancy option to show ACF fields based on pages templates.
* One problem: Themosis templates are not registered as "default" WordPress templates.
* This file hooks into the acf filters and allows ACF to use the Themosis templates.
*/
// add themosis templates
add_filter('acf/location/rule_values/page_template', 'add_themosis_templates_to_acf_rules');
function add_themosis_templates_to_acf_rules($choices)
@dstollie
dstollie / MyModel.php
Created November 11, 2015 13:54
Wordpress Snippet: Simple snippet to get the following, previous and related posts of a post of a certain post type
<?php
/**
* returns a WP_Query instance which generates a list of news items which have the same theme taxonomy as the given post.
* If not post is given the global post will be used
*
* @param null $postId
* @param [] $query
*
* @return WP_Query
*/
@dstollie
dstollie / 0_reuse_code.js
Created December 8, 2015 01:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dstollie
dstollie / reinit-git-repository.sh
Last active December 9, 2015 21:10
Remove all commits to reset a remote GIT repository
#!/bin/sh
#
# 1. Delete the .git directory locally.
# 2. Recreate the git repostory:
$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
@dstollie
dstollie / samenzwolle-create-activity.php
Last active May 26, 2016 15:24
SamenZwolle.nl activiteit aanmaken PHP voorbeeld
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$appUrl = 'http://samenzwolle.bijna.live/api/activities';
$apiKey = '$2y$10$WaWaK1rIVzjiIYh4gkbl.uexHS8dMNBSfcPOO1l3/9k8V4xnQUwBi';
$body = "{\"name\":\"Voorbeeld activiteit\",\"description\":\"Dit is een omschrijving\",\"start_date\":[\"09-05-2016 00:00\",\"11-05-2016 00:00\"],\"end_date\":[\"10-05-2016 00:00\",\"12-05-2016 00:00\"],\"url_email\":\"https://example.com/activities/1\",\"street\":\"Wilhelm Rontgenstraat\",\"house_number\":\"11B\",\"zipcode\":\"8013NE\",\"postbox\":\"-\",\"image1\":\"http://lorempixel.com/400/200/\",\"image2\":\"http://lorempixel.com/400/200/\",\"image3\":\"http://lorempixel.com/400/200/\",\"agreement\":\"1\"}";
$curl = curl_init();
@dstollie
dstollie / .phpcs_dist
Created April 5, 2017 22:49
PHP CS Fixer for the win
<?php
$finder = PhpCsFixer\Finder::create();
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@PHP70Migration' => true,