Skip to content

Instantly share code, notes, and snippets.

@jukkatupamaki
jukkatupamaki / knex-pg-check.md
Last active January 18, 2022 21:43
How to use check constraints with Knex.js and Postgres

How to use check constraints with Knex.js and Postgres

Check constraints are useful for validating INSERT and UPDATE queries. With Knex.js, you have to use raw calls to add or drop constraints.

Add a constraint to check that my_column in my_table is at least 0:

knex.schema.raw(`
  ALTER TABLE
    my_table
 ADD CONSTRAINT
@shuhei
shuhei / headers-timeout-keep-alive.js
Created April 28, 2019 18:08
A test case for server.headersTimeout + keep alive (fails on Node v10.15.2 and newer)
const http = require("http");
const net = require("net");
const server = http.createServer((req, res) => {
req.resume();
res.end("hello");
});
server.keepAliveTimeout = 6 * 1000;
server.headersTimeout = 4 * 1000;
@ryzokuken
ryzokuken / merkle.js
Last active July 30, 2022 15:57
TypeScript Merkle Tree Implementation
const hash = require('easy-crypto/hash');
class MerkleTreeNodeGeneric {
compare(node) {
return this.hash === node.hash;
}
}
class MerkleTreeChildNode extends MerkleTreeNodeGeneric {
constructor(data) {
@threepointone
threepointone / for-snook.md
Last active August 26, 2023 15:43
For Snook

https://twitter.com/snookca/status/1073299331262889984?s=21

‪“‬In what way is JS any more maintainable than CSS? How does writing CSS in JS make it any more maintainable?”

‪Happy to chat about this. There’s an obvious disclaimer that there’s a cost to css-in-js solutions, but that cost is paid specifically for the benefits it brings; as such it’s useful for some usecases, and not meant as a replacement for all workflows. ‬

‪(These conversations always get heated on twitter, so please believe that I’m here to converse, not to convince. In return, I promise to listen to you too and change my opinions; I’ve had mad respect for you for years and would consider your feedback a gift. Also, some of the stuff I’m writing might seem obvious to you; I’m not trying to tell you if all people of some of the details, but it might be useful to someone else who bumps into this who doesn’t have context)‬

So the big deal about css-in-js (cij) is selectors.

@Icelandjack
Icelandjack / Yoneda.markdown
Last active February 10, 2023 00:06
Yoneda
import Data.Functor.Yoneda
import Data.Char
import Data.Kind

infixr 5
  ·

type  List :: (Type -> Type) -> Constraint
class List f where
@Icelandjack
Icelandjack / Notation.markdown
Last active July 6, 2019 18:37
Notes on Notation

Non-standard operators I use :) linked to from my twitter profile

I use kind synonyms

type T   = Type
type TT  = T -> T
type TTT = T -> TT
type C   = Constraint
type TC  = T -> C

gif-from-tweet

There are so many great GIFs out there and I want to have copies of them. Twitter makes that harder than it should be by converting them to MP4 and not providing access to the source material. To make it easier, I made a bash pipeline that takes a tweet URL and a filename, extracts the MP4 from that tweet and uses ffmpeg to convert back to GIF.

Dependencies

  • ffmpeg
    • macOS: brew install ffmpeg
    • Ubuntu/Debian: apt install ffmpeg
@fstanis
fstanis / upspin-drive-guide.md
Last active July 3, 2024 05:52
Upspin server backed by Google Drive on a Raspberry Pi

Set up an Upspin server backed by Google Drive

Overview

The purpose of this document is to explain how to deploy an Upspin server on a Debian or Ubuntu based machine - which can be a Raspberry Pi - and, optionally, use Google Drive to back the data.

Effectively, this will give you all the nifty advantages Upspin gives you in terms of file sharing without requiring a costly server.

Requirements

@ebidel
ebidel / monitor_internet_connection.js
Last active February 28, 2018 18:32
Puppeteer: monitor status of internet connectivity using headless Chrome
Moved to https://github.com/ebidel/puppeteer-examples/blob/master/monitor_internet_connection.js
@mrry
mrry / tensorflow_self_check.py
Last active August 24, 2023 17:13
[DEPRECATED] TensorFlow on Windows self-check
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,