Skip to content

Instantly share code, notes, and snippets.

View axyz's full-sized avatar

Andrea Moretti axyz

  • Zalando SE
  • Berlin
View GitHub Profile
@axyz
axyz / code-url-encoder.ts
Created September 14, 2023 07:46
Encode code string in a compressed URL string
import { strToU8, strFromU8, compressSync, decompressSync } from "fflate";
const urlEncode = (str: string) =>
btoa(str).replace(
/[/+=]/g,
(a) => ({ "/": "-", "+": "_", "=": "~" }[a] || a)
);
const urlDecode = (str: string) =>
atob(str.replace(/[-_~]/g, (a) => ({ "-": "/", _: "+", "~": "=" }[a] || a)));

What to use

  • Test runner: ava
  • React components testing: enzyme
  • Endpoint testing: express + supertest
  • Mocking framework: sinon
  • External dependencies mocking: proxyquire

Test cases

all the following examples are using ava syntax, but they may be easily adapted to mocha or tape as well

let barposition = "bottom"
let mapleader = ","
map b :buffer<Space>
map B :bookmarks<Space>
map <C-u> scrollPageUp
map <C-d> scrollPageDown
function BSTLinearPartition(seq, k) {
if (seq.length <= 1) return [seq];
if (k >= seq.length) return seq.map(el => [el]);
const limit = threshold(seq, k);
let current = 0;
return seq.reduce((res, el) => {
if (sum(res[current]) + el > limit) current++;
res[current].push(el);
function greedyLinearPartition(seq, k) {
return seq
.sort((a, b) => b - a)
.reduce((res, el) => {
res[smallerArrayIndex(res)].push(el);
return res;
// waiting for more elegant solutions (Array.fill) to work correctly
}, new Array(k).join().split(',').map(i => []));
}
function _perfectRowsNumber(photos, screenWidth, screenHeight) {
const idealHeight = parseInt(screenHeight / 2, 10);
const totalWidth = photos.reduce((sum, img) => sum + img.ratio * idealHeight, 0);
return Math.round(totalWidth / screenWidth);
}
@axyz
axyz / packages.el
Created July 21, 2015 21:34
React spacemacs layer
;;; packages.el --- react Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Andrea Moretti & Contributors
;;
;; Author: Andrea Moretti <axyzxp@gmail.com>
;; URL: https://github.com/axyz
;;
;; This file is not part of GNU Emacs.
;;
;; -*- mode: dotspacemacs -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration."
(setq-default
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (ie. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '("~/.my-spacemacs-layers/")
@axyz
axyz / axyz-post-gallery.php
Last active August 29, 2015 14:16
axyz-post-gallery
<?php
/*
Plugin Name: WP Post Gallery
Version: 0.1
Author: Andrea Moretti (@axyz)
Author URI: http://github.com/axyz
License: GPL2
*/
@axyz
axyz / Andrea Moretti CV
Last active August 29, 2015 14:03
Andrea_Moretti_CV
Andrea Moretti
==============
I was Born in **1987** in **Rome** where I'm actually living. After a childhood spent on dreaming to become a scientist, I've firstly approached programming languages at 11 when I've casually found QBASIC on an old 486 laptop.
My **high school** was **"Liceo Scientifico Tullio Levi Civita"** (science and math).
Now I'm still studying **Computer Science** at **"Università La Sapienza"** in Rome. I should have already finished it, but I'm kind of a bad student. Everything I learn, I learn it by myself or working with inspiring people; but this do not help with exams. Then I've also spent **1 year** doing my **Erasmus** at **"Universidad de Las Palmas de Gran Canaria"**, this neither helps with exams, but being **able to live and work in a multicultural environment** has no price in my humble opinion.
I'm collaborating with **Eikona Photography and Digital Imaging** as a **Photographer**, **IT Specialist** and **Web Designer**