Skip to content

Instantly share code, notes, and snippets.

@rw3iss
rw3iss / getInnerError.ts
Created August 9, 2022 03:22
getInnerError
// Finds the inner most
export const getInnerError = (e) => {
const _getInner = (_e) => {
if (!_e) return undefined;
if (typeof _e == 'string') return _e;
return _getInner(_e.error) || _getInner(_e.data) || _getInner(_e.response) || _getInner(_e.message);
};
return _getInner(e) || 'Unknown error.';
@rw3iss
rw3iss / cpp.snippets.json
Last active April 12, 2024 00:50
snippets.json
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Generate class header": {
"prefix": "cls",
"body": [
"#pragma once",
@rw3iss
rw3iss / settings.json
Last active April 12, 2024 00:50
settings.json
{
"window.title": "${dirty} ${folderPath} 💠 ${activeEditorMedium} 🔷 ${rootName} ",
"explorer.autoReveal": true,
"explorer.autoCollapse": false,
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"explorer.compactFolders": true,
"workbench.layoutControl.enabled": true,
"workbench.list.smoothScrolling": true,
//"workbench.list.mouseWheelScrollSensitivity": ".2", // mac
@rw3iss
rw3iss / GoogleAnalyticsService.ts
Created June 25, 2022 18:30
GA4 Google Analytics Class
/**
* @author pybymantis@gmail.com (Daniel Kennedy)
* @copyright Copyright (c) 2021, AdCloud
* @description GoogleAnalyticsService
*/
// https://support.google.com/analytics/answer/9213390?hl=en&utm_id=ad#zippy=%2Cin-this-article
// https://www.npmjs.com/package/ga-4-react
// ga4.gtag('event','pageview','path')
@rw3iss
rw3iss / useJitRef.js
Created December 1, 2021 04:44
useJitRef.js
const none = {};
export function useJitRef(init) {
const value = useRef(none);
const ref = useLazyRef(() => ({
get current() {
if (value.current === none) {
value.current = init();
}
return value.current;
},
@rw3iss
rw3iss / useScrollDirection.js
Created November 24, 2021 02:00
useScrollDirection.js
import { useEffect, useRef, useState } from 'react';
export function useScrollDirection(element = window) {
const prevScrollY = useRef(0)
const [goingUp, setGoingUp] = useState(false);
const handleScroll = () => {
const currentScrollY = element.scrollTop;
if (prevScrollY.current < currentScrollY && goingUp) {
setGoingUp(false);
@rw3iss
rw3iss / logging.js
Last active December 16, 2021 01:14
Logging by namespace
/* Usage:
import { getLogger } from 'lib/utils/logging';
const log = getLogger('somename').log;
log('something');
*/
let loggers = {};
// retrieve a logger by name.
export const getLogger = function(namespace = '', color = DEFAULT_LOG_COLOR, enabled = true) {
@rw3iss
rw3iss / package.json
Created June 10, 2021 03:50
nodemon node server restarting
"dev": "nodemon --signal SIGTERM --watch './src/**/*' -e ts,js,json,env --exec \"npm run restart\"",
restart.sh:
node build/index.js --no-deprecation --no-warnings --trace-deprecation
@rw3iss
rw3iss / index.tsx
Created May 29, 2021 01:57
MobileComponent
import React, { useEffect, useState } from 'react';
import { isMobile } from 'lib/utils/UiUtils';
// Dynamic component which rendered a different child depending on mobile vs. desktop.
// Will re-render upon resize state change.
export default MobileComponent = ({ component: Component, ...props }) => {
const [currIsMobile, setIsMobile] = useState(isMobile());
useEffect(() => {
window.addEventListener('resize', (e) => {
@rw3iss
rw3iss / package.json
Last active April 20, 2021 16:30
npm scripts
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "build/index.js",
"scripts": {
"setup": "npm install",
"serve": "node build/index.js",
"dev": "concurrently --kill-others \"npm run build-watcher\" \"npm run build-reload\"",
"build-watcher": "nodemon --watch './src/**/*' -e ts,tsx,js,jsx,scss,html,json,env --exec \"npm run build\"",