Skip to content

Instantly share code, notes, and snippets.

(cl-defun test (&key bar)
(message "bar: %s" bar))
(test :bar 'qwe)
;; "bar: qwe"
(cl-defun test (&rest foo &key bar)
(message "foo: %s bar: %s" foo bar))
(test 'qwe :bar 'asd)
;; (error "Keyword argument qwe not one of (:bar)")
;; -*- lexical-binding: t; -*-
(defun test9 ()
(let ((a '(10)))
(setcar a (* 2 (car a)))
a))
(test9) ; 20
(test9) ; 40
(test9) ; 80
(defun display-buffer-above-selected (buffer alist)
"Try displaying BUFFER in a window below the selected window.
This either splits the selected window or reuses the window below
the selected one."
(let (window)
(or (and (setq window (window-in-direction 'above))
(eq buffer (window-buffer window))
(window--display-buffer buffer window 'reuse alist))
(and (not (frame-parameter nil 'unsplittable))
(let ((split-height-threshold 0)
(defun display-buffer-above-selected (buffer alist)
"Try displaying BUFFER in a window below the selected window.
This either splits the selected window or reuses the window below
the selected one."
(let (window)
(or (and (setq window (window-in-direction 'above))
(eq buffer (window-buffer window))
(window--display-buffer buffer window 'reuse alist))
(and (not (frame-parameter nil 'unsplittable))
(let ((split-height-threshold 0)
;; 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)))
(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)))
(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)))
@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`,
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 / 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.