Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar
🚀
Extremely busy. Open source activity paused.

Artem Zakharchenko kettanaito

🚀
Extremely busy. Open source activity paused.
View GitHub Profile
@kettanaito
kettanaito / gatsby-config.js
Created March 18, 2020 10:36
Gatsby custom field resolver
// Importing this fails, as the plugin is distributed in modern module format
// and `gatsby-config.js` is not transpiled.
const firebase = require('gatsby-plugin-firebase')
exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
Query: {
customField: {
type: 'String',
resolve() {
@kettanaito
kettanaito / app.js
Created April 6, 2020 07:05
IE-specific bundle
if (__IE__) {
const ieSpecificShim = require('ie-shim')
ieSpecificShim(...)
}
@kettanaito
kettanaito / App.jsx
Created May 27, 2020 06:33
CSS Variables in Styled Components
import { createGlobalStyle, css } from 'styled-components'
const GlobalStyle = createGlobalStyle`
html {
/* Maps all colors from the `theme` to CSS variables: */
${({ theme }) => Object.entries(theme.colors).map(([name, value]) => css`
--${camelCaseToKebabCase(name)}: ${value};
`)}
}
`
@kettanaito
kettanaito / README.md
Created June 20, 2020 16:02
Working with remotes in Git

Working with multiple remotes

Adding a new remote

$ git remote add REMOTE_NAME REMOTE_URL

Verify that the new remote has been added by running git remote -v and seeing your REMOTE_NAME in the list.

I have a class called SocketPolyfill that looks roughly like this:

import { EventEmitter } from 'events'

export class SocketPolyfill extends EventEmitter {
	// methods here
}
@kettanaito
kettanaito / gql.d.ts
Last active October 27, 2020 16:17
Common TypeScript declarations
declare module '*.gql' {
import { DocumentNode } from 'graphql'
const vaule: DocumentNode
export default value
}
@kettanaito
kettanaito / compose.ts
Last active March 3, 2021 00:18
TypeScript snippets
// Source: https://medium.com/@minaluke/typescript-compose-function-b7512a7cc012
type ArityOneFn = (arg: any) => any
type PickLastInTuple<T extends any[]> = T extends [
...rest: infer U,
argn: infer L
]
? L
: never
type FirstFnParameterType<T extends any[]> = Parameters<PickLastInTuple<T>>[any]
type LastFnParameterType<T extends any[]> = ReturnType<T[0]>
@kettanaito
kettanaito / case.ts
Last active January 29, 2021 14:19
Response body retrieval
// Determine a body of the given Response.
// In case of a Response that has no body (i.e. 204 response),
// return `null`.
function getResponseBody(res: Response) {
res.body // ReadableStream, locked
await res.text() // always "" for a response with no body
}
// Empty string cannot be used as a response body
// for the responses that have no body (i.e. 204 response).
@kettanaito
kettanaito / getCompilationSource.ts
Last active February 9, 2021 17:23
Webpack – Get compilation source
import { createFsFromVolume, Volume } from 'memfs'
const fs = createFsFromVolume(new Volume())
const compiler = webpack({
entry: 'file.js',
output: { filename: 'main.js' }
})
// Compile the file to memory.
compiler.outputFileSystem = fs