Skip to content

Instantly share code, notes, and snippets.

View voxpelli's full-sized avatar

Pelle Wessman voxpelli

View GitHub Profile
@voxpelli
voxpelli / referrer-bookmarklet.js
Created April 25, 2014 13:04
Forgot from where a tab was opened? This bookmarklet helps you find out
// javascript:(function(){var%20result%20=%20window.prompt(%27You%20came%20here%20from:%27,%20document.referrer);if%20(result%20!==%20null)%20{window.open(result);}}())
(function(){
var result = window.prompt('You came from here:', document.referrer);
if (result !== null) {
window.open(result);
}
}())
@voxpelli
voxpelli / gist:3cb981f4fa65fc82f7f0
Created June 25, 2014 13:21
My initial take on a CSSLint .csslintrc config
{
"adjoining-classes": false,
"box-model": false,
"box-sizing": false,
"floats": false,
"gradients": false,
"ids": false,
"qualified-headings": false,
"text-indent": false,
"unique-headings": false,
@voxpelli
voxpelli / README.md
Created June 25, 2014 13:32
My initial take on a JSHint .jshintrc config

If it is mainly a Node.js project that should be linted, then I would switch the "browser" setting for a "node" setting, but no matter if the default is that the javascript files are meant for a Node.js environment or a browser environment one can always override it in a specific file by adding the JSLint-compatible settings:

/*jslint node: true */

Or:

/*jslint browser: true */
@voxpelli
voxpelli / autoselect.js
Created August 4, 2014 17:35
Less annyoing auto-select in readonly textarea content (with purpose of making it _easier_ to copy&paste stuff – not harder)
$('textarea[readonly]').on('mouseup', function () {
if (document.activeElement === this && this.selectionStart === this.selectionEnd) {
$(this).select();
}
});
(function () {
if (window.parent !== window) {
window.parent.postMessage(JSON.stringify({
// The config of your endpoint
reply: 'http://voxpelli.com/reply?u={url}'
}), '*');
}
// Pick a way to invoke the registerProtocolHandler, through a submit handler in admin or something
document.getElementById('confForm').addEventListener('submit', function (e) {
@voxpelli
voxpelli / indieconfig-loader.html
Last active August 29, 2015 14:06
Promise based loading of indie-config, wrapped in an example page using that promise. More info @ http://indiewebcamp.com/indie-config
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Indie Configuration</title>
<link rel="stylesheet" href="/css/style.css" />
</head>
<body>
<div class="page" id="page-wrapper">
<header>
@voxpelli
voxpelli / fail.js
Created September 16, 2014 14:22
Node.js fail with EventEmitter, Promise and Exception
var events = require('events');
var Promise = require('Promise');
var foo = new events.EventEmitter();
foo.on('bar', function () {
console.log('Four');
throw new Error('Fail!');
});
@voxpelli
voxpelli / news.js
Created March 20, 2015 14:53
Content Management _Components_ rather than Content Management _System_
// Create a "news" type content type
// Example module names – not real ones
module.exports = function () {
return require('contenttype')
.addField('title', require('textfield'))
.addField('image', require('imagefield'))
.addField('author', require('authorlink'));
};
@voxpelli
voxpelli / README.md
Last active August 29, 2015 14:27
Private Messaging With From: Sequence diagram
if (get_magic_quotes_gpc()) {
function strip_the_slashes($array) {
foreach($array as $key => $value) {
if (is_array($value)) {
$value = strip_the_slashes($value);
} else {
$value = stripslashes($value);
}
$array[$key] = $value;
}