Skip to content

Instantly share code, notes, and snippets.

View reaperes's full-sized avatar

Kim Namhoon reaperes

  • Seoul, Korea
View GitHub Profile
@reaperes
reaperes / assembly-simple.sol
Last active December 14, 2023 09:21
solidity assembly mload, add real-world example
pragma solidity ^0.8.9;
contract Simple {
function example() public pure {
address remote = 0x1111111111111111111111111111111111111111;
address local = 0x2222222222222222222222222222222222222222;
bytes memory path = abi.encodePacked(remote, local);
assembly {
return(0x00, x) // What number is suitable for x?
}
@reaperes
reaperes / remove-old-containers.sh
Created October 20, 2023 04:52
Remove unnecessary old containers
#!/bin/bash
# Must set container prefix
DELETE_REGEX="^temp-.*"
# protect containers regex
EXCLUDE_REGEX="(?!(jenkins|nginx))"
current=$(date +"%s")
deleteUntil=$(date -d '-3 days' +"%s")
/**
* Not working itself. only shows how to get block number from timestamp for example
**/
export async function findBlockNumberFromTimestamp(timestamp) {
invariant(timestamp <= new Date().getTime(), `timestamp: ${timestamp} should be less than or equal current timestamp`)
const targetTimestamp = convertToTimestampSeconds(timestamp)
const latestBlockNumber = await jsonRpcProvider.getBlockNumber()
const latestTimestamp = await blockTimestampFetcher.fetch(latestBlockNumber) as number
@reaperes
reaperes / api-response.md
Created January 13, 2022 06:03
api common response
@reaperes
reaperes / deploy.yml
Created January 13, 2022 01:14
Github deploy workflow vis CodeDeploy with github
name: Deploy main branch to production
on:
push:
branches: [ main ]
env:
DEPLOY_IAM_ROLE: arn:aws:iam::1234567890:role/deployer
GITHUB_REPOSITORY: org/repo
@reaperes
reaperes / deploy.yml
Created January 13, 2022 00:37
Github deploy workflow vis CodeDeploy with S3 bucket
name: Deploy main branch to production
on:
push:
branches: [ main ]
env:
DEPLOY_IAM_ROLE: arn:aws:iam::1234567890:role/deployer
jobs:
@reaperes
reaperes / calculate_thumbprint.sh
Created January 12, 2022 23:45
Generate github actions oidc thumbprints
#!/usr/bin/env sh
# ref:
# - https://github.com/awsdocs/iam-user-guide/blob/main/doc_source/id_roles_providers_create_oidc_verify-thumbprint.md
# - https://stackoverflow.com/questions/69247498/how-can-i-calculate-the-thumbprint-of-an-openid-connect-server
HOST=$(curl https://token.actions.githubusercontent.com/.well-known/openid-configuration | jq -r '.jwks_uri | split("/")[2]')
echo | openssl s_client -servername $HOST -showcerts -connect $HOST:443 2> /dev/null \
| sed -n -e '/BEGIN/h' -e '/BEGIN/,/END/H' -e '$x' -e '$p' | tail +2 \
@reaperes
reaperes / create-random-accounts.js
Created December 30, 2021 14:24
Create ethereum accounts
const ethers = require('ethers');
const entropy = ethers.utils.randomBytes(16); // or 32
const mnemonic = ethers.utils.entropyToMnemonic(entropy);
console.log(mnemonic);
const wallets = [];
const maxIdx = 10;
for (let i=0; i<maxIdx; i++) {
const wallet = ethers.Wallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0/${i}`);
@reaperes
reaperes / sync.sh
Created December 30, 2021 08:08
Sync bitbucket to github
#!/usr/bin/env sh
BITBUCKET_ID=
BITBUCKET_PW=
GITHUB_ID=
GITHUB_PW=
BITBUCKET=https://$BITBUCKET_ID:$BITBUCKET_PW@bitbucket.org/org/repo.git
GITHUB=https://$GITHUB_ID:$GITHUB_PW@github.com/org/repo.git
@reaperes
reaperes / .github_workflows_main.yml
Last active December 30, 2021 09:46
Web front deploy on AWS
name: Deploy main branch to production
on:
push:
branches: [ main ]
env:
DEPLOY_IAM_ROLE: arn:aws:iam::111111111111:role/deployer
DEPLOY_BUCKET: s3://bucket-name
CACHE_DIR: ${{ github.workspace }}/node_modules