Skip to content

Instantly share code, notes, and snippets.

View koolamusic's full-sized avatar
🎯
Focusing

BLS12-381 koolamusic

🎯
Focusing
View GitHub Profile
@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 -->
@koolamusic
koolamusic / metamask-signature.html
Created December 21, 2021 05:50
retrieve the signature from metamask
<!DOCTYPE html>
<html>
<head>
<title>Get Public Key</title>
</head>
<body>
<div style="margin-bottom:5px">Enable Metamask, then click on the sign button and sign with your wallet to get your public key</div>
<div style="margin-bottom:5px"><button onclick="enableMM()">Enable Metamask</button></div>
<div style="margin-bottom:20px"><button onclick="findPublicKey()">Sign</button></div>
const createDelegateBySigMessage = (compAddress, delegatee, expiry = 10e9, chainId = 1, nonce = 0) => {
const types = {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
],
Delegation: [
{ name: 'delegatee', type: 'address' },
{ name: 'nonce', type: 'uint256' },
@koolamusic
koolamusic / tile.js
Last active November 30, 2021 12:00
Memory Match Game
// https://www.khanacademy.org/computing/computer-programming/programming-games-visualizations/memory-game/a/intro-to-memory
var Tile = function(x, y, face) {
this.x = x;
this.y = y;
this.size = 50;
this.face = face;
this.isFaceUp = false;
this.isMatch = false;
};
@koolamusic
koolamusic / cipher.js
Created October 10, 2021 18:25
Pure Nodejs two-way cipher. also checkout https://github.com/paragonie/sodium-plus for a fast lib implementation of C-libsodium
var crypto = require("crypto");
var algorithm = "aes-192-cbc"; //algorithm to use
var password = "Hello darkness";
const key = crypto.scryptSync(password, 'salt', 24); //create key
var text= "this is the text to be encrypted"; //text to be encrypted
const iv = crypto.randomBytes(16); // generate different ciphertext everytime
const cipher = crypto.createCipheriv(algorithm, key, iv);
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); // encrypted text
@koolamusic
koolamusic / wait_for_http_200.sh
Created September 24, 2021 16:04 — forked from rgl/wait_for_http_200.sh
Wait for an HTTP endpoint to return 200 OK with Bash and curl
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9000)" != "200" ]]; do sleep 5; done'
# also check https://gist.github.com/rgl/c2ba64b7e2a5a04d1eb65983995dce76
@koolamusic
koolamusic / authWrapper.js
Created August 27, 2021 17:07
Middleware and context example Nextjs
// Adapted from: https://betterprogramming.pub/why-i-got-rid-of-getinitialprops-in-my-next-js-project-fc926e98ed61
export function authWrapper(next) {
return async function auth(ctx) {
const user = await session.getUser();
if (!user) {
return {
redirect: {
destination: '/sign-in',