Skip to content

Instantly share code, notes, and snippets.

View sajclarke's full-sized avatar

Shannon Clarke sajclarke

View GitHub Profile
@sajclarke
sajclarke / script.js
Last active February 15, 2024 13:26 — forked from gd3kr/script.js
Download a JSON List of twitter bookmarks
/*
the twitter api is stupid. it is stupid and bad and expensive. hence, this.
Literally just paste this in the JS console on the bookmarks tab and the script will automatically scroll to the bottom of your bookmarks and keep a track of them as it goes.
When finished, it downloads a JSON file containing the raw text content of every bookmark.
for now it stores just the text inside the tweet itself, but if you're reading this why don't you go ahead and try to also store other information (author, tweetLink, pictures, everything). come on. do it. please?
*/
@sajclarke
sajclarke / gist:91ab53c830b04555508bf5775c5d2811
Created November 16, 2022 23:29
Disable yup validation based on external variable
//external variable
const disabledEndYear = true
//schema validation for yup
const schema = yup
.object({
field_name: yup.number().when([], {
is: (val: any) => {
return !disabledEndYear; //if false
},
@sajclarke
sajclarke / convertFileUploadToBinary.js
Created July 6, 2022 11:42
Convert HTML file input to binary string
// The below function accepts the HTMLInputElement event from a <input type="file" />
// and returns a binary string
function readFileDataAsBase64(e) {
const file = e.target.files[0];
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (event) => {
resolve(event.target.result);
@sajclarke
sajclarke / trie.js
Created December 19, 2020 18:07
Building a trie using Javascript. Credit to @dariothornhill
const routes = [['foo', 'bar'], ['foo'], ['products']]
function TrieNode(value) {
this.value = value;
this.children = []
}
const checkValue = (node, value) => {
return node.value === value;
}
pragma solidity ^0.5.0;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract DAOToken is ERC20 {
/// The event emitted (useable by web3) when a token is purchased
event LogFunding(address indexed sender, uint256 tokens);
@sajclarke
sajclarke / App.js
Created November 21, 2018 19:38
Refactor the getWeb3, getAccount and getBalance functions
getWeb3 = () => new Promise((resolve, reject) => {
try{
if(typeof window.web3 !== undefined){
resolve(new Web3(Web3.givenProvider))
}else{
this.setState({errorMsg:'web3 not found'})
@sajclarke
sajclarke / web3PastEvents.js
Created October 8, 2018 14:44
web3 v1.0.0 - how to get past events
const DEPLOYED_ADDRESS
const CONTRACT_EVENT
try {
const web3 = await this.getWeb3()
const accounts = await web3.eth.getAccounts()
const tickerRegInstance = new web3.eth.Contract(TickerRegistry.abi, DEPLOYED_ADDRESS)
@sajclarke
sajclarke / App.js
Created October 1, 2018 15:57
Step 2 of polymath web3 tutorial
import React, { Component } from 'react';
import Web3 from 'web3'
import logo from './poly_logo.svg';
import './App.css';
const PolyTokenFaucet = require('./contracts/PolyTokenFaucet.json');
class App extends Component {
@sajclarke
sajclarke / App.js
Created October 1, 2018 15:56
Step 3 of polymath tutorial
import React, { Component } from 'react';
import Web3 from 'web3'
import { Container, Row, Col, Button, Alert, Form, FormGroup, Label, Input, FormText } from 'reactstrap'
import logo from './poly_logo.svg';
import './App.css';
const PolyTokenFaucet = require('./contracts/PolyTokenFaucet.json');
class App extends Component {
@sajclarke
sajclarke / App.js
Created October 1, 2018 12:49
Step 1 of polymath tutorial
import React, { Component } from 'react';
import Web3 from 'web3'
import logo from './poly_logo.svg';
import './App.css';
class App extends Component {
constructor(props) {
super(props)