Skip to content

Instantly share code, notes, and snippets.

@wilsoncusack
wilsoncusack / TextViewExperiment.swift
Created July 8, 2019 21:02
SwiftUI + UITextView with dismiss keyboard button
//
// TextViewExperiment.swift
// Wilson Cusack
//
// Most of the code from https://www.icalvin.dev/post/403
// There's a few changes, but mainly just the ability to close the keyboard.
//
import SwiftUI
import UIKit
@wilsoncusack
wilsoncusack / ReusableExample.swift
Last active June 30, 2023 23:24
SwiftUI Reusable View Using Generic Types
struct HorizontalList<Item, Card, Detail>: View where Item: NSManagedObject, Card: View, Detail: View{
var items: FetchedResults<Item>
var card: (Item) -> Card
var detail: (Item) -> Detail
// init(items: FetchedResults<Item>, @ViewBuilder card: @escaping (Item) -> Card, @ViewBuilder detail: @escaping (Item) -> Detail) {
// self.items = items
// self.card = card
// self.detail = detail
// }
@wilsoncusack
wilsoncusack / commune_take_1.sol
Last active October 17, 2020 18:06
A Smart Contract that facilitates creating communes where all funds sent to the commune are distributed amongst members
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
contract Commune is ERC20 {
using SafeMath for uint256;
constructor() public ERC20("Commune DAI", "COMD") {
}
@wilsoncusack
wilsoncusack / DecimalStrings.sol
Last active February 28, 2023 06:24
Solidity Decimal String Helpers
function decimalString(uint256 number, uint8 decimals, bool isPercent) private pure returns(string memory){
uint8 percentBufferOffset = isPercent ? 1 : 0;
uint256 tenPowDecimals = 10 ** decimals;
uint256 temp = number;
uint8 digits;
uint8 numSigfigs;
while (temp != 0) {
if (numSigfigs > 0) {
// count all digits preceding least significant figure
@wilsoncusack
wilsoncusack / schema.graphql
Created November 9, 2021 15:58
nft-backed loans subgraph entities
type Loan @entity {
id: ID!
closed: Boolean!
perSecondInterestRate: BigInt!
accumulatedInterest: BigInt!
lastAccumulatedTimestamp: BigInt!
durationSeconds: BigInt!
loanAmount: BigInt!
collateralTokenId: BigInt!
collateralContractAddress: Bytes!
@wilsoncusack
wilsoncusack / LendVault.sol
Created November 16, 2021 20:00
NFT-Loan Lending Vault Sketch
pragma solidity 0.8.6;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../interfaces/INFTLoanFacilitator.sol";
struct LendValues {
uint256 loanAmount;
uint256 perSecondInterestRate;
@wilsoncusack
wilsoncusack / testPrankPayable.sol
Created December 21, 2021 12:19
Prank Payable
interface Vm {
function prank(address) external;
}
contract Foo {
function bar() public {
require(msg.sender == address(1), 'wrong sender');
}
function barPayable() public payable {
@wilsoncusack
wilsoncusack / query.graphql
Created December 25, 2021 03:58
NFT Sales Indexer Query
{
sales(where: {nftContractAddress: "0x8d04a8c79ceb0889bdd12acdf3fa9d207ed3ff63", nftTokenId: "606"} orderBy: timestamp, orderDirection: desc)
{
id
nftTokenId
price
}
}
@wilsoncusack
wilsoncusack / main.rs
Last active December 29, 2021 18:30
Rust Ethereum Vanity Address Generation
use ethers::{
signers::{LocalWallet, Signer},
};
fn main() {
let vanity_hex = "01";
// OR pass as input
// let mut args: Args = args();
// let vanity_hex = args.nth(1).unwrap();
let bytes_to_match = hex::decode(vanity_hex).expect("invalid hex");
@wilsoncusack
wilsoncusack / typedGraphqlQuery.ts
Last active January 13, 2022 17:01
Passing Objects as Document Variables using URQL
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Loan_Filter = {
closed?: InputMaybe<Scalars['Boolean']>;
closed_in?: InputMaybe<Array<Scalars['Boolean']>>;
closed_not?: InputMaybe<Scalars['Boolean']>;
closed_not_in?: InputMaybe<Array<Scalars['Boolean']>>;
};