Skip to content

Instantly share code, notes, and snippets.

View danielkhoo's full-sized avatar
📚

Daniel danielkhoo

📚
View GitHub Profile
@danielkhoo
danielkhoo / Dockerfile
Created August 30, 2018 10:02
Dockerfile for Node
FROM node:8-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .
RUN npm install
EXPOSE 3000
CMD [ "node", "server.js" ]
@danielkhoo
danielkhoo / default
Created August 31, 2018 10:30
Nginx Proxy for Node
server_name mynewsite.com www.mynewsite.com;
location / {
#----------Add this section-----------
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;
"Fat Console Log": {
"prefix": "clgf",
"body": [
"console.log('\\n\\n\\nhellothere\\n',$1,'\\n\\n\\n');",
"$2"
],
"description": "Fat Console Log"
},
"Arrow Function": {
"prefix": "arfn",
"body": [
"const $1 = () => {",
"return ",
"};",
"$2"
],
"description": "Arrow Function"
}
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 commit their choice
* @dev players can commit multiple times to change their choice until the other player commits
* @param choice - "rock", "paper" or "scissors"
* @param salt - a player chosen secret string used to "salt" the commit hash
*/
function commit(string memory choice, string memory salt)
public
validGameState(activeGame[msg.sender], GameState.CommitPhase)
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
*/
@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,
@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 / 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