Skip to content

Instantly share code, notes, and snippets.

@pwm
pwm / openresty
Last active March 3, 2023 22:39
openresty init script
#!/bin/bash
#
# chkconfig: 2345 55 25
# description: Openresty
# processname: nginx
# config: /usr/local/openresty/nginx/conf/nginx.conf
# pidfile: /usr/local/openresty/nginx/logs/nginx.pid
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
@pwm
pwm / puml_to_svg.sh
Created March 4, 2016 14:33
Turning plantuml .puml files to .svg
#!/usr/bin/env bash
PUML_RELATIVE_WORKING_DIR="diagrams/"
PUML_BIN=$(which plantuml 2>/dev/null)
########
set -u # exit on unset var
set -e # exit on non-true return value
cd $(dirname ${BASH_SOURCE[0]})/.. # change to project root for relative paths
@pwm
pwm / es6_object_iter.js
Last active August 16, 2016 15:27
Useless stuff to help me remember some ES6 concepts
'use strict';
const Foo = (() => {
const params = new WeakMap();
class Foo {
constructor(bar, baz) {
params.set(this, {
'barKey': bar,
'bazKey': baz
@pwm
pwm / workspace.sh
Created September 29, 2016 17:03 — forked from scottsb/casesafe.sh
Create and manage a case-sensitive disk-image on OSX.
#!/bin/bash
# ---------------------------------------------------------
# Customizable Settings
# ---------------------------------------------------------
# where to store the sparse-image
WORKSPACE=${HOME}/.workspace.dmg.sparseimage
# location where workspace will be mounted
@pwm
pwm / functor.php
Last active November 25, 2016 20:48
My little explanation of what a functor is
<?php
// This would be a type class in Haskell.
// Any type that implements this interface/type class is a Functor.
interface Functor {
// map() takes a function and returns a Functor.
// The "Functor F" before the "=>" simply means that F implements Functor.
// map :: Functor F => (a -> b) -> F b
public function map(callable $fn);
}
@pwm
pwm / keynote-code-hl.fish
Last active December 16, 2016 15:46
Keynote - Fish function for copy&pasting highlighted code
# You will first need to install highlight:
# brew install highlight
function keynote-code-hl --argument-names 'syntax'
if test -n "$syntax"
pbpaste | highlight \
--syntax=$syntax \
--font Menlo \
--font-size 24 \
--style anotherdark \
--out-format rtf \
@pwm
pwm / keynote-latex.txt
Created December 16, 2016 15:51
Keynote - How to add math notation
1. Install MacTeX:
brew cask install Caskroom/cask/mactex
2. Download LaTeXiT:
https://www.chachatelier.fr/latexit/latexit-downloads.php?lang=en
3. Write LaTeX code, press "LaTeX it!" and copy&paste the result into Keynote.
@pwm
pwm / unfold_composition.php
Last active January 28, 2017 14:41
An example of how compose() unfolds
<?php
////////////////////////////////////////////////////////////////
// compose = foldl (.) id
////////////////////////////////////////////////////////////////
function curry(callable $fn, ...$args): \Closure {
return function (...$partialArgs) use ($fn, $args) {
$args = array_merge($args, $partialArgs);
$numRequiredArgs = (new \ReflectionFunction($fn))
@pwm
pwm / digraph.php
Created March 20, 2017 19:50
DIgraph
<?php
declare(strict_types = 1);
namespace FFW\Container;
class Digraph
{
public const SOURCE_VERTEX = 'Source Vertex';
/** @var string[][] */
@pwm
pwm / pure_iteration.php
Created May 10, 2017 19:56
Lifting out computation from iteration
<?php
declare(strict_types=1);
function uppercaseWordsImperative(array $words): void {
foreach ($words as $word) {
$word = strtoupper($word);
echo $word.' ';
}
}