Skip to content

Instantly share code, notes, and snippets.

View danielkhoo's full-sized avatar
📚

Daniel danielkhoo

📚
View GitHub Profile
@danielkhoo
danielkhoo / sitemap.js
Created December 10, 2023 08:00
NextJS Sitemap Handler
export default function handler(req, res) {
// getPosts is a fn that returns all the posts, you should already have this for a markdown/mdx site
const posts = getPosts();
res.statusCode = 200
res.setHeader('Content-Type', 'text/xml')
// Instructing the Vercel edge to cache the file
res.setHeader('Cache-control', 'stale-while-revalidate, s-maxage=3600')
// generate sitemap here
@danielkhoo
danielkhoo / og.js
Created January 2, 2023 07:27
Dynamic OpenGraph Snippet
import { ImageResponse } from '@vercel/og'
export const config = {
runtime: 'edge',
}
export default async function handler(req) {
const HOST = 'https://danielkhoo.xyz'
const { searchParams } = req.nextUrl
const title = searchParams.get('title') || 'danielkhoo.xyz'
const description = searchParams.get('description') || `Hello there! I'm Daniel. Welcome to my online home for ideas, writing and side projects.`
@danielkhoo
danielkhoo / head.html
Last active January 1, 2023 08:19
Twitter and OpenGraph Cards
<!-- OpenGraph Meta Tags -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content="@jadenkore" />
<meta property="twitter:domain" content="danielkhoo.xyz" />
<meta property="twitter:url" content="https://danielkhoo.xyz/twitter-and-open-graph-cards" />
<meta name="twitter:title" content="Twitter and OpenGraph Cards" />
<meta name="twitter:description" content="Having a personal site is great for standing out and expressing your creativity..." />
<meta name="twitter:image" content="https://danielkhoo.xyz/sd2.png" />
<!-- OpenGraph Meta Tags -->
<meta property="og:url" content="https://danielkhoo.xyz/" />
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
/**
* @title Digital Collectible
* @author Daniel Khoo
* @notice A dynamic NFT wrapper for digital collectibles on Instagram / Twitter with editable token URI
@danielkhoo
danielkhoo / dcw.json
Last active September 18, 2022 09:58
Digital Collectible Wrapper Metadata
{
"name": "Digital Collectible Wrapper",
"description": "A dynamic wrapper NFT for linking Digital Collectibles on Instagram and Twitter",
"image": "https://github.com/danielkhoo.png"
}
@danielkhoo
danielkhoo / scriptable-npm-download-widget.js
Created September 3, 2022 12:11
Scriptable: npm download widget
const PACKAGE = "nric"
let widget = await createWidget();
// Check where the script is running
if (config.runsInWidget) {
// Runs inside a widget so add it to the homescreen widget
Script.setWidget(widget);
} else {
// Show the medium widget inside the app
@danielkhoo
danielkhoo / scriptable-eth-gas-widget.js
Last active September 3, 2022 11:42
Scriptable: Eth Gas Widget
const API_KEY = "" // Add your etherscan API KEY here
let widget = await createWidget();
// Check where the script is running
if (config.runsInWidget) {
// Runs inside a widget so add it to the homescreen widget
Script.setWidget(widget);
} else {
// Show the medium widget inside the app
@danielkhoo
danielkhoo / BuidlGuidlTabard.sol
Last active November 9, 2023 13:52
Contract for BuidlGuidl Tabard NFT v1 on Eth Mainnet at https://etherscan.io/address/0x06a13a0fcb0fa92fdb7359c1dbfb8c8addee0424
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Base64.sol";
/**
* @title BuidlGuidl Tabard
* @author Daniel Khoo
@danielkhoo
danielkhoo / RockPaperScissors.sol
Created February 7, 2022 07:01
Completed RockPaperScissors Contract
pragma solidity >=0.8.0 <0.9.0;
//SPDX-License-Identifier: MIT
contract RockPaperScissors {
// 4 Game Phases: Join, Commit, Reveal, Result
enum GameState {
JoinPhase,
CommitPhase,
RevealPhase,
pragma solidity >=0.8.0 <0.9.0;
/**
* @notice Function for players to reveal their choice. The first player to reveal sets a deadline for the second player
* this is prevent players for abandoning the game once they know they have lost based on the revealed hash.
* At the end of the deadline, the player who committed can trigger a "win-by-default".
* If both players reveal in time, the second player's reveal will call determineWinner() and advance the game to the result phase
* @notice Unlike commit, players can only reveal once
* @param salt - a player chosen secret string from the "commit" phase used to prove their choice via a hash match
*/