Skip to content

Instantly share code, notes, and snippets.

View httpJunkie's full-sized avatar
🏠
Working from home

Eric Bishard httpJunkie

🏠
Working from home
View GitHub Profile
@httpJunkie
httpJunkie / useSwitchNetwork.ts
Created October 18, 2023 19:50
React Hook (JavaScript/TypeScript) that Switches MetaMask user to desired Ethereum chain
import * as contractAbi from '~/lib/contract-abis/MyCOntract.json'
export const config = {
// This config assumes you have access to an ABI like we have imported above
'0x13881': {
name: 'Mumbai',
contractAddress: contractAbi.networks[Number('0x13881')]?.address,
symbol: 'MATIC',
blockExplorer: 'https://mumbai.polygonscan.com',
rpcUrl: 'https://rpc-mumbai.maticvigil.com',
},
@httpJunkie
httpJunkie / switchAddnetwork.js
Last active July 15, 2022 16:17
Switch and or Add a network in MetaMask
try {
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xf00' }],
});
} catch (switchError) {
// This error code indicates that the chain has not been added to MetaMask.
if (switchError.code === 4902 || switchError?.data?.orginalError?.code === 4902) {
try {
await ethereum.request({
@httpJunkie
httpJunkie / std-margin-and-padding-input.scss
Last active March 16, 2022 14:10
Standard margin and padding loop with Sass
$amounts: (5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 75, 100);
$sides: (top, right, bottom, left);
@each $space in $amounts {
@each $side in $sides {
.margin-#{$side}-#{$space} {
margin-#{$side}: #{$space}px !important;
}
.padding-#{$side}-#{$space} {
@httpJunkie
httpJunkie / seg.txt
Created December 6, 2021 23:31
segfault
ericbishard@RMML0522 travel-api % DEBUG=* ts-node src/index.ts
express:router:route new '/' +0ms
express:router:layer new '/' +2ms
express:router:route get '/' +1ms
express:router:layer new '/' +0ms
express:router:route new '/:id' +0ms
express:router:layer new '/:id' +0ms
express:router:route get '/:id' +0ms
express:router:layer new '/' +0ms
express:router:route new '/' +0ms
@httpJunkie
httpJunkie / install-nvm-mac-m1.md
Last active November 22, 2021 00:09
Install Node/NVM on Mac M1

As a web developer these days, we typically need to be able to switch versions of Node on the fly, for this we want to install Node Version Manager on a clean install of our machine, we don't want to start by installin Node on it's own as this will give us a single version of Node (whichever we decide to install)

If you install Node first and then try to install NVM, things can get complicated, so if you have already installed Node, my suggestion is to completely remove it before installing NVM.

As well, NVM is explicitly not supported when installed via homebrew - the only correct way to install it is with the install script in NVM's Readme.

So if you have a brand new Mac M1 these are the steps you need to go through.

  1. Navigate to your home directory
@httpJunkie
httpJunkie / gist:25179edfb81301add1aeb5b977f65176
Last active March 31, 2021 18:16
Docker Instance for Couchbase latest
docker pull couchbase
docker run -d --name cblatest -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase
@httpJunkie
httpJunkie / couchbase-javascript-developer-resource.md
Last active August 26, 2020 17:41
Couchbase JavaScript Developer Resource
@httpJunkie
httpJunkie / useWindowSizeWithDebounce.js
Last active August 14, 2020 13:16
useWindowSizeWithDebounce
import { useEffect, useState } from 'react';
const debounce = (delay: number, fn: any) => {
let timerId: any;
return function (...args: any[]) {
if (timerId) {
clearTimeout(timerId);
}
@httpJunkie
httpJunkie / useLocalStorageState.js
Last active May 14, 2020 11:00
useLocalStorageState
/* https://stackblitz.com/edit/use-local-storage-state */
function useLocalStorageState(key, defaultValue) {
const [state, setState] = useState(() => {
let value
try {
value = JSON.parse(
window.localStorage.getItem('my-app-count') || JSON.stringify(defaultValue)
)
} catch (e) {
@httpJunkie
httpJunkie / new-gatsby-novela-site
Last active April 12, 2020 19:48
Create Gatsby Novela site from scratch
# Setting Up a New Gatsby Novela Themed Site
This is a step-by-step unstructional on how to set up The Novela Gatsby theme by Narative for your own blog or website.
## Prerequisites
- GitHub Account/Repo
- Git installed
- Node installed
- An editing environment (VS Code)