Skip to content

Instantly share code, notes, and snippets.

View d-smith's full-sized avatar

Doug Smith d-smith

View GitHub Profile
@d-smith
d-smith / stuff.md
Last active December 15, 2023 04:26
Stuff 2023
  1. Good braid scissors like Gerber Neat Freak

  2. Lures - FIsherman's Marine, Cabela's, online sources, etc

  • Mepps Trouter kit
  • Blue Fox Vibrax spinners - size 3 and 5, blue, copper, gold, silver, green, purple
  • Brad's Killer Fishing Gear - Wiggler lure, misc sizes and colors for trout/steelhead/salmon
  1. Trumpet Stand - K and M 5 legged
@d-smith
d-smith / misc.md
Last active November 7, 2023 15:48
Some misc for working with cobra cli, sqlite3, foundry, etc

Create the db in the cmd directory sqlite3 attestor.db < att.sql

To do some FiddyCent token operations, run scripts\deploy-details.sh to get the contract address and an export command. Run the export command, then play with the contract.

cast call $FIDDY_CENT "totalSupply()(uint256)"  --rpc-url  http://127.0.0.1:8545

cast send $FIDDY_CENT "transfer(address,uint256)" --private-key $DEPLOYER_KEY $ACCT1 50

cast call $FIDDY_CENT "balanceOf(address)" $ACCT1
@d-smith
d-smith / sign-auth-details.md
Created July 28, 2023 18:23
Details related to attempting to validate web3auth signed message

Here's the message signed in the web3auth example (modified):

const signMessage = async (): Promise<any> => {
    if (!provider) {
      console.log("provider not initialized yet");
      return;
    }
    const web3 = new Web3(provider);
 const fromAddress = (await web3.eth.getAccounts())[0];
@d-smith
d-smith / .deps...remix-tests...remix_accounts.sol
Created February 19, 2023 16:26
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
library TestsAccounts {
function getAccount(uint index) pure public returns (address) {
address[15] memory accounts;
accounts[0] = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
accounts[1] = 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2;
@d-smith
d-smith / .deps...remix-tests...remix_accounts.sol
Created February 19, 2023 05:41
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
library TestsAccounts {
function getAccount(uint index) pure public returns (address) {
address[15] memory accounts;
accounts[0] = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
accounts[1] = 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2;
Add the payload as data, e.g.
$.data VARCHAR(256000)
CREATE OR REPLACE STREAM "DESTINATION_SQL_STREAM" (event_data VARCHAR(256000));
CREATE OR REPLACE PUMP "STREAM_PUMP" AS INSERT INTO "DESTINATION_SQL_STREAM"
SELECT STREAM "data" AS "event_data"
FROM "SOURCE_SQL_STREAM_001";

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@d-smith
d-smith / HelloWorld.java
Created April 30, 2016 15:08
Lambda Expressions
//Executed at http://www.tutorialspoint.com/compile_java8_online.php
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World");
java.util.function.Function<Integer,Integer> times2 = (Integer x) -> 2*x;
java.util.function.Function<Integer,java.util.function.Function<Integer,Integer>> timesN = x -> y -> x * y;
System.out.println(times2.apply(2));
System.out.println(timesN.apply(2).apply(3));
}
@d-smith
d-smith / basic-ddl.sql
Last active February 19, 2016 19:43
mariadb basics
show databases;
create database roll;
create user rolluser identified by 'rollpw';
create table if not exists roll.sample (
name varchar(128) primary key,
value varchar(256)
)
@d-smith
d-smith / stuff.txt
Last active February 19, 2016 00:05
docker compose and mariadb stuff
docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest
docker run -it --link some-mariadb:mysql --rm mariadb sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
sudo tar cvf ~vagrant/app-dev-volume-data.tar ./dvol
docker run -it --link vagrant_mariadb_1:mysql --rm mariadb sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'