Skip to content

Instantly share code, notes, and snippets.

View mattdesl's full-sized avatar
👋

Matt DesLauriers mattdesl

👋
View GitHub Profile
@mattdesl
mattdesl / ContextLoss.js
Created April 5, 2014 17:54
Simulating context loss with a mouse click
var loseCtx = context.gl.getExtension("WEBGL_lose_context");
//May not exist in some browsers, or if WebGLInspector is enabled
if (loseCtx) {
//Attach a mouse click to the canvas...
canvas.addEventListener("mousedown", function() {
//Force the canvas to lose its WebGL context
loseCtx.loseContext();
//Here you may want to present the user with a progress indicator
@mattdesl
mattdesl / Home.tsx
Created April 25, 2024 16:52
wallet signature mechanism for Meridian book verification
import { ConnectButton } from '@rainbow-me/rainbowkit';
import type { NextPage } from 'next';
import { useSignMessage } from 'wagmi'
import Image from 'next/image';
import { verifyMessage } from 'ethers/lib/utils'
import { useAccount, useConnect, useDisconnect } from 'wagmi'
import { createMessage } from '../tools/sign';
import Head from 'next/head';
import styles from '../styles/Home.module.css';
// Static artwork
const randomRange = (min, max) => Math.random() * (max - min) + min;
export default ({ width, height, data }) => {
const baseHue = Math.random() * 360;
const newColor = () => {
const hue = baseHue + randomRange(-1, 1) * 5;
const sat = 50 + randomRange(-1, 1) * 10;
@mattdesl
mattdesl / PointCheck.sol
Last active April 16, 2024 09:25
Verification of bn254 points aka alt_bn128
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.12 <0.9.0;
contract PointCheck {
struct G1Point {
uint256 x;
uint256 y;
}
event BroadcastSecKey(address indexed sender, uint256 secKey);
@mattdesl
mattdesl / glsl-background.glsl
Created April 26, 2017 18:02
Like CSS background-size: contain but in GLSL
vec2 backgroundUV (vec2 uv, vec2 resolution, vec2 texResolution) {
float tAspect = texResolution.x / texResolution.y;
float pAspect = resolution.x / resolution.y;
float pwidth = resolution.x;
float pheight = resolution.y;
float width = 0.0;
float height = 0.0;
if (tAspect > pAspect) {
height = pheight;
@mattdesl
mattdesl / cli.js
Created September 13, 2022 10:37
colour palette from text prompt using Stable Diffusion https://twitter.com/mattdesl/status/1569457645182152705
/**
* General-purpose NodeJS CLI/API wrapping the Stable-Diffusion python scripts.
*
* Note that this uses an older fork of stable-diffusion
* with the 'txt2img.py' script, and that script was modified to
* support the --outfile command.
*/
var { spawn, exec } = require("child_process");
var path = require("path");
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;

Gluten-Free Buckwheat Sablé Cookies

Ingredients:

  • 100g buckwheat flour
  • 50g white sugar
  • 50g salted butter
  • Pinch of salt, to taste
  • Big pinch of cinnamon, to taste (note: Cassia type cinnamon, or what you’d find in a Swedish grocery store)
  • Big pinch of cardamom powder, to taste

Easy Soy-Glazed Chicken Recipe[^1]

Ingredients:

  • 4-6 Chicken thighs
  • Soy sauce
  • Mirin
  • Smoked chilli flakes
  • Garlic powder
  • Ginger powder
@mattdesl
mattdesl / offset-path.js
Created December 19, 2018 14:44
MIT – 2D vector path offsetting algorithm (work in progress)
/*
Copyright 2018 Matt DesLauriers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE