Skip to content

Instantly share code, notes, and snippets.

Michael Lehenbauer mikelehen

Block or report user

Report or block mikelehen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View firestore-rest-server-timestamp-example.txt
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"
@mikelehen
mikelehen / generate-pushid.js
Created Feb 11, 2015
JavaScript code for generating Firebase Push IDs
View generate-pushid.js
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
View firepad-drag-drop-images.js
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 / presence-example.js
Created Jan 10, 2014
Per-session presence bits.
View presence-example.js
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);
}
});
@mikelehen
mikelehen / firepad-node.js
Created Dec 16, 2013
Curtesy of Clément (https://github.com/iclems), a node script that instantiates firepad in order to extract the text contents.
View firepad-node.js
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;
@mikelehen
mikelehen / firepad-insert-image.js
Created Oct 23, 2013
Inserting an image into firepad.
View firepad-insert-image.js
firepad.insertEntity('img', {
'src' : 'http://cdn.dashburst.com/wp-content/uploads/2013/01/Grumpy-Cat.jpg',
});
@mikelehen
mikelehen / auto-expand-firepad.css
Created Sep 28, 2013
Styles to make firepad auto-expand to fit its content.
View auto-expand-firepad.css
.firepad {
height: auto;
}
.firepad-toolbar {
position: relative;
margin-top: 20px;
margin-left: 10px;
top: auto;
left: auto;
@mikelehen
mikelehen / entity-modification.js
Created Sep 28, 2013
An example of registering an 'img' entity that modifies itself on click or shift-click (see onclick handler).
View entity-modification.js
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 / firepad-drag-drop.js
Created Aug 29, 2013
Simple drag/drop of images into Firepad... probably not production-ready, but seems to work.
View firepad-drag-drop.js
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();
View .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
You can’t perform that action at this time.