Skip to content

Instantly share code, notes, and snippets.

View vnglst's full-sized avatar
💭
Building 🪲

Koen van Gilst vnglst

💭
Building 🪲
View GitHub Profile
async function validatePassword(password: string): string[] {
let errors = []
// 1. Don't regex for things you can trivially express in code
// -----------------------------------------------------------
// For example, we could have written this as `/^.{0,7}$/` but that's not
// nearly as clear as checking the length of the string.
if (password.length < 8) {
errors.push("Password must be at least 8 characters long")
@antony
antony / bash.sh
Last active February 8, 2022 01:36
Auth0 SSR Compatible Integration with Sapper
npm install --save express express-openid-connect
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@mayel
mayel / up
Last active January 2, 2022 01:11
up: script to keep your Mac up-to-date (both OS and Homebrew updates) via the command line
replaced by https://gist.github.com/mayel/c07bc0acb91824501d5bdbdc9eb7b33a
@wojteklu
wojteklu / clean_code.md
Last active April 19, 2024 18:00
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@thevangelist
thevangelist / my-component.spec.js
Created August 4, 2016 13:06
The only React.js component test you'll ever need (Enzyme + Chai)
import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from '../src/my-component';
const wrapper = shallow(<MyComponent/>);
describe('(Component) MyComponent', () => {
it('renders without exploding', () => {
expect(wrapper).to.have.length(1);
});
@thomasm0
thomasm0 / countries.json
Last active March 25, 2021 14:27
ISO 3166-1 Country List in Dutch / ISO 3166-1 Landen lijst in Nederlands JSON
[
{
"name": "Afghanistan",
"short_name": "AF",
"calling_code": "93"
},
{
"name": "Åland",
"short_name": "AX",
"calling_code": "358"
@mjackson
mjackson / createBinding.js
Last active September 18, 2021 09:19
A workaround for the lack of a promise cancelation API
/**
* Registers the given callback to be called in the node.js callback
* style, with error as the first argument, when the promise resolves.
*
* Also, returns a function that may be used to prevent the callback
* from ever being called. Calling the returned function is synonymous
* with saying "I no longer care about the resolution of this promise,
* even if it fails."
*
* Since there is no provision in the promise spec for cancel/abort
// A Unit test template for Tape
// See 5 Questions every unit test must answer:
// https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d
import test from 'tape';
test('What are you testing?', assert => {
const msg = 'what should it do?'
const actual = 'what was the output?';
this.ycQuestions = [
"So what are you working on?",
"Have you raised funding?",
"What makes new users try you?",
"What competition do you fear most?",
"What’s the worst thing that has happened?",
"Will you reincorporate as a US company?",
"What’s an impressive thing you have done?",
"Where is the rocket science here?",
"Why did you pick this idea to work on?",