Skip to content

Instantly share code, notes, and snippets.

View gabro's full-sized avatar

Gabriele Petronella gabro

View GitHub Profile
@gabro
gabro / git-working-history
Last active March 27, 2023 09:47
Github-like working directory history
#!/bin/bash
FILES=`git ls-tree --name-only HEAD .`
MAXLEN=0
IFS=$(echo -en "\n\b")
for f in $FILES; do
if [ ${#f} -gt $MAXLEN ]; then
MAXLEN=${#f}
fi
done
@gabro
gabro / AssetPicker.swift
Created November 2, 2015 10:07
A block-based asset picker for videos, photos and files
import Photos
import MobileCoreServices
class AssetPicker: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIDocumentPickerDelegate, UIDocumentMenuDelegate {
static let sharedInstance = AssetPicker()
private lazy var cameraPicker: UIImagePickerController = {
let cameraPicker = UIImagePickerController()
@gabro
gabro / crypto.scala
Created July 22, 2020 05:49
Read string into keyring
import org.bouncycastle.openpgp.{
PGPPublicKeyRing,
PGPPublicKeyRingCollection,
PGPUtil,
}
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator
def readPGPPublicKeys(pubKeys: List[String]): PGPPublicKeyRingCollection = {
val fingerprintCalculator = new JcaKeyFingerprintCalculator()
val publicKeyRings = pubKeys.map { pubKey =>
@gabro
gabro / validation.flow.js
Last active February 24, 2020 16:38
Dynamic object validation using $ObjMap in Flow
/* @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(),
@gabro
gabro / sublime.tex
Created December 2, 2012 00:25
LaTeX example
\documentclass{article}
\title{LaTeX is now Sublime}
\author{Gabriele Petronella}
\begin{document}
\maketitle
\section{My first section}
@gabro
gabro / main.tex
Created December 7, 2012 19:23
An example of a multi-part LaTeX document
\documentclass{article}
\title{A long document}
\author{Gabriele Petronella}
\date{\today}
\begin{document}
\maketitle
@gabro
gabro / extension.ts
Created September 28, 2018 08:37
VSCode decoration API
'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 {
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==
export default function (babel) {
const { types: t } = babel;
return {
visitor: {
NumericLiteral(path) {
path.node.value += 1
}
}
};
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");
}
}
};
}