Skip to content

Instantly share code, notes, and snippets.

@laalaguer
laalaguer / moving-mysql-data-directory-mac-os.md
Last active June 14, 2025 04:23
Moving MySQL data directory to external disk

Sometimes database is too large for Mac's internal disk. Moving data directory to an external HDD disk is required, and here is how.

Environment

  • Mac Mini 2025 (M4 chip) + HDD external drive formatted with APFS (defaut: case insensitive).
  • MySQL version v8.0.42.
  • Data ~200GB.

Failed Attempts

@laalaguer
laalaguer / find-account-has-code.py
Last active February 28, 2022 09:23
Find block that one account has code
''' Python script to find the earliest block that an account has code.
python3 find.py [node_url] [address]
'''
import sys
from typing import Union
from thor_requests.connect import Connect
from math import sqrt
class Uniswap:
def __init__(self, xs):
self.xs = xs
self.lastK = sqrt(xs[0] * xs[1])
def swap(self, i, dx):
d = self.xs[0] * self.xs[1]
# Speed up.
cache = {}
def f(n):
# Speed up.
if cache.get(n) != None:
return cache[n]
if n == 1:
print('n==1, directly return 1')
# No speed up.
def f(n):
if n == 1:
print('n==1, directly return 1')
return 1
p = [] # Storage for temp results.
for i in range(1, n): # i in [1, n)
temp = 1 + max(i-1, f(n-i))
p.append(temp)
@laalaguer
laalaguer / path-finder.js
Created December 6, 2021 11:32
Uniswap V2 route (path) finder for two tokens, if given a set of pools
class PathFinder {
constructor(pairs) {
this.graph = new Map()
pairs.forEach((item) => {
if (!this.graph.has(item[0])) {
this.graph.set(item[0], new Array())
}
if (!this.graph.has(item[1])) {
this.graph.set(item[1], new Array())
}
@laalaguer
laalaguer / path-finder-recursive.js
Last active December 6, 2021 11:33
Uniswap v2 path (route) finder between two tokens, only yields one route
class DotPath {
constructor(a, b) {
this.storage = [a, b]
}
hasDot(dot) {
switch (dot) {
case this.storage[0]:
return true
case this.storage[1]:
@laalaguer
laalaguer / test_abstract.py
Last active October 12, 2021 02:43
Python Abstract Override can be done with different func params but same name, no error is raised.
import abc
class A(abc.ABC):
@abc.abstractmethod
def foo(self):
print("abstract foo()")
class B(A):
def foo(self, who:str): # Note: function signature is different
print("hello", who)
@laalaguer
laalaguer / abstract-python.py
Created September 28, 2021 05:39
Python3 Interface and Abstract class
import abc
class MyInterface(abc.ABC): # Same as class MyInterface(metaclass=abc.ABCMeta)
def __init__(self, age: int):
print('MyInterface: init')
self.age = age
@abc.abstractmethod
def load_data(self, name: str):
# CPU temperature
read temperature < /sys/class/thermal/thermal_zone0/temp
printf "CPU:\t%s °C\n" $(($temperature/1000))
# Memory pressure
memtotal=0
memfree=0
while read -r name value unit; do
if [ "${name}" == "MemTotal:" ]; then
memtotal=${value}