Skip to content

Instantly share code, notes, and snippets.

View ortense's full-sized avatar
💀
Coding...

Marcus Ortense ortense

💀
Coding...
View GitHub Profile
@ortense
ortense / memoize.js
Created July 27, 2017 18:24
simple and small memoize function
const memoize = fn => {
const memo = {}
return (...args) => {
if (args in memo) return memo[args]
return (memo[args] = fn.apply(null, args))
}
}
@ortense
ortense / pipe.js
Created July 27, 2017 17:58
simple and small pipe function
const pipe = (...fns) => arg =>
fns.reduce((acc, fn) => fn(acc), arg)
/*
const a = x => `a(${x})`
const b = x => `b(${x})`
const c = x => `c(${x})`
const piped = compose(a, b, c)
@ortense
ortense / compose.js
Last active July 27, 2017 18:05
simple and small compose function
const compose = (...fns) =>
fns.reduce((f, g) => (...args) => f(g(...args)))
/*
const a = x => `a(${x})`
const b = x => `b(${x})`
const c = x => `c(${x})`
const composed = compose(a, b, c)
composed('x') // a(b(c(x)))
@ortense
ortense / pubsub-simple.js
Created June 20, 2017 21:00 — forked from fatihacet/pubsub-simple.js
Simple PubSub implementation with JavaScript - taken from Addy Osmani's design patterns book -
var pubsub = {};
(function(q) {
var topics = {}, subUid = -1;
q.subscribe = function(topic, func) {
if (!topics[topic]) {
topics[topic] = [];
}
var token = (++subUid).toString();
topics[topic].push({
token: token,
@ortense
ortense / fluent-interface.js
Created June 2, 2017 00:12
A simple experiment with fluent interface in javascript
const lower = str => str.toLowerCase()
const upper = str => str.toUpperCase()
const trim = str => str.trim()
const exclaim = str => `${str}!!`
const string = str => ({
get upper() { return string(upper(str)) },
@ortense
ortense / curry.js
Last active August 5, 2017 19:43
simple and small curry function
const curry = (fn, ...args) => {
if (args.length === fn.length) return fn(...args)
return (...more) => curry(fn, ...args, ...more)
}
/*
const add = (a, b, c) => a + b + c
const curred = curry(add)
@ortense
ortense / CustomError.js
Last active September 22, 2017 20:51
Custom Error with classes
const propertyDescriptor = { enumerable: true, writable: false }
export default class CustomError extends Error {
constructor(message) {
super(message)
this.type = this.constructor.name
Object.defineProperty(this, 'type', propertyDescriptor)
Object.defineProperty(this, 'message', propertyDescriptor)
}
@ortense
ortense / .eslintrc
Created January 11, 2017 12:27 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@ortense
ortense / .babelrc
Last active November 24, 2016 21:14
Hello World with express-decorators
{
"presets": ["es2015"],
"plugins": [
"transform-decorators-legacy",
"transform-async-to-generator"
]
}
@ortense
ortense / tagueamento-youtube.md
Last active October 6, 2016 19:12
youtube iframes api

Passo a passo para taguear YouTube

Esse código é totalmente dependente dos polyfill de

  • Array forEach
  • Array Map
  • Array Filter

Não se esqueça de adiciona-los a implementação!!!