Skip to content

Instantly share code, notes, and snippets.

View ruiramos's full-sized avatar
🎹
pianando

Rui Ramos ruiramos

🎹
pianando
View GitHub Profile
@ruiramos
ruiramos / pattern-matching2.js
Last active January 19, 2022 14:58
Simple Javascript pattern matching
let a = [null, {status: 'OK'}];
switch_(
(err, _) => console.log('error', err),
(_, resp) => console.log('response', resp)
)(a);
// logs 'response' { "status": "OK" }
let b = [{err: 401}, null];

Keybase proof

I hereby claim:

  • I am ruiramos on github.
  • I am ruiramos (https://keybase.io/ruiramos) on keybase.
  • I have a public key ASCKDnmBgn3g9-b0wwMB8-wmq3ao9Y2FIkQMUouET-k4Cwo

To claim this, I am signing this object:

requestAction: function(action, method, options){
var unMapMethod = {
POST: 'create',
PUT: 'update',
DELETE: 'delete',
GET: 'read'
};
// calls ampersand sync
this.sync(unMapMethod[method], this, _.extend({
@ruiramos
ruiramos / index.js
Created October 25, 2015 14:32
requirebin sketch
var State = require('ampersand-state');
var Collection = require('ampersand-collection')
var Person = State.extend({
props: {
name: 'string',
birthdate: 'date',
job: {type: 'string', default: 'Web Developer'},
},
@ruiramos
ruiramos / index.js
Created January 29, 2015 13:06
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Rebuild to run it on the right
var State = require('ampersand-state');
var MyState = State.extend({
props: {
'arriving': ['object', false, function(){
return {hello: 'there!'}
}],
'leaving': ['string', false, 'bye!']
@ruiramos
ruiramos / jsbin.fatojefa.html
Created July 16, 2014 00:03
Objective: I have 3 workers doing independent things, but I only want to update the app's state once they're all in the "same (synchronous) page" - meaning that if one updates, I want to wait for the others to update as well before showing the result. Reference implementation:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="out"></div>
</body>