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 / 01_script.js
Last active December 27, 2015 10:09
get all commits from one GitHub organization using jQuery
var org = 'hoodiehq';
var sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
$.getJSON('https://api.github.com/orgs/'+org+'/events').then( function(events) {
var commits = [];
events.forEach( function(ev){
if (ev.created_at < sevenDaysAgo) return;
if (ev.type !== 'PushEvent' || ! ev.payload.commits) return;
ev.payload.commits.forEach( function(commit) {
commits.push(commit.author.name + ': ' + commit.message.split(/\n/)[0])
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gr2m
gr2m / sinon_expect_promise_helpers.js
Last active December 20, 2015 21:19
sinon expect helpers
// adds expect.js helpers for promises:
//
// expect(promise).to.be.promise()
// expect(promise).to.be.resolved()
// expect(promise).to.be.resolvedWith(['love'])
// expect(promise).to.be.rejected()
// expect(promise).to.be.rejectedWith(['hate'])
// expect(promise).to.be.pending()
@gr2m
gr2m / messaging_worker_dreamcode.js
Last active December 20, 2015 14:39
a Hoodie messaging worker (dreamcode yet) that allows to send messages between users
module.exports = function(hoodie) {
hoodie.task.on('new:message', handleNewMessage);
function handleNewMessage(originDb, message) {
// move new message to the recipients
var recipient = message.to;
hoodie.account.find('user', recipient, function(error, user) {
if (error) {
@gr2m
gr2m / 01_hoodie-email-worker.dreamcode.js
Last active December 17, 2015 05:19
This is dreamcode for the Hoodie (http://hood.ie) Email worker, doing the backend magic behind hoodie.email.send( options ). I'm not a Node person, just dreaming out loud ;-)
function Worker(app) {
this.app = app;
app.on('add:$email', this.sendEmail.bind(this) );
}
Worker.prototype.sendEmail = function(email) {
// check if email has been configured
var emailConfig = app.config.get("email")
@gr2m
gr2m / call_for_contributors.md
Last active December 17, 2015 00:19
Hoodie empowers frontend developers to build fully capable apps, without thinking backend. We've put a lot of thoughts into its API and made a proof-of-concept implementation, but now want to reach out to gather opinions on how hoodie.js should be implemented "the proper JavaScript way".

hoodie.js is a library to abstract common backend tasks in form of frontend developer friendly JavaScript methods.

The API is what we care most about. No matter of how complex are behind the curtain, hoodie.js has to remain as simple as jQuery.

The current implementation is done with CoffeeScript, for reasons. But we want to move to make a proper JavaScript implementation and want to invite you to help us:

  • what's your opinion on how the hoodie.js modules should be structured, the "JavaScript way"?
  • what are libraries we should look into / learn from?
  • this is your chance: do you want to help migrating hoodie.js to JavaScript? Raise your hand
@gr2m
gr2m / control_devices.dreamcode.js
Last active August 29, 2016 09:01
Imagine you could control other devices with a simple JavaScript API, right from your browser.
// Ask the coffee machine at IP 192.168.2.2 to do its job
device('192.168.2.2')
.do( 'coffee' )
.then( wakeMeUpCallback )
// turn all lights on
device.findAll('light').do('turnOn')
@gr2m
gr2m / payments_dreamcode.js
Last active April 29, 2024 19:17
Imagine you could purchase items from your store, with pure JavaScript in the browser. How would it look like? Here's what I came up with. Forks & comments much appreciated! #nobackend #dreamcode
// purchase a product with a credit card
purchase('productId')
.using( {
cc: "4556934156210213",
valid: "2016-10",
csc: "123"
} )
// purchase a product with paypal
purchase('productId')
@gr2m
gr2m / convert_dreamcode.js
Last active August 29, 2016 09:01
Imagine you could convert all kind of things to all kind of different things, e.g. taking a screenshot of a dom element or converting another website to a screenshot. Forks & comments much appreciated! #nobackend #dreamcode
// convert a dom element to a PDF and download it
convert( $('.invoice') ).to( 'invoice.pdf' ).download()
// alternatively
download( convert( $('.invoice') ).to( 'invoice.pdf' ) )
// convert another website to a png and show it on the page
convert( 'http://exam.pl/page' ).toImage().then( $('.screenshots').append )
// attach a file to an email