Skip to content

Instantly share code, notes, and snippets.

@aschmoe
aschmoe / convertTypesToProps.mjs
Created August 25, 2023 22:42
Script example for typescript-to-proptypes
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import glob from 'glob';
import prettier from 'prettier';
import rimraf from 'rimraf';
import * as ttp from 'typescript-to-proptypes';
/**
* Creates needed directories for a file path
@ciiqr
ciiqr / zod-optional-null.ts
Last active June 18, 2024 13:47
zod optional/nullable/nullish differences
// zod schema
z.object({
// valid if string or:
optional: z.string().optional(), // field not provided, or explicitly `undefined`
nullable: z.string().nullable(), // field explicitly `null`
nullish: z.string().nullish(), // field not provided, explicitly `null`, or explicitly `undefined`
});
// type
{
@r17x
r17x / setupTest.md
Last active April 22, 2019 11:34
Setup Test in ReactJs With Jest Enzyme & etc
  • create setupTests.js in src/setupTests.js (automatically CRA read setupTest.js)
// setupTests.js
import React from "react";
import Adapter from "enzyme-adapter-react-16";
import Enzyme, { configure, shallow, mount, render } from "enzyme";
import { createSerializer } from "enzyme-to-json";
import sinon from "sinon";

expect.addSnapshotSerializer(createSerializer({ mode: "deep" }));
@cdleon
cdleon / macbook-pro-2011-defective-gpu-fix.md
Last active June 3, 2024 16:56
Macbook Pro 2011 GPU Defect fix macOS Sierra and High Sierra
@blackgate
blackgate / mbp2011-disable-amd-gpu.md
Last active November 22, 2023 01:23
Macbook Pro 2011 - Disable AMD GPU
@robinvdvleuten
robinvdvleuten / CorsListener.php
Created September 11, 2017 11:39 — forked from frodosghost/CorsListener.php
CORS Listener and Handling with Symfony2
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
@scokmen
scokmen / HttpStatusCode.ts
Created April 25, 2017 11:10
Typescript Http Status Codes Enum
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
@fokusferit
fokusferit / enzyme_render_diffs.md
Last active June 18, 2024 11:27
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨