Skip to content

Instantly share code, notes, and snippets.

View johnrjj's full-sized avatar
😶‍🌫️
probably writing code

John Johnson johnrjj

😶‍🌫️
probably writing code
View GitHub Profile
@johnrjj
johnrjj / mosh-launcher.sh
Created June 30, 2025 13:02
mosh-server workaround on mac osx
#!/bin/bash
# File location: ~/bin/mosh-launcher.sh
# --- Set the PATH for Homebrew ---
eval "$(/opt/homebrew/bin/brew shellenv)"
# --- Set the Locale for UTF-8 ---
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# --- Execute the real mosh-server ---
@johnrjj
johnrjj / backend.js
Created May 17, 2023 17:04
sign in with ethereum wallet via siwe
import cors from 'cors';
import express from 'express';
import Session from 'express-session';
import { generateNonce, SiweMessage } from 'siwe';
const app = express();
app.use(express.json());
app.use(cors({
origin: 'http://localhost:8080',
credentials: true,
@johnrjj
johnrjj / fill-with-native-token.tsx
Last active March 10, 2022 07:52
fill with native token with nftswap v3
const MAKER_ASSET: SwappableAsset = {
type: 'ERC20',
tokenAddress: DAI_TOKEN_ADDRESS_MUMBAI_TESTNET,
amount: '1000000000', // 1 DAI
};
const TAKER_ASSET: SwappableAsset = {
type: 'ERC20',
tokenAddress: WMATIC_TOKEN_ADDRESS_MUMBAI_TESTNET,
amount: '1000000000', // 0.0000001 WMATIC
};
@johnrjj
johnrjj / 0x-api-ethers.ts
Created September 24, 2021 18:18
0x API swap w/ ethers.js
import { Web3Provider } from '@ethersproject/providers'
const provider = new Web3Provider(window.ethereum)
const [address] = await window.ethereum.request({ method: 'eth_accounts' })
const res = await fetch('https://api.0x.org/swap/v1/quote?buyAmount=1000000&buyToken=USDT&sellToken=USDC')
const quote = await res.json()
@johnrjj
johnrjj / useScrollProgress.tsx
Created June 10, 2020 16:13
useScrollProgress
/* eslint-disable */
import { RefObject, useEffect } from 'react';
import { useRafState } from 'react-use';
export interface State {
x: number;
y: number;
totalHeight: number;
}
@johnrjj
johnrjj / App.js
Created February 20, 2019 19:42
Experiment React Stuff
import React, { Component } from 'react';
import { Experiment } from './experiment/Experiment';
import { Case } from './experiment/Case';
class App extends Component {
render() {
return (
<div className="App">
<Experiment>
<Case when={(experimentMetadata) => experimentMetadata.foo === 'bar'}>
@johnrjj
johnrjj / intersection-util.ts
Created February 11, 2019 18:53
marzullo algo
// https://en.wikipedia.org/wiki/Marzullo%27s_algorithm
const calculateIntersectingRanges = (ranges: Array<[number, number, any?]>, userOptions = {}) => {
let START = 1;
let END = -1;
let points: Array<{
value: number;
rangeIndex: number;
type: number;
count?: number;
index?: number;
@johnrjj
johnrjj / dothething.jsx
Created February 11, 2019 18:23
app.js for tooltips
class App extends Component {
render() {
return (
<FullscreenContainer>
<TooltipManager>
<Canvas>
<div>
I'm, like, always trying to save the planet? Here's my chance. I was part of something special.
Checkmate... Life finds a way.
@johnrjj
johnrjj / pluck.ts
Created December 28, 2016 01:10
typescript mapped types
// Takes an array of objects and a property to 'pluck' or 'grab'
// > pluck([{k1: 1, k2: 3}, {k1: 5, k2: 1}], 'k1')
// > [1, 5]
/*
T = OBJECT a.k.a. ({ k1: val1, k2: val2})
K = property
*/
const pluck = <T, K extends keyof T>(objs: T[], key: K): T[K][] => {
@johnrjj
johnrjj / jira-oauth.js
Last active March 19, 2017 19:16
Jira Request w/ OAuth (After OAuth Dance)
var request = require('request');
// After getting access tokens...
// Don't worry these aren't valid tokens...
const oauth = {
consumer_key: 'test',
private_key: `-----BEGIN RSA PRIVATE KEY-----
AoGBAKZ4sQJ8rglpGX02SdeMF570vKVXtxf6jhl5TveGYmRsSvFpB9Kexa26YMqn
oPUBYTmITIsfWOXv/SG+fWrBUEDHqqREIzH6XsR6US5JCKZkwF5PpTRnYwIDAQAB
-----END RSA PRIVATE KEY-----`,