Skip to content

Instantly share code, notes, and snippets.

Avatar

Wim Mostmans Sitebase

View GitHub Profile
@Sitebase
Sitebase / heroku.js
Created Feb 12, 2015
Detect if node app is running on Heroku
View heroku.js
function isHeroku()
{
return process.env.NODE && ~process.env.NODE.indexOf("heroku") ? true : false;
}
@Sitebase
Sitebase / server.js
Created Feb 4, 2015
Force https in express
View server.js
var app = express();
...
app.use(function(req, res, next) {
if (req.headers['x-forwarded-proto'] === 'https') {
next(); // already on https so just continue
else
res.redirect('https://' + req.headers.host + req.url); // redirect to https
});
@Sitebase
Sitebase / gist:355fc595129862cb245f
Created Feb 3, 2015
Example ambassador tracking script
View gist:355fc595129862cb245f
<script>
(function(i,s,o,g,r,a,m){i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)};
a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=a.defer=1;a.src=g;
m.parentNode.insertBefore(a,m)})(window,document,'script','//api.bubobox.com/tracker.js','_bbq');
_bbq('init', { user_id: 1, segment: 'website' });
</script>
@Sitebase
Sitebase / bbbx-reorder-stack-script.js
Created Jan 12, 2015
Reorder BuboBox stack items
View bbbx-reorder-stack-script.js
var bbbx_stack_presets = {
'overlay' : {
modules: [
'pre',
'terms.pre',
'terms',
'terms.post',
'overlay.pre',
'overlay',
'overlay.post',
@Sitebase
Sitebase / deltag.sh
Created Jan 9, 2015
Batch git tag delete locally and remote
View deltag.sh
# replace "release-" on the following line with the string you want to search for
# or remove the "| grep release-" part to remove all local and remote tags
for t in `git tag | grep release-`
do
echo "delete $t"
git push origin :$t # Delete remote
git tag -d $t # Delete local
done
@Sitebase
Sitebase / gist:e68497ef7c4bad436385
Created Dec 9, 2014
Snippet for implementing video attach to a form with BuboBox
View gist:e68497ef7c4bad436385
<div class="bbbx-widget" data-widget="11"></div>
<script type="text/javascript">
var bbbx_widget_id = 11;
var bbbx_visual = false;
var bbbx_share_enabled = false;
function bbbx_config() {
this.subscribe('published', function(e) {
BBBX.$('.bubobox_result').html('<a href="javascript:mybb.openPlayer(\'' + e.entryId + '\')">Video bekijken</a> | <a href="javascript:mybb.openRecorder()">Video opnieuw opnemen</a>');
BBBX.$('#video_id').val(e.entryId);
@Sitebase
Sitebase / code.php
Created Dec 2, 2014
Example of a very basic unit test in PHP
View code.php
<?php
function sum( $number1, $number2 )
{
if( ! is_int( $number1 ) || ! is_int( $number2 ) )
throw new Exception( 'Both arguments should be numeric' );
return $number1 + $number2;
}
@Sitebase
Sitebase / gravatar.js
Created Nov 13, 2014
Little trick to check if a gravatar is available or not for a certain email address.
View gravatar.js
var http = require('http'),
md5 = require('MD5');
var options = {
method: 'HEAD',
host: 'www.gravatar.com',
port: 80,
path: '/avatar/' + md5('info@blabla.be') + '?d=http://bla.com'
};
var req = http.request(options, function(res) {
@Sitebase
Sitebase / bbbx-module-bootstrap.js
Created Nov 13, 2014
Bootstrap custom BuboBox front-end module
View bbbx-module-bootstrap.js
/**
* This is an example BBBX widget module
* It can be used to add additional functionallity to the BuboBox platform in a modularized way
*/
window.bbbx_modules = window.bbbx_modules || []; // Make modules array if not yet exists
window.bbbx_modules.push(function(sandbox, $) {
var NAME = 'custommodule';
var exports = {
@Sitebase
Sitebase / bbbx-login-stack.js
Last active Aug 29, 2015
Let users login with their custom account before they can submit an entry.
View bbbx-login-stack.js
/**
* BuboBox form callback module
*
* @author Wim Mostmans (wim@bubobox.com)
* @license BSD
*
* Copyright (c) 2014 BuboBox
*/
window.bbbx_modules = window.bbbx_modules || []; // Make modules array if not yet exists