Skip to content

Instantly share code, notes, and snippets.

@cmaas
cmaas / 2023-09-27 How to use Tape with TypeScript and ESM.md
Created September 27, 2023 19:45
I write stuff in TypeScript and used Tape as a test runner. After converting my project to use ECMAScript modules (ESM), tape stopped working, causing quite a bit of headache.

2023-09-27 How to use Tape with TypeScript and ESM

I write stuff in TypeScript and used Tape as a test runner. After converting my project to use ECMAScript modules (ESM), tape stopped working, causing quite a bit of headache.

Goals

  • Write tests in TypeScript. Tests live next to source files.
  • Do not compile tests to the dist directory.
  • Use ts-node to transpile tests on the fly and use tape as the test runner.
@cmaas
cmaas / 11ty-related-posts-filter.md
Last active August 16, 2022 13:56
11ty: show related articles in a sorted way

2021-06-13 Lessons Learned from Journaling for 13 years

tl;dr: Start writing mundane things down, don't obsess over structure or words, reduce friction, let it unfold over the years, have no expectations about therapeutic effects or whatever.


  • I started journaling around 2008.
  • I almost never read in my journal and when I do, I sometimes cringe, and sometimes I'm surprised what aspect of myself stayed the same.
  • Journaling didn't change my life, but I think it's a good thing. I'm a forward-looking guy, not too obsesses with the past. These days, I mostly note down development steps of my kids. That is the current goal: Being able to tell my kids how they were when they were little, what we did. It's crazy how I can't even remember small things when my first son was born.
@cmaas
cmaas / 2021-06-13 Zettelkasten Simplified.md
Created June 13, 2021 13:36
I think the Zettelkasten method is a good idea, but Zettelkasten.de is incredibly verbose to explain a simple note-taking approach. Here's my summary and my *process*.

2021-06-13 Zettelkasten Simplified

I think the Zettelkasten method is a good idea, but Zettelkasten.de is incredibly verbose to explain a simple note-taking approach. Here's my summary and my process.

Two modes of organization

Be aware of this concept:

  • Spend more time on organizing and less time on information retrieval. Good for notes you need to refer often to. Nothing for me actually. I write maybe 3-5 notes per day at most.
  • Spend less time on organizing infos and more time on retrieval. Good when you don't need the info often (or at all). Example: Letters, tax statements, emails, whatever. Just dump them all in a folder in a chronological order and if you ever need to find something, search for it, although this might take a bit longer.
@cmaas
cmaas / laravel-update-mysql-datetime.md
Created January 29, 2015 15:24
Laravel 4 – Update MySQL DATETIME field and increase value with DATE_ADD

Update MySQL DATETIME field and increase value with DATE_ADD

You can update a MySQL DATETIME field in Laravel with Eloquent like so:

DB::table('users')
    ->where('id', $user_id)
    ->update(array('valid_until' => DB::raw('DATE_ADD(valid_until, INTERVAL 1 MONTH)')));
@cmaas
cmaas / basic.html
Last active February 3, 2021 15:55
HTML5 Page Templates: Basic & Social
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="css/style.css">
<link rel="icon" type="image/png" href="favicon.png">
</head>
@cmaas
cmaas / CastsValueObject.php
Last active March 21, 2020 12:56
A Trait to automatically cast value objects in Laravel without needing a Mutator and an Accessor.
<?php
trait CastsValueObjects
{
protected function castAttribute($key, $value)
{
$castToClass = $this->getValueObjectCastType($key);
// no Value Object? simply pass this up to the parent
if (!$castToClass) {
return parent::castAttribute($key, $value);
@cmaas
cmaas / code-entry.tsx
Last active January 21, 2020 11:33
Simple StencilJS component to show a code entry for an app lock screen. Requires @ionic/core for UI
import { Component, Event, EventEmitter, Prop, State, h } from '@stencil/core';
/*
Requires @ionic/core for the UI.
CSS shake animation by Sarah Drashner to place whereever you want,
taken from https://css-tricks.com/snippets/css/shake-css-keyframe-animation/
.shake-animation {
animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
@cmaas
cmaas / phpbb-login-by-email.md
Last active June 25, 2019 08:42
PHPBB3: Login by email and authenticate at ACP

PhpBB3: Login by email and re-authenticate at ACP

I made a custom auth provider that accepts the email as username. However, if you try to login to the ACP, you get this error:

You are not able to re-authenticate as a different user.

The problem causing this is in the file includes/functions.php. When you re-authenticate for the ACP, the provided username is compared with the user data (around line 2358):

// Check if the supplied username is equal to the one stored within the database if re-authenticating
@cmaas
cmaas / laravel-value-object.md
Last active October 24, 2017 10:25
Laravel: Basic Value Object

Laravel: Basic Value Object

If you want to enforce certain values in your models, you can use simple value objects for this job. This class helps to reuse some of the logic:

/**
 * Representation of a simple value object with a single attribute that should be validated
 *
 * @package Demo
 */