Skip to content

Instantly share code, notes, and snippets.

View montlebalm's full-sized avatar
✌️

Chris Montrois montlebalm

✌️
  • Airtable
  • Louisville, CO
View GitHub Profile
@montlebalm
montlebalm / reddit_diablo_spoiler.js
Created May 17, 2012 17:13
r/diablo spoiler hider
// ==UserScript==
// @name Spoiler hider
// @description Hide spoilers on the page without the subreddit theme
// @author Chris Montrois
// @include *reddit.com/r/diablo/
// @version 1.0
// ==/UserScript==
// A function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
@montlebalm
montlebalm / F2.BaseAppClass.js
Last active December 22, 2015 16:19
F2 AMD - Example usage of an F2 container and app using AMD
define("F2.BaseAppClass", ["F2.Events", "F2.Defer"], function(events, defer) {
var AppClass = function() {};
// Init function that will be called by F2 automatically
// You probably don't want to override this, but you can
AppClass.prototype.init = function(appId, instanceId, context) {
var self = this;
this.appId = appId;
@montlebalm
montlebalm / container-example.js
Last active December 23, 2015 18:39
An example of loading an F2 app with real AMD.
// AppClass
define("com_markit_header", ["F2.Defer", "F2", "MyCoolClass"], function(defer, F2) {
var AppClass = function() {};
return AppClass;
});
@montlebalm
montlebalm / F2: Sandboxing via AMD plugin
Created January 21, 2014 17:45
Playing with sandboxing in F2 by using an AMD plugin. The plugin uses a domain key to group apps.
// Inside F2 library
// --------------------------------------------------------------------------------
// Override "define" to give us the appId inside the plugin
var oldDefine = define;
define = function(id, deps, fn) {
// Append the appId to the dependency
if (deps && deps instanceof Array) {
for (var i = 0; i < deps.length; i++) {
if (deps[i].indexOf('F2Sandbox!') === 0) {
Goals for sandboxing:
- Prevent "F2.Events.emit = function() { }" hijacking
- Apps can sandbox themselves without the container
- Sandboxing is optional
- Sandboxed apps can emit global events
- Apps can be sandboxed with any app from any domain
@montlebalm
montlebalm / F2: sandboxing by appIds
Created January 21, 2014 18:23
This approach allows an app to specify a range of AppIds it is allowed to communicate with. Pros: - Simple or detailed configuration - Makes F2 plugins easy, since each app gets its own instance Cons: - If the app is used in multiple pages, the configuration list might be very long - It requires the app to specify every possible app it wants to …
/*
Summary
In this example, each app gets its own instance of F2. Every instance of F2
will share all the same page events. This setup will allow each app to add its
own plugins without interfering with the rest of the apps.
We'll add internal checks to make sure events are only broadcast to "trusted"
apps. This should allow any app to specify any other app on the page
*/
var F2Class = function() {
return {
emit: function(name, data) {
console.log("Safe and sound");
}
};
};
@montlebalm
montlebalm / .vimrc
Created September 25, 2014 16:28
Get it on. Vim till the break of dawn.
set nocompatible
filetype off
filetype plugin indent off
" -----------------------------------------------------------------------------
" Plugins
" -----------------------------------------------------------------------------
" Set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle.vim/
@montlebalm
montlebalm / Component.js
Last active September 22, 2015 15:23
Testing React Components with React Router
var Component = React.createClass({
contextTypes: {
router: React.PropTypes.func
},
propTypes: {
isCool: React.PropTypes.bool
},
getDefaultProps() {
return {
isCool: false
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="output_h"></div>
<div id="output_v"></div>
<script src="virtual-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>