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 / early-init.el
Last active October 29, 2024 23:39
.emacs.d
;;; Package --- Summary -*- lexical-binding: t; -*-
;;; variables
(defvar enable-debug-p nil
"non-nil to enable debug.")
;;; garbage collection
;; garbage collection significantly affects startup times. this setting delays
;; garbage collection during startup but will be reset later.
@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 <[email protected]>
;; 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
*/