Skip to content

Instantly share code, notes, and snippets.

View wjkoh's full-sized avatar
🎯
Focusing

Woojong Koh wjkoh

🎯
Focusing
View GitHub Profile
@wjkoh
wjkoh / .js
Created December 12, 2021 09:19
Error: cannot estimate gas; transaction may fail or may require manual gas limit
const hre = require("hardhat");
const BATON_CONTRACT_ADDR = "YOUR_BATON_CONTRACT_ADDRESSS";
async function main() {
const Batons = await hre.ethers.getContractFactory("Batons");
const batons = await Batons.attach(BATON_CONTRACT_ADDR);
console.log("Connected to batons at :", BATON_CONTRACT_ADDR);
// Calling read functions consecutively is fine.
@wjkoh
wjkoh / export_csv.py
Last active December 14, 2021 13:22
Export CSV from Google Spreadsheet using Python
import requests
import argparse
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--spreadsheet_id', type=str, required=True)
parser.add_argument('--gid', type=int, required=True)
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
args = parser.parse_args()
@wjkoh
wjkoh / options.lua
Last active August 26, 2023 08:20
LazyVim: Set working directory to the current file
-- ~/.config/nvim/lua/config/options.lua
-- See also https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file
--
-- Options are automatically loaded before lazy.nvim startup
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
-- Add any additional options here
vim.opt.autochdir = true
@wjkoh
wjkoh / dartls.lua
Last active December 8, 2023 03:01
LazyVim: Set up Dart and Flutter LSP
-- Copy this file to your ~/.config/nvim/lua/plugins/
-- This file was written by @cddm. See https://www.reddit.com/r/neovim/comments/14c5e6o/how_to_set_up_dartflutter_with_neovim/jojf4z5/
return {
{
"neovim/nvim-lspconfig",
opts = {
servers = {
dartls = {},
},
},
@wjkoh
wjkoh / DebugProfile.entitlements.xml
Last active August 29, 2023 09:03
Flutter: Your MacOS app retrieves empty data from Cloud Firestore
<!-- Update macos/Runner/DebugProfile.entitlements like the following. -->
<!-- See https://docs.flutter.dev/platform-integration/macos/building#setting-up-entitlements -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
@wjkoh
wjkoh / set-editor.fish
Last active October 20, 2023 08:27
Fish: Set NeoVim as your default editor
#!/usr/bin/env fish
# This will allow LazyGit and Ranger to use NeoVim as their editor.
set -Ux EDITOR nvim
@wjkoh
wjkoh / streams.dart
Created September 16, 2023 09:20
Flutter: A chain of two streams
class ProfileModel extends ChangeNotifier {
final Stream<User?> _userStream = FirebaseAuth.instance.authStateChanges();
User? user;
Stream<DocumentSnapshot<Profile>>? _profileStream;
Profile? profile;
ProfileModel() {
_userStream.listen((User? newUser) {
user = newUser;
profile = null;
@wjkoh
wjkoh / go_slog_critical.go
Last active April 11, 2024 16:36
go/slog: How to wrap slog's functions and report the correct source line number
const (
LevelCritical = slog.Level(12)
)
// Critical is an example of a user-defined logging function that wraps slog.
// The log record contains the source position of the caller of Critical.
func Critical(msg string, args ...any) {
if !slog.Default().Enabled(context.Background(), LevelCritical) {
return
}
@wjkoh
wjkoh / go.lua
Last active October 20, 2023 08:45
LazyVim: Install go.nvim plugin
-- Copy this file to your ~/.config/nvim/lua/plugins/.
-- Add $GOPATH/bin to $PATH. For example, `set -Ux GOPATH $HOME/go && fish_add_path $GOPATH/bin`
-- Consider using https://github.com/fatih/vim-go instead of go.nvim.
return {
{
"ray-x/go.nvim",
dependencies = { -- optional packages
"ray-x/guihua.lua",
"neovim/nvim-lspconfig",
"nvim-treesitter/nvim-treesitter",
@wjkoh
wjkoh / flutter-tools.lua
Created October 10, 2023 11:59
LazyVim: Install flutter-tools plugin
-- Copy this file to your ~/.config/nvim/lua/plugins/
-- See https://github.com/akinsho/flutter-tools.nvim for details.
return {
{
"akinsho/flutter-tools.nvim",
lazy = false,
dependencies = {
"nvim-lua/plenary.nvim",
"stevearc/dressing.nvim", -- optional for vim.ui.select
},