Skip to content

Instantly share code, notes, and snippets.

@arlindosilvaneto
arlindosilvaneto / user-provider-consumer-HOC.js
Last active May 8, 2019 17:08
ReactJS Context API Provider with State and Consumer HOC
import React, { createContext } from 'react';
const UserContext = createContext();
export default class UserProvider extends React.Component {
constructor(props) {
super(props);
this.state = {
user: {},
@arlindosilvaneto
arlindosilvaneto / express-handlers.ts
Last active May 7, 2019 21:16
Typescript Decorators
function log(target: any, property: string, descriptor: PropertyDescriptor) {
let method = descriptor.value;
descriptor.value = function() {
console.warn(`[RUNNING]: ${property}`);
method.apply(this, arguments);
}
}
class Handlers {
@log
@arlindosilvaneto
arlindosilvaneto / auth-filter.clj
Last active March 8, 2017 13:46
Filter architecture for Luminus Webframework
(defn request-auth
"Finds the user by the header token parameter and pass it to the next chain filter/controller as the :user request parameter"
[req & chain]
(let [token (get-in req [:headers "x-auth-token"])]
(if (nil? token)
{:status 401}
(let [user (user/find-by-token (:tx req) token)]
(if (nil? user)
{:status 403}
(let [new-req (assoc req :user (assoc (:user user) :id (:id user)))]
@arlindosilvaneto
arlindosilvaneto / README.md
Last active October 19, 2016 15:45
Neo4j Python Decorator Handler

Neo4j Decorator Driver for Python

All annotations assumes class methods as decorated sources.

Query Decorator Signature

@Query([cypher statement], asTable=False)