Skip to content

Instantly share code, notes, and snippets.

View gr2m's full-sized avatar
cookin'

Gregor Martynus gr2m

cookin'
View GitHub Profile
@gr2m
gr2m / offline_maps_dreamcode.js
Created November 15, 2013 19:44
Imagine you could use your map-based web application offline, including the map tiles. How could the API look like? #nobackend #dreamcode
// Add a new map to the collection
var map = OfflineMap.add('Berlin')
// This will not yet download it, to do so, call download on it.
// It returns a promise, with done / fail / progress callbacks
var download = OfflineMap.find('Berlin').download();
download.progress( updateProgressBar );
// Before downloading, you can also calculate its size
var map = OfflineMap.find('Berlin');
@gr2m
gr2m / hoodie.plugins.js
Created May 28, 2014 17:55
Hoodie Plugin that maintains a local list of user accounts that have been used in a browser. See discussion at https://github.com/hoodiehq/discussion/issues/42
'use strict';
var hoodie = require('backbone').hoodie;
hoodie.extend(function(hoodie,lib, utils) {
var PROFILES_STORE_KEY = '_hoodie_profiles';
var store = utils.localStorageWrapper;
var api = getAllProfiles;
var profiles = store.getObject(PROFILES_STORE_KEY) || [];
//
@gr2m
gr2m / learnings.md
Last active August 29, 2015 14:04
I've read the whole Bootstrap 3 documentation. I learned a few new things.
@gr2m
gr2m / .bash_profile
Created July 30, 2014 13:44
serve the assets of current folder with CORS headers
alias corsserver="echo -e \"from SimpleHTTPServer import SimpleHTTPRequestHandler\nimport BaseHTTPServer\nclass CORSRequestHandler (SimpleHTTPRequestHandler):\n def end_headers (self):\n self.send_header('Access-Control-Allow-Origin', '*')\n SimpleHTTPRequestHandler.end_headers(self)\nif __name__ == '__main__':\n BaseHTTPServer.test(CORSRequestHandler, BaseHTTPServer.HTTPServer)\" | python"
@gr2m
gr2m / reproduce.md
Last active August 29, 2015 14:05
showcase of problem with PhantomJS

setup

git clone https://github.com/hoodiehq/hoodie-admin-dashboard/
cd hoodie-admin-dashboard
gco admin_dashboard_tests
npm install
bower install
grunt serve
@gr2m
gr2m / combine_requests.js
Created September 4, 2014 11:51
How to achive the logic below with the native JavaScript Promise implementation?
var requestPromise;
function getCurrentState() {
// prevent sending multiple GET requests to /state.json. If one is pending, return its promise
if (requestPromise.isPending()) return requestPromise;
requestPromise = ajaxRequestReturningPromise('GET', '/state.json');
return requestPromise;
}
promise1 = getCurrentState()
promise2 = getCurrentState()
promise = new Promise(function (resolve, reject) {
// do stuff here
}
promise.then(null, null, function progressHandler() {
// how to get here?!
});
@gr2m
gr2m / gistbook.json
Created December 10, 2014 18:10
Anonymous Gistbook
{"title":"Anonymous Gistbook","author":"gr2m","pages":[{"pageName":"","sections":[{"type":"text","source":"# Welcome to Gistbook!\n\n$$x = \\int_a^b{x\\mathrm{d}x}$$"},{"type":"html","source":"<div>hello</div>"},{"type":"css","source":"div {\n\n background: #333;\n}"},{"type":"javascript","source":"var _ = require('underscore');\n\n_.each([1,2,3], function(num) {\n console.log('hello');\n})"}]}],"public":true}
function securityWrapper(checkAllowed, original, args) {
var userCtx = args.options.userCtx || {
//Admin party!
name: null,
roles: ["_admin"]
};
if (userCtx.roles.indexOf("_admin") !== -1) {
return original();
}
if (!checkAllowed) {
var fs = require('fs')
var PDF = require('dream-pdf')
var tableData = require('./table.json')
PDF.plugin(require('dream-pdf-text'))
PDF.plugin(require('dream-pdf-image'))
PDF.plugin(require('dream-pdf-table'))
pdf = new PDF({
size: [210, 297]