Skip to content

Instantly share code, notes, and snippets.

Rayner Pupo raynerpupo

Block or report user

Report or block raynerpupo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View L&LFP.md

Intro

Discipline is the future

https://www.youtube.com/watch?v=ecIWPzGEbFc blah Uncle Bob Martin conference about the Future of programming, can reduce the whole conference in one word "discipline" FP paradigm is even older than others mainstream like OOP. It's taking a rise lately given most of the current languages/ecosystems can eventually get an approximate result, yet the time and effort to build and refactor could be very different.

View monoid.ts
export {}
// A monoid is a binary associative operation with an identity
// Laws
// 1 - Associativity: (x <> y) <> z = x <> (y <> z)
// 2 - Left identity: mempty <> x = x
// 3 - Right identity: x <> mempty = x
type Monoid<A = any> = {
mempty: A,
View ModernJS.md

Modern JavaScript

Template literals

Multiline strings

Default parameters

Classes

View coercion.md

Coercion

Coercion is an implicit conversion of types:

// amount is a number
var amount = 32;

// since " years" is a string there is a implicit conversion of amount to string
var age = amount + " years";
console.log(age); // => 32 years
View mixins.md

Mixins

Mixins favors composition over inheritance by adding some custom behavior to an existing object

const fulfillable = {
  fullfill: (doneFunction) => done("OK")
};

const myObj = {
  quit: () => console.log("quit"),
View async_await.md

Async / Await

Async and await let us handle asynchronous code easily, it's somehow similar to generators, pausing the execution whenever the await is prefixed:

// To be able to wait for a call we need to mark a function as async
async function getTemperature () {
// We wait until the getWeather function returns the value
  const weather = await getWeather(....);
  
View call_apply_bind.md

Call apply and bind

Call and Apply

The call and apply functions are similar, they expect a the contex (this) and the parameter to call the function, the only difference is that apply accepts the function parameters in an array.

const calculate = function(x, y) {
  return this.operation(x, y);
}

const multiply = {
View errorfirst_callback.md

Node Error first callback

The expected callback function

This kind of callback function have the error as the first parameter and the actual value as the second

function incrementAndLog(err, value) {
  if (err) {
    console.log("there's no value to increment");
    return;
View callback_promisify.md

Callbacks

Are basically functions that are called when some result is ready or they can also be used to signal errors.

function aDividedByB(a, b, onResultFn, onErrorFn) {
  if (b != 0) {
    return onResultFn(a / b);
  }
  return onErrorFn("The divisor can't be zero!");
}
@raynerpupo
raynerpupo / prototyping.md
Created Mar 9, 2018
JS Prototyping exercise
View prototyping.md

#Shapes Using the new ES6 features related to prototyping, implement a small library to define geometric shapes (not visually) and allow basic calculations. ###Requirements

  • The shapes to define are Circle, Square and Rectangle.
  • All shapes must define a function to calculate the area and perimeter .
  • Use a only positive coordinate system (implement validations while building the shapes or changing its properties).
  • Implement a predicate function collidesWith to check if the shape collides with another shape of the same type.
  • Given a list of shapes, print its properties and the area and perimeter properties.
  • All functionalities should be properly tested.
You can’t perform that action at this time.