Skip to content

Instantly share code, notes, and snippets.

View brosapinto's full-sized avatar

Bruno Pinto brosapinto

View GitHub Profile
@brosapinto
brosapinto / react-context-state-provider
Last active February 3, 2020 15:02
Basic State Management using React Context and Hooks
import React, { createContext, useContext, useReducer } from "react";
const StoreContext = createContext();
export default function StoreProvider({ children, initialState, reducer }) {
return (
<StoreContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StoreContext.Provider>
);
@brosapinto
brosapinto / compiler.js
Last active May 29, 2018 14:04
Simple SPEL expressions subset parser
const wrap = ({ type, value }) => {
switch (type) {
case "string":
return `'${value}'`;
case "variable":
return `%{${value}}`;
default:
return value;
}
};
@brosapinto
brosapinto / keybase.md
Last active January 12, 2018 22:08
Keybase Claim

Keybase proof

I hereby claim:

  • I am brosapinto on github.
  • I am brosapinto (https://keybase.io/brosapinto) on keybase.
  • I have a public key ASCns9732lzSHzfzZaiJL0SoDREcpm5Iu3UVH6qb7Y-ZQAo

To claim this, I am signing this object:

@brosapinto
brosapinto / jsbin.lakunekucu.js
Last active November 1, 2016 21:58 — forked from anonymous/index.html
RxJS Poller
'use strict';
angular.module('app', []).service('client', function ($q) {
this.query = function (xs) {
console.log('XHR request for ' + xs.join(' '));
return $q.when('response');
};
}).factory('poller', function (client, $timeout) {
var items = [];
var cadence = new Rx.BehaviorSubject(0);
@brosapinto
brosapinto / String Replace
Created December 17, 2014 18:25
String replace with placeholders
function parse(str, map) {
return str.replace(/{(\w+)}/g, function (match, key) {
return map[key];
});
}
parse("{holder} world! {holder} juicy!", { holder: "hello"}); // hello world! hello juicy!
@brosapinto
brosapinto / Loop Over Array
Created May 6, 2014 16:18
Loop Array in Bash
items=( "item1" "item2" "item3" )
for item in "${items[@]}"
do
echo $item
done