Skip to content

Instantly share code, notes, and snippets.

@moodysalem
moodysalem / PreventLeaveRoute.jsx
Created January 22, 2017 18:52
React HOC to prevent leaving a page
import React, { Component, PropTypes } from 'react';
/**
* Only ever render one of these per page
*
* TODO: improve with react-side-effect to better handle multiple instances of this being rendered at once so we can
* nest the component in forms
*/
export default class PreventLeaveRoute extends Component {
static contextTypes = {
@moodysalem
moodysalem / render-text.jsx
Created November 11, 2016 19:18
Render React component to text
import { render, unmountComponentAtNode } from 'react-dom';
export function renderText(component) {
const _el = document.createElement('div');
document.body.appendChild(_el);
render(component, _el);
const text = _el.innerText;
unmountComponentAtNode(_el);
document.body.removeChild(_el);
return text;
@moodysalem
moodysalem / example.sol
Last active April 1, 2022 22:05
Transient Storage Example
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
/// @notice The canonical ERC20 interface
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(
@moodysalem
moodysalem / TransientStorage.sol
Last active September 14, 2023 10:12
proxy yul code for using transient storage
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.12;
type TransientStorageProxy is address;
library TransientStorage {
function init() internal returns (TransientStorageProxy proxy) {
// initCode == bytecode from `yarn compile-tsp`
bytes
memory initCode = hex'602980600d600039806000f3fe366020811460135760408114602057600080fd5b600035b360005260206000f35b602035600035b450';
@moodysalem
moodysalem / CSSInliner.java
Last active November 23, 2023 08:12
Attempt to inline CSS using Java HTML parsing library jsoup
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
@moodysalem
moodysalem / leaderboard.csv
Created February 16, 2024 16:48
Leaderboard STRK allocations
0x49fb4281d13e1f5f488540cd051e1507149e99cc2e22635101041ec5e4e4557 realmsworld.stark 0
0x44c0d80799aca566a792c5ef2491ba5e36391dd7fceffd9afe2824335ab55e1 mimesis.stark 1200
0x680afd6b0843e7851390521d87e849f010babbc608ba53dcff02b1c0fcd6fa 1800
0x3f60afe30844f556ac1c674678ac4447840b1c6c26854a2df6a8a3d2c015610 sendmoodz.stark 91800
0x79b6f2012e8fc8b94b79d81e24fcf41d5cc3b84cd98e3ba6fd715ba0d2037fa computerbleu.stark 0
0x3c22c9daf71cc2c9cdb6018bccd3903b94ca0ce74ba048a4f8ee4ccd7451e83 chenzs.stark 1200
0x2c36503c8ed3a54daed4b7d1870593329aa144c6fb389d3afd86659384773a0 0
0x7266c8d2cf45ecba9221e7691f80fb3e6c4ff30b09f6a3a1097341a2f3f14de e.stark 0
0x6e14b28449c412a336e7a5a3473da083b9159e6845be4d02ee50f6095a5b3ce 1200
0x3474353878b236171e4c08e52465d9f2cf6c3babf726cc292ff1566e68612c3 grug.stark 40650
@moodysalem
moodysalem / promise-cancellable.js
Last active April 9, 2024 18:06
ES6 Cancellable Promise Wrapper
/**
* Returns a promise that has a cancelled method that will cause the callbacks not to fire when it resolves or rejects
* @param promise to wrap
* @returns new promise that will only resolve or reject if cancel is not called
*/
export default function cancellable(promise) {
var cancelled = false;
const toReturn = new Promise((resolve, reject) => {
promise.then(() => {