Skip to content

Instantly share code, notes, and snippets.

View samkingco's full-sized avatar

Sam King samkingco

View GitHub Profile
@samkingco
samkingco / RandomSymbol.tsx
Last active January 24, 2024 18:33
Random symbol
"use client";
import { useEffect, useState } from "react";
const symbols = ["⦂⦂", "⦿", "⊛", "⊚", "⊙", "⦚", "⟁", "⦂⦚"];
function getRandomSymbol() {
const randomIndex = Math.floor(Math.random() * symbols.length);
return symbols[randomIndex];
}
@samkingco
samkingco / [...nextauth].ts
Created November 21, 2022 23:00
connectkit-next-auth
import { IncomingMessage } from "http";
import { NextApiRequest, NextApiResponse } from "next";
import NextAuth, { type NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { getCsrfToken } from "next-auth/react";
import { SiweMessage } from "siwe";
export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
const providers = [
CredentialsProvider({
@samkingco
samkingco / MyComponent.tsx
Created October 13, 2022 00:57
useENS hook with react-query
import { useAccount } from "wagmi";
import { useENS } from "./useENS";
export function MyComponent() {
const { address: connectedAddress } = useAccount();
const { displayName } = useENS(connectedAddress);
return (
<>
{connectedAddress ? (
@samkingco
samkingco / IPhotoCollection.sol
Last active May 29, 2022 23:51
Off and on-chain photo collection contracts
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.14;
interface IPhotoCollection {
function getOriginalsBaseURI() external view returns (string memory);
function getOriginalTokenId(uint256 editionId) external pure returns (uint256);
function getRawEditionPhotoData(uint256 id) external view returns (bytes memory);
@samkingco
samkingco / CozyCoMembership.sol
Created December 4, 2021 01:27
CozyCoMembership
//SPDX-License-Identifier: Unlicense
/// @title: cozy co. membership
/// @author: The Stitcher AKA samking.eth
/*
:-.:- .-:.=: -==. :- .=== .==: :-::- .--.-:
*@%..=@--%@+ %@# .#%%@@#-+.-@@# #@@- +@@: -@*:%@# *@%.
%@@: :.-@@% .@@@ ....:-: %@@: -@@# +@@= ::.@@@. %@@:
@samkingco
samkingco / T83_screencode.js
Created October 30, 2021 00:02
Create designs for the T83 NFT project
function gridToPairOfUint160(grid) {
let gridR = grid.map((_, index) => [grid].map((row) => row[index]).reverse());
let grid2R = gridR[0].map((_, index) =>
gridR.map((row) => row[index]).reverse()
)[0];
let leftPart = 0n;
let rightPart = 0n;
for (let i = 0; i < 14; i++) {
for (let j = 0; j < 22; j++) {
const power = BigInt(13 - i) + 14n * BigInt(j % 11);
@samkingco
samkingco / styled.d.ts
Created August 27, 2021 23:00
Typed theme in styled components
import "styled-components";
import theme from "./theme"; // Or wherever your theme object is
type Theme = typeof theme;
declare module "styled-components" {
export interface DefaultTheme extends Theme {}
}
@samkingco
samkingco / resolvers.ts
Created August 17, 2019 18:11
GraphQL resolver type issues
import { Resolvers } from "./schema-types";
const users = [
{
id: "user-1",
name: "Sam",
commentIds: ["comment-2"]
}
];
// containers/App.js
import React from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { compose, lifecycle } from 'recompose';
import { provideState, injectState } from 'freactal';
import { initialState, effects, computed } from 'state';
import Summary from 'components/Summary';
const provider = provideState({
@samkingco
samkingco / README.md
Last active April 12, 2017 18:12
REST API