Skip to content

Instantly share code, notes, and snippets.

@mpontus
mpontus / script.user.js
Last active August 9, 2020 10:32 — forked from alexkirsz/script.js
YouTube Player for edX
// ==UserScript==
// @name YouTube Player for edX
// @namespace morhaus
// @version 1.1
// @description Replace the default edX video player with the YouTube player
// @author Alexandre Kirszenberg <alexandre.kirszenberg@gmailcomr>
// @match https://courses.edx.org/*
// @match https://courses.ionisx.com/*
// @grant none
// ==/UserScript==
@mpontus
mpontus / mock.ts
Created August 7, 2020 15:24
Jest class mock
type JestMock<T extends (...args: any[]) => any> = jest.Mock<
ReturnType<T>,
Parameters<T>
>;
export type InstanceMock<T> = T &
{
[K in keyof T]: T[K] extends (...args: any[]) => any ? JestMock<T[K]> : T[K]
};
@mpontus
mpontus / copy-markdown-link.js
Last active July 29, 2020 18:06
Copy Page Link - bookmarklet to copy a link for the current page in markdown format
@mpontus
mpontus / tasks.json
Created April 5, 2020 22:48
VSCode task for running `cargo test` in watch mode
{
"version": "2.0.0",
"tasks": [
{
"label": "Run `cargo test` in watch mode",
"detail": "Requires \"cargo watch\" subcommand: https://github.com/passcod/cargo-watch",
"group": "test",
"type": "process",
"command": "cargo",
"args": ["watch", "-x", "test --no-fail-fast"],
@mpontus
mpontus / README.md
Created October 16, 2018 09:40
Flexbox centered, scrollable container

Not the first time I'm having this problem. This time I will document my solution for future reference.

Preface

The goal is to have root container (usually the #root container of the page), which centers its child element when the child is small enough to fit on the page. Otherwise, the container employs vertical scrollbar.

Solution

TL;DR: add margin: auto; on the child.

import React from "react";
import { StyleSheet, Text, View } from "react-native";
import SphericalMercator from "@mapbox/sphericalmercator";
import { MapView, Constants } from "expo";
const merc = new SphericalMercator();
const getZoomLevelFromRegion = (region, viewport) => {
const { longitudeDelta } = region;
const { width } = viewport;
@mpontus
mpontus / webpack.config.js
Created September 25, 2017 13:28
Storybook + CRA dotenv
// .storybook/webpack.config.js
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const dotenv = path.resolve(__dirname, '../.env');
const NODE_ENV = process.env.NODE_ENV || 'development';
const dotenvFiles = [
`${dotenv}.${NODE_ENV}.local`,
(defmacro ecukes-recurse-catch (symbols &rest body)
"Catch on entry to SYMBOLS during execution of BODY."
(letrec ((value (make-symbol "thrown-value"))
(function (lambda () (throw value nil)))
(fnsym (make-symbol "advice")) (unwind))
`(let ((,fnsym ,function))
,@(mapcar (lambda (symbol)
(prog1 `(advice-add ',symbol :override ,fnsym)
(push `(remove-advice ',symbol ,fnsym) unwind)))
(if (listp symbols) symbols (list symbols)))
(require 'dash)
(require 'color)
(let* ((hs (--map (/ (% (* 62 it) 100) 100.0) (number-sequence 1 18)))
(ss (number-sequence 0.0 1.0 0.2)) (ls (number-sequence .0 1.0 0.1))
(hsls (-table (lambda (a b c) (list a b c)) hs ss ls))
(sample (lambda (hex) (propertize " " 'face (cons 'background-color hex))))
(hsl2hex (-compose (-applify 'color-rgb-to-hex) (-applify 'color-hsl-to-rgb)))
(preview (lambda (lst) (mapconcat (-compose sample hsl2hex) (-flatten lst) "")))
(strs (-map (-partial '-map (-partial '-map (-compose sample hsl2hex))) hsls)))
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(--map
(insert (propertize (make-string 20 ?\s) 'font-lock-face
(cons 'background-color it)) ?\n)
(--map
(apply 'color-rgb-to-hex (color-hsl-to-rgb it 1 0.5))
(number-sequence 0.05 1.0 0.05)))