Skip to content

Instantly share code, notes, and snippets.

@mikelehen
mikelehen / firepad-drag-drop.js
Created August 29, 2013 00:30
Simple drag/drop of images into Firepad... probably not production-ready, but seems to work.
codeMirror.setOption('onDragEvent', function(cm, e) {
// Move the cursor as they drag.
var pos = codeMirror.coordsChar({left: e.x, top: e.y });
codeMirror.setCursor(pos);
codeMirror.focus();
var isImageDrop = e.type == 'drop' && e.dataTransfer.files && e.dataTransfer.files.length > 0 && e.dataTransfer.files[0].type && e.dataTransfer.files[0].type.indexOf('image/') > -1;
if (!isImageDrop) return;
event.preventDefault();
@mikelehen
mikelehen / entity-modification.js
Created September 28, 2013 23:05
An example of registering an 'img' entity that modifies itself on click or shift-click (see onclick handler).
firepad.registerEntity('img', {
render: function(info, handle) {
var attrs = ['src', 'alt', 'width', 'height', 'style', 'class'];
var html = '<img ';
for(var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
if (attr in info) {
html += ' ' + attr + '="' + info[attr] + '"';
}
}
@mikelehen
mikelehen / auto-expand-firepad.css
Created September 28, 2013 23:15
Styles to make firepad auto-expand to fit its content.
.firepad {
height: auto;
}
.firepad-toolbar {
position: relative;
margin-top: 20px;
margin-left: 10px;
top: auto;
left: auto;
@mikelehen
mikelehen / firepad-insert-image.js
Created October 23, 2013 19:05
Inserting an image into firepad.
firepad.insertEntity('img', {
'src' : 'http://cdn.dashburst.com/wp-content/uploads/2013/01/Grumpy-Cat.jpg',
});
@mikelehen
mikelehen / firepad-node.js
Created December 16, 2013 22:43
Curtesy of Clément (https://github.com/iclems), a node script that instantiates firepad in order to extract the text contents.
var jsdom = require('jsdom');
var fs = require('fs');
var Firepad = {};
Firepad.load = function(ref, callback) {
jsdom.env('<head></head><body><div id="firepad"></div></body>', function (errors, window) {
var document = document || window.document;
codeMirror.setOption('onDragEvent', function(cm, e) {
// Move the cursor as they drag.
var pos = codeMirror.coordsChar({left: e.x, top: e.y });
codeMirror.setCursor(pos);
codeMirror.focus();
var isImageDrop = e.type == 'drop' && e.dataTransfer.files && e.dataTransfer.files.length > 0 && e.dataTransfer.files[0].type && e.dataTransfer.files[0].type.indexOf('image/') > -1;
if (!isImageDrop) return;
event.preventDefault();
@mikelehen
mikelehen / prune-firepad-history.js
Created April 10, 2013 19:37
Prune history of a Firepad.
// This should be easier, but due to an oversight in the checkpoint id's, it's a tad tricky (you need this revision/id stuff).
// I'll rework things to be cleaner in the near future.
function pruneHistory(firepadRef) {
var characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
function revisionToId(revision) {
if (revision === 0) {
return 'A0';
}
@mikelehen
mikelehen / .vimrc
Created July 29, 2013 00:04
My vimrc
set autoindent ignorecase noerrorbells ruler hlsearch sw=4 sts=4 expandtab
set textwidth=79 nowrapscan formatoptions-=t incsearch tabstop=4
set scrolloff=2 norestorescreen history=100 shortmess=ao nobackup
set matchtime=1 showmatch smartcase wildmenu wildmode=longest:full
syntax on
map Q gq
map Y y$
behave xterm
@mikelehen
mikelehen / presence-example.js
Created January 10, 2014 20:51
Per-session presence bits.
var presenceRef = new Firebase('https://mike.firebaseio.com/users/michael/presence');
presenceRef.root().child('.info/connected').on('value', function(s) {
if (s.val() === true) {
// we're connected. Set up presence with a per-session presence bit.
var ref = presenceRef.push();
ref.onDisconnect().remove();
ref.set(true);
}
});
POST https://firestore.googleapis.com/v1beta1/projects/firestore-fun/databases/(default)/documents:commit?key={YOUR_API_KEY}
{
"writes": [
{
"update": {
"name": "projects/firestore-fun/databases/(default)/documents/foo/bar",
"fields": {
"some-field": {
"stringValue": "some-value"