Skip to content

Instantly share code, notes, and snippets.

Gabriele Petronella gabro

Block or report user

Report or block gabro

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
@gabro
gabro / extension.ts
Created Sep 28, 2018
VSCode decoration API
View extension.ts
'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { window, commands, ExtensionContext, Range, Position, TextEditor, workspace, DecorationOptions } from 'vscode';
const decorationType = window.createTextEditorDecorationType({ })
function addDecorations(e: TextEditor) {
try {
View ScastieModifier.scala
package docs
import mdoc.Reporter
import mdoc.StringModifier
import scala.meta.inputs.Input
import java.util.UUID
/** Transforms scala code blocks into Scastie snippets
*
* ==Usage==
View babel-increment.js
export default function (babel) {
const { types: t } = babel;
return {
visitor: {
NumericLiteral(path) {
path.node.value += 1
}
}
};
View eslint-no-console.js
export default function(context) {
return {
CallExpression(node) {
const { callee } = node;
if (callee.type === "MemberExpression" && callee.object.name === "console" && callee.property.name === "log") {
context.report(node, "Do not use console.log");
}
}
};
}
View gist:26221d7c21ac0430fd944a4e6ab2095c
parser | AST | ES2017 | ES next
-----------|:---------------:|:------:|:--------------:
acorn | ESTree | ✅ | only stage-4
babylon | Babylon AST | ✅ | ✅
espree | ESTree | ✅ | same as acorn
esprima | ESTree | ✅ | ❌
flow | ESTree + custom | ✅ | ✅
TypeScript | TypeScript AST | ✅ | ✅
@gabro
gabro / cats.scala
Created Feb 25, 2017
Monad Transformers for the working programmer
View cats.scala
import cats.data.OptionT, cats.std.future._
def findAddressByUserId(id: Long): Future[Option[Address]] =
(for {
user <- OptionT(findUserById(id))
address <- OptionT(findAddressByUser(user))
} yield address).value
@gabro
gabro / compose-applicative.js
Last active Nov 21, 2016
Applicative instances composition in vanilla js
View compose-applicative.js
function composeFunctor(f, g) {
function map(h, fga) {
return f.map(ga => g.map(h, ga), fga)
}
return { map }
}
function composeApplicative(f, g) {
@gabro
gabro / applicative.js
Created Nov 21, 2016
Applicative abstraction in vanilla.js
View applicative.js
const arr = {
ap(fab, fa) {
return fab.reduce((acc, f) => acc.concat(fa.map(f)), [])
}
}
const f = (n) => n * 2
const g = (n) => n + 1
const a1 = [f, g]
@gabro
gabro / validation.flow.js
Last active Nov 23, 2018
Dynamic object validation using $ObjMap in Flow
View validation.flow.js
/* @flow */
// A simplified representation of types using phantom types (so that we store the Type information both at value and type level)
class Type<T> {};
class StringT extends Type<string> {}
class NumberT extends Type<number> {}
// A schema for a User
const User = {
name: new StringT(),
View keybase.md

Keybase proof

I hereby claim:

  • I am gabro on github.
  • I am gabro (https://keybase.io/gabro) on keybase.
  • I have a public key ASBZl9AJO-rUEOoKZ98kEhpqYfcs3vlfuC1DA_bwE0FdRgo

To claim this, I am signing this object:

You can’t perform that action at this time.