Skip to content

Instantly share code, notes, and snippets.

View Kashkovsky's full-sized avatar
😎

Denys Kashkovskyi Kashkovsky

😎
  • Grammarly, Inc.
  • Kyiv, Ukraine
View GitHub Profile
@Kashkovsky
Kashkovsky / launch.json
Created July 18, 2018 17:04
Debug typescript jest tests in VS Code
/** .vscode/launch.json */
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": [
@Kashkovsky
Kashkovsky / mount_share_cert.sh
Created August 6, 2018 17:56
Mount SMB share and import certificate if it is newer than the installed one
#!/bin/bash
# Define keychain
kc="/users/$USER/Library/Keychains/login.keychain"
# Open SMB share
open smb://$USER@<domain.com>/fs/users/$USER
sleep 5
# Parse password from csv file in share
pwd=$(cat "/Volumes/$USER/$USER.csv" | awk -F';' '! /"Password"/ {print $2}' | cut -d "\"" -f 2)
# Find existing certificate
c=$(echo "security find-certificate -c $USER.<domain.com>")
@Kashkovsky
Kashkovsky / useSafeState.ts
Created August 21, 2019 15:27
useSafeState
import { useState, useEffect, useCallback } from "react";
const useSafeState = <T>(initialValue: T): [T, (value: T) => void] => {
let mounted = true;
const [current, setCurrent] = useState(initialValue);
useEffect(() => () => (mounted = false), []);
const setter = useCallback((value: T) => mounted && setCurrent(value), [mounted]);
return [current, setter];
}
@Kashkovsky
Kashkovsky / useSafeState.ts
Last active August 21, 2019 15:28
useSafeState
import { useState, useEffect, useCallback } from "react";
const useSafeState = <T>(initialValue?: T): [T, (value: T) => void] => {
let mounted = true;
const [current, setCurrent] = useState(initialValue);
useEffect(() => () => (mounted = false), []);
const setter = useCallback((value: T) => mounted && setCurrent(value), [mounted]);
return [current, setter];
}