Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
sindresorhus / esm-package.md
Last active April 24, 2024 09:47
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@sschizas
sschizas / DoHConfigurarion.swift
Created December 23, 2020 20:03
DNS-over-HTTPS (DoH) configuration enumeration to be used in `NWParameters.PrivacyContext`.
enum DoHConfigurarion: Hashable {
case adGuard
case alibaba
case cloudflare
case google
case openDNS
case quad9
var httpsURL: URL {
switch self {
@ClickerMonkey
ClickerMonkey / types.ts
Last active February 6, 2024 07:21
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
@iridiumcao
iridiumcao / check_git_branch_exists.sh
Created March 22, 2020 13:57
How to check if a git branch exists in the local/remote repository?
# Local:
# https://stackoverflow.com/questions/21151178/shell-script-to-check-if-specified-git-branch-exists
# test if the branch is in the local repository.
# return 1 if the branch exists in the local, or 0 if not.
function is_in_local() {
local branch=${1}
local existed_in_local=$(git branch --list ${branch})
if [[ -z ${existed_in_local} ]]; then
echo 0
@bseib
bseib / README.md
Last active November 24, 2023 17:08
Webpack + JSP

Webpack + JSP

These snippets were created after reading the following article on how to use webpack to build code bundles for individual JSP pages, and specifically how to get those JSP pages to refer to the correct filename + hash.

https://medium.com/@jsilvax/introducing-webpack-into-an-existing-java-based-web-app-ff53f14d37ec

There was no actual code, but the description of the approach was enough to put something together. jsilvax just posted some code here: https://medium.com/p/510d859b9f36/responses/show

@osv
osv / formikGotoErrorOnSubmitEffect.tsx
Last active March 4, 2019 07:24
React Formik, scroll to first element in DOM that is not valid and has error (Hook + Typescript version)
import { connect, FormikContext, getIn } from 'formik';
import * as React from 'react';
import { useEffectWhenCountIncremented } from './reactHooks';
import { PageContext } from './context';
const FormikGotoErrorOnSubmitEffectFn: React.FunctionComponent<{
formik?: FormikContext<any>;
}> = ({ formik }) => {
@damienlaughton
damienlaughton / UIAccessorizedTextField.swift
Created March 28, 2018 15:16
UIAccessorizedTextField is an iOS friendly alternative to the drop down list
//
// UIAccessorizedTextField.swift
// AccessorizedTextField
//
// Created by Damien Laughton on 28/03/2018.
// 2018 Mobilology Limited. No rights reserved.
//
import Foundation
import UIKit
@hongrich
hongrich / gist:260fc8c36aaed3f2a63c0612ba9fc910
Last active June 3, 2019 20:29
App Store Review Guidelines
App Store Review Guidelines
Introduction
Apps are changing the world, enriching people’s lives, and enabling developers like you to innovate like never before. As a result, the App Store has grown into an exciting and vibrant ecosystem for millions of developers and more than a billion users. Whether you are a first time developer or a large team of experienced programmers, we are excited that you are creating apps for the App Store and want to help you understand our guidelines so you can be confident your app will get through the review process quickly.
The guiding principle of the App Store is simple - we want to provide a safe experience for users to get apps and a great opportunity for all developers to be successful. We do this by offering a highly curated App Store where every app is reviewed by experts and an editorial team helps users discover new apps every day. For everything else there is always the open Internet. If the App Store model and guidelines are not best for your app or business idea th
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 21, 2024 09:43
Swift Concurrency Manifesto
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.