Skip to content

Instantly share code, notes, and snippets.

View jaggedsoft's full-sized avatar
Productive

jagged jaggedsoft

Productive
View GitHub Profile
@aghyad97
aghyad97 / play-sound-web-api.ts
Created September 8, 2025 17:07
Playing sounds with Web APIs
const audioCtxRef = useRef<AudioContext | null>(null);
const ensureAudio = useCallback(() => {
if (audioCtxRef.current) return audioCtxRef.current;
const Ctx =
(window as any).AudioContext || (window as any).webkitAudioContext;
if (!Ctx) return null;
audioCtxRef.current = new Ctx();
return audioCtxRef.current;
@z0r0z
z0r0z / Multisig.sol
Last active March 9, 2022 01:50
Simple gas-optimized multi-signature contract.
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.4;
/// @notice Simple gas-optimized multi-signature contract.
contract Multisig {
event Propose(address indexed proposer, uint256 indexed proposal);
event Sign(address indexed signer, uint256 indexed proposal);
event Execute(uint256 indexed proposal);
error NotSigner();
@tommyettinger
tommyettinger / DeepMap.txt
Created January 1, 2021 22:28
Multi-layer dungeon map; '<' and '>' are staircases
--------------------------------------------------- depth 0
┌───┐┌────┐ ┌─┐ ┌────┐
┌┘.""└┘....└┐ ┌┘.└┐ ┌┘....└┐
┌┘...""...#..│┌────────┐ ┌┘...└┐│..#...└──┐
│............└┘.,~~~~,.└──┐ │.....││.........└┐
└┐..............───~~.....└┐ └┐...─┴┘...│..┌┐..│ ┌─┐
│...............,,~~......│ │.........│..└┘..└─┬────┘.└┐
├─.────.........,.┌┐......│ └┐.┌──┐...└─.......│.......└┐
│................┌┘│.....┌┘ └─┘ │.....................│
└┐.┌──┐.┌┐....┌──┴┐├─..┌─┴┐ │...┌──┐.............┌┘
@talegift
talegift / calculateUniswapTWAP.js
Created November 17, 2020 16:59 — forked from l3wi/calculateUniswapTWAP.js
Off-chain Uniswap V2 TWAP calculator in Javascript
import { ethers } from 'ethers'
// To use this you need to read the Uniswap v2 contract for a pair/
// PRICE pulled from priceXCumulativeLast
// TIMESTAMPS pulled from _blockTimestampLast in getReserves()
// Mock Data
// In a real scenario you would fetch and store price & timestamp at an interval
// to mirror the contract calculating the TWAP on chain
const price0 = '529527205677379158060966860839'
@cryptoscopia
cryptoscopia / dydxFlashLoanTemplate.sol
Created October 21, 2020 06:42
A single-file simplest possible template for a contract that obtains a flash loan from dydx, does things, and pays it back.
// SPDX-License-Identifier: AGPL-3.0-or-later
// The ABI encoder is necessary, but older Solidity versions should work
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
// These definitions are taken from across multiple dydx contracts, and are
// limited to just the bare minimum necessary to make flash loans work.
library Types {
enum AssetDenomination { Wei, Par }
@Keyinator
Keyinator / index.php
Last active February 25, 2024 18:08 — forked from Jengas/index.php
Discord oauth2 example PHP
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('max_execution_time', 300); //300 seconds = 5 minutes. In case if your CURL is slow and is loading too much (Can be IPv6 problem)
error_reporting(E_ALL);
define('OAUTH2_CLIENT_ID', 'PLEASE EDIT');
define('OAUTH2_CLIENT_SECRET', 'PLEASE EDIT');
$authorizeURL = 'https://discordapp.com/api/oauth2/authorize';
$tokenURL = 'https://discordapp.com/api/oauth2/token';
$apiURLBase = 'https://discordapp.com/api/users/@me';
@ageis
ageis / .bashrc 02-25-2020
Last active May 10, 2024 02:34
@ageis's ~/.bashrc 🖥️ with numerous useful functions, aliases and one-liners. ⚠️ NOTE: many paths in sourced scripts and environment variables are specific to my system, but if you dig in I hope you'll find something you can use!
#!/bin/bash
# ~/.bashrc: executed by bash(1) for non-login shells.
# kevin gallagher (@ageis) <kevingallagher@gmail.com>
# normally I divide this into separate files: .bashrc, .bash_profile, .bash_aliases and .bash_functions (also .bash_logout), but it's all concatenated here.
ulimit -s unlimited
export MYUID=$(id -u)
export USER="$(id -un)"
if [[ "$TILIX_ID" ]] || [[ "$VTE_VERSION" ]]; then
// This is universal, works with Infura -- set provider accordingly
const ethers = require('ethers')
//const provider = ethers.getDefaultProvider('rinkeby')
const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL)
function hex_to_ascii(str1) {
var hex = str1.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2) {
@jasny
jasny / sha256-hmac.md
Last active July 16, 2025 12:32
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

@matthewp
matthewp / decorate-element.js
Last active April 23, 2020 07:57
decorate-element
function decorate(tag, template) {
customElements.define(tag, class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
let root = this.shadowRoot;
if(!root.firstChild) {