Skip to content

Instantly share code, notes, and snippets.

View koolamusic's full-sized avatar
🎯
Focusing

U.M Andrew koolamusic

🎯
Focusing
View GitHub Profile
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { TransferHelper } from "./libraries/TransferHelper.sol";
import { FinderInterface } from "./interfaces/FinderInterface.sol";
import { IConditionalTokens } from "./interfaces/IConditionalTokens.sol";
@koolamusic
koolamusic / IDiamonCut.sol
Created July 30, 2022 21:41
A sample implementation of the solidity Diamond pattern used in this DeFi app https://louper.dev/diamond/0x362fA9D0bCa5D19f743Db50738345ce2b40eC99f
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IDiamondCut {
enum FacetCutAction {
Add,
Replace,
Remove
}
// Add=0, Replace=1, Remove=2
const { NotFound } = require('http-errors');
const { ForbiddenError } = require('@casl/ability');
const Comment = require('./model')();
async function findAll(req, res) {
const comments = await Comment.accessibleBy(req.ability);
res.send({ items: comments });
}
@koolamusic
koolamusic / DateFormatDirective.ts
Created July 15, 2022 10:09
GraphQL directives to work with Nestjs
import { SchemaDirectiveVisitor } from '@graphql-tools/utils';
import { defaultFieldResolver, GraphQLField, GraphQLString } from 'graphql';
import formatDate from 'dateformat';
export class DateFormatDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field;
const { defaultFormat } = this.args;
field.args.push({
deprecationReason: undefined,
```ts
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
/**
* Hello fellow Nerd,
* In this smart contract we have taken every measure possible to
* keep the costs of gas managable every step along the way. Gas during The Accidental Apocalypse
* is hard to find -- You can't be pourin' it out on the ground like it grows on trees.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract MerkleTreeExample {
// --- PROPERTIES ---- //
// Calculated from `merkle_tree.js`
bytes32 public merkleRoot =
@koolamusic
koolamusic / addRPCNetworkEthers.js
Created February 18, 2022 13:34
Add an RPC EVM Supported Network to Metamask
/** @see https://docs.metamask.io/guide/rpc-api.html#other-rpc-methods*/
async function changeNetwork(){
await ethereum.request({ method: 'wallet_addEthereumChain',
params:[
{chainId: "IN_HEXADECIMAL_FORM",
chainName: "CHAIN_NAME",
nativeCurrency: {
name: "NATIVE_CURRENCY_NAME",
symbol: "NATIVE_CURRENCY_SYMBOL",
decimals: NATIVE_CURRENCY_DECIMALS //In number form
@koolamusic
koolamusic / Scroll.jsx
Last active February 12, 2022 20:32
Horizontal Scroll
const HorizontalScroll = styled.div`
position: relative;
overflow: hidden;
--offset: 20vw;
--move-initial: calc(-25% + var(--offset));
--move-final: calc(-50% + var(--offset));
div {
width: fit-content;
display: flex;
@koolamusic
koolamusic / read-file.js
Last active December 30, 2021 22:53
Read File from browser using XMLHttpRequest
function readTextFile(file) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if(rawFile.readyState === 4) {
if(rawFile.status === 200 || rawFile.status == 0) {
var allText = rawFile.responseText;
doSomethingWithTheText(allText);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Tonejs Demo</title>
</head>
<body>
<!-- Learn music theory https://www.youtube.com/watch?v=rgaTLrZGlk0 -->