Skip to content

Instantly share code, notes, and snippets.

View sondnm's full-sized avatar
🎯
Focusing

Son Dang sondnm

🎯
Focusing
View GitHub Profile
@sondnm
sondnm / erc20_balance_at_block.js
Created September 19, 2023 16:20
How to get an ERC20 token balance of an address at a particular block
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://eth.llamarpc.com');
const walletAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; // vitalik.eth
const contractAddress = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // weth
const tokenDecimals = 18;
// ERC20 ABI for balanceOf
const abi = [
@sondnm
sondnm / hardhat-init.sh
Created February 20, 2022 14:10
Init hardhat project
#!/bin/bash
yarn add --dev hardhat
npx hardhat
yarn add --dev @nomiclabs/hardhat-ethers @nomiclabs/hardhat-waffle @nomiclabs/hardhat-etherscan \
@typechain/hardhat @typechain/ethers-v5 @types/chai @types/chai-as-promised @types/mocha \
chai chai-as-promised \
dotenv ethereum-waffle ethers \
hardhat-abi-exporter hardhat-deploy hardhat-deploy-ethers \
hardhat-typechain ts-generator ts-node typechain typescript \
@openzeppelin/contracts
@sondnm
sondnm / reddit-upvoter.js
Last active May 8, 2021 10:11
Reddit upvoter
items = document.getElementsByClassName("icon-upvote") // new Reddit version
// items = document.getElementsByClassName("arrow up") // old Reddit version
Array.prototype.forEach.call(items, function(el, i){
setTimeout(function(){
el.click();
},1000 + ( i * 400 ));
});
@sondnm
sondnm / openssl-1.0.2t-reinstall.md
Last active December 28, 2020 10:07
[MacOS] Install openssl 1.0.2t using brew extract

Kudos to https://github.com/kensoh at aisingapore/TagUI#635 (comment)

brew uninstall openssl
brew tap-new $USER/old-openssl
brew extract --version=1.0.2t openssl $USER/old-openssl
brew install openssl@1.0.2t
brew install openssl
ln -s /usr/local/Cellar/openssl@1.0.2t/1.0.2t/lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
ln -s /usr/local/Cellar/openssl@1.0.2t/1.0.2t/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
@sondnm
sondnm / learning-computer-security.md
Created August 16, 2020 14:10 — forked from nfarrar/learning-computer-security.md
Learning Computer Security

Learning Computer Security

About This Guide

This is an opinionated guide to learning about computer security (independently of a university or training program), starting with the absolute basics (suitable for someone without any exposure to or knowledge of computer security) and moving into progressively more difficult subject matter.

It seems that most people don't realize how much information is actually available on the internet. People love to share (especially geeks) and everything you need to become well versed in computer security is already available to you (and mostly for free). However, sometimes knowing where to start is the hardest part - which is the problem that this guide is intended to address. Therefore, this guide can accuratley be described as a 'guide to guides', with additional recommendations on effective learning and execises, based on my own experiences.

Many of the free resources are the best resources and this guide focuses on them. It is intended to provided a comprehensive

@sondnm
sondnm / HTDP12.4.TF_solution.rkt
Created June 13, 2020 05:47 — forked from twfarland/HTDP12.4.TF_solution.rkt
My solution for exercise 12.4 in HTDP
;; 12.4 Rearranging words
;; a 'word' is either
;; 1 - empty, or
;; 2 - (cons a w) where a is a symbol
;; ('a, 'b,..., 'z) and w is a word
;; examples:
(define noword empty)
(define red (cons 'r (cons 'e (cons 'd empty))))
@sondnm
sondnm / shm_open_get.c
Created April 10, 2020 18:09
POSIX shared memory demo
// Eg: shm_open_get // => "Hello"
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>

Keybase proof

I hereby claim:

  • I am sondnm on github.
  • I am sondnm (https://keybase.io/sondnm) on keybase.
  • I have a public key ASCdm3ZFC1nMWSTi8axuQ26HLaJwJ7LUtlqczUMkKeYsAwo

To claim this, I am signing this object:

@sondnm
sondnm / lions-unix-source-code.c
Created March 2, 2020 15:38
Lions' Commentary on UNIX source code
0100: /* fundamental constants: cannot be changed */
0100: /* fundamental constants: cannot be changed */
0101:
0102:
0103: #define USIZE 16 /* size of user block (*64) */
0104: #define NULL 0
0105: #define NODEV (-1)
0106: #define ROOTINO 1 /* i number of all roots */
0107: #define DIRSIZ 14 /* max characters per directory */
0108:
@sondnm
sondnm / git-rubocop-pre-commit
Created May 28, 2019 09:25
Simple git hook to run Rubocop before committing
# .git/hooks/pre-commit
#! /bin/sh
inspected_files=$(git diff --diff-filter=ACMR --name-only HEAD)
if [ $(echo $inspected_files | wc -w) -gt "0" ];
then
bundle exec rubocop $inspected_files --force-exclusion --auto-correct
fi