Skip to content

Instantly share code, notes, and snippets.

@sketchbuch
sketchbuch / my-reducer.js
Last active January 25, 2020 07:24
JS - My own version of array.reduce - based on a video by MPJ (FunFunFunction)
const numbers = [1, 2, 3]
const result = numbers.reduce((acc, cur) => acc += cur, 0)
result //?
const summr = (total, addition) => total + addition
const myReducer = (reducerFunc, initialValue, arr) => {
let accumilation = initialValue
@sketchbuch
sketchbuch / ssh-notes-mac.txt
Last active January 24, 2020 07:02
SSH related commands on a Mac
These notes are for mac os.
Config File
===========
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/name of key
@sketchbuch
sketchbuch / bash-aliases.txt
Last active June 2, 2020 16:07
BASH - Snippets (Ubuntu)
###########
# Aliases #
###########
alias cra='create-react-app'
@sketchbuch
sketchbuch / jest-mock-react-i18next.ts
Last active January 24, 2020 07:05
TESTING - Jest mock translate for jest / react-i18next with components
import { translate } from 'react-i18next'
jest.mock('react-i18next', () => ({
t: (key: string) => key,
translate: () => Component => {
Component.defaultProps = { ...Component.defaultProps, t: () => '' }
return Component
},
}))
@sketchbuch
sketchbuch / flutter-coomands.txt
Last active January 24, 2020 07:05
FLUTTER - Commands Reference
Clear device caches:
===================
> flutter clean
Get packages
============
> flutter pub get
@sketchbuch
sketchbuch / mock-window-properties-jest.js
Last active January 24, 2020 07:06
TESTING - How to mock window properties in Jest
// Store original value to set back after tests
const previousInnerWidth = window.innerWidth
Object.defineProperty(window, 'innerWidth', {
configurable: true,
value: 400,
writable: true,
})
@sketchbuch
sketchbuch / typescript-sytled-components.ts
Last active January 24, 2020 07:06
TS - Typescript Types For Styled Components
export const StyledImg = styled.img<StyledImgProps>`
position: relative;
`
// Overriding a styled component's styles
export const StyledIcon = styled(Img)<StyledIconProps>`
position: relative;
`
@sketchbuch
sketchbuch / vsc-extension-use-view-when-condition.js
Last active January 24, 2020 07:07
VSC - An example of how to control visibility of a view container's views in a VSC Extension
// Update the value used by a view's "when" condition
// Can't use in getChildren()
vscode.commands.executeCommand('setContext', someContextVar, isVisibleBoolean);
// Package.json
/*
...
"views": {
@sketchbuch
sketchbuch / vsc-extension-detect-active-editor-language-change.js
Last active January 24, 2020 07:09
VSC - How to detect a change of the langauge used by the active editor in a VSC Extension
// Called when active editor language is changed:
// After the active editor language changes the content is "re-opened" so just listen for the open event
// And check the lang of the active editor
vscode.workspace.onDidOpenTextDocument(() => {
const editor = vscode.window.activeTextEditor
if (editor !== undefined) {
const {
document: { languageId },
} = editor;
@sketchbuch
sketchbuch / example-typescript-predicate-type-guard.ts
Last active January 24, 2020 07:04
TS - Typescript example of a Predicate Type Guard
export interfac-e NpmContributors {
email?: string;
githubUsername?: string;
name: string;
url?: string;
}
export interface NpmMaintainer {
email: string;