Skip to content

Instantly share code, notes, and snippets.

@DouglasdeMoura
DouglasdeMoura / api.ts
Last active April 1, 2024 15:00
Tiny wrapper around fetch
// Extends the return of the HTTPError class
class HTTPError extends Error {
readonly response: any;
readonly status: number;
readonly statusText: string;
constructor(status: number, statusText: string, response: any) {
super(statusText);
this.status = status;
this.statusText = statusText;
@odbol
odbol / Deferred.ts
Created August 4, 2022 23:06
Deferred: a Promise that you can resolve or reject after the fact.
/**
* A Promise that you can resolve or reject after the fact.
*/
export class Deferred<T> {
private _resolve?: (result: T) => void;
private _reject?: (error: Error) => void;
promise: Promise<T>;
constructor() {
this.promise = new Promise((resolve, reject) => {
@danpetitt
danpetitt / nvmuse.md
Last active May 28, 2024 20:42
Using nvmrc on Windows

Using nvmrc on Windows

Unfortunately nvm use on Windows does not change the node version to that specified in the .nvmrc file as its not supported on nvm for Windows: coreybutler/nvm-windows#388

So the easiest solution to this is to use a simple Powershell command that performs an approximation of the command as follows: nvm use $(Get-Content .nvmrc).replace( 'v', '' );

However, thats a bit awkward and we can do a bit more so instead, we can create an 'alias' to a function that calls the command instead:

function callnvm() {
@kmelve
kmelve / schemas.js
Last active February 23, 2024 01:27
Super simple galleries on Sanity.io
/*
$ sanity init
# Follow steps, choose the clean template
# go to schemas/schema.js and paste this in
*/
// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator'
@kmelve
kmelve / Image.css
Created October 11, 2019 15:07
Lazyload Images from Sanity.io
.root {
display: block;
position: relative;
}
.lqip {
image-rendering: pixelated;
width: 100%;
opacity: 1;
transition: opacity 50ms 100ms ease-out;
@simon360
simon360 / check-packages.js
Created April 20, 2018 11:58
Compare different package.json files in a monorepo to see if dependency versions differ
const chalk = require("chalk");
const packages = [
require("./package.json"),
require("./packages/cec-scripts/package.json"),
require("./packages/generator-cec/package.json"),
require("./packages/utility-cec-simulator/package.json")
];
const compareDeps = p => {
@WebMaestroFr
WebMaestroFr / Group.css
Last active January 16, 2022 08:22
Slide Up and Down with React Transition Group
.Group-item,
.Group-item.ui,
.Group-item.ui:first-child {
display: block;
margin-top: 1em;
}
.Group-item-enter.Group-item-enter-active {
transition: opacity 300ms ease-in, margin 300ms ease-out;
}
@ArnaudValensi
ArnaudValensi / create-ssl-cert.sh
Created January 9, 2018 09:39
Generate a self signed certificate without passphrase for private key
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 10000 -nodes
@filipelenfers
filipelenfers / .hyper.js
Created January 5, 2018 13:05
Hyper.js using Zsh on Windows with WSL
//I like to use zsh(with oh-my-zsh) as my default shell.
//First define your default distro for wsl
//run this on cmd.exe
//wslconfig /l
//wslconfig /s Ubuntu
//use this options on preferences of Hyper.js termina to use it as default.
{
shell: 'C:\\Windows\\System32\\bash.exe',
@geraldvillorente
geraldvillorente / import.md
Created June 14, 2017 05:03
How to import database in MySQL in Docker?

This is a simple way of importing MySQL database in Docker.

  1. In you Dockerfile you must have a shared folder. Shared folder is a directory in your host machine that is mounted to Docker instance.

  2. Put the exported sql file in the shared folder.

  3. Login to your Docker instance via docker exec -it DOCKER_CONTAINER_ID bin/bash.

  4. Login to MySQL via mysql -u USERNAME -p.