Skip to content

Instantly share code, notes, and snippets.

View ahaxu's full-sized avatar

AhaXu ahaxu

View GitHub Profile
@ahaxu
ahaxu / htr-mua-he-ruc-ro-2024.py
Last active May 9, 2024 01:39
htr-mua-he-ruc-ro-2024.py
def f(activities):
import math
from datetime import datetime
act_by_date = dict()
for act in activities:
if act.get('type') != "Run":
continue
km = round(act["distance"]/1000, 2)
@ahaxu
ahaxu / htmt-tho-xay-cha-lan-2024.py
Last active March 10, 2024 03:35
HTMT tho xay challenge 2024
def f(activities, team):
import math
from datetime import datetime
act_by_date = dict()
for act in activities:
dt_str = act.get('start_date_local') # 2021-02-12T20:40:00Z
dt_obj = datetime.strptime(dt_str, '%Y-%m-%dT%H:%M:%SZ')
# key for ac_by_date dict
dt_ymd = int("{}{}{}".format(dt_obj.year, dt_obj.month, dt_obj.day))
@ahaxu
ahaxu / distinctG.hs
Last active June 5, 2023 03:05
distinctG.hs
-- Link to youtube https://youtu.be/c4saFSUAmlg
-- | Remove all duplicate integers from a list. Produce a log as you go.
-- If there is an element above 100, then abort the entire computation and produce no result.
-- However, always keep a log. If you abort the computation, produce a log with the value,
-- "aborting > 100: " followed by the value that caused it.
-- If you see an even number, produce a log message, "even number: " followed by the even number.
-- Other numbers produce no log message.
--
-- /Tip:/ Use `filtering` and `StateT` over (`OptionalT` over `Logger` with a @Data.Set#Set@).
@ahaxu
ahaxu / ecert-sketch.sh
Last active April 27, 2023 03:58
gen sketch for cert
#!/bin/bash
set -e
#
# usage:
# cat athelete.txt | xargs -I$ sh -c './ecert-sketch.sh "$"'
#
slugify () {
@ahaxu
ahaxu / ecert.sh
Created April 27, 2023 03:27
ecert generate
#!/bin/bash
set -e
slugify () {
echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z
}
NAME=$1
DISTANCE=$2
LOOPS=$3
@ahaxu
ahaxu / vesting-sample.hs
Created March 18, 2023 06:14
vesting contract generated by chat gpt
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module VestingSpecificRecipient
( vestingSpecificRecipient
, LockParams(..)
, VestingSchema
@ahaxu
ahaxu / tmux copy to clipboard macOSx.md
Created March 11, 2023 11:46
tmux copy to clipboard macOSx

Env iterm2 macosx

  • Open the iTerm2 menu
  • Select Preferences
  • On the "General" tab, select "Selection."
  • Check "Applications in the terminal may access the clipboard."

need to run

@ahaxu
ahaxu / 3d-triathlon-tet-2023.py
Created January 6, 2023 05:07
3d-triathlon-tet-2023.py
def calculate_set3(rs, acts):
if len(acts) == 0:
return rs
brick = [acts[0]]
for i in range(len(acts)):
if i == 0:
continue
@ahaxu
ahaxu / vim_rebind_nav_insert_mode_command_mode.vimrc
Last active January 7, 2024 03:15
vim rebind move up down when in insert mode or command mode
" In insert or command mode, move normally by using Ctrl
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
cnoremap <C-h> <Left>
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-l> <Right>
@ahaxu
ahaxu / haskell_connect_db_with_options.hs
Last active December 6, 2022 02:43
haskell_connect_db_with_options.hs
import Database.PostgreSQL.Simple
import System.Environment
import Database.PostgreSQL.Simple.Options
getDBConn :: IO Connection
getDBConn = do
-- get db info
hostName <- getEnv "DB_HOST"
dbName <- getEnv "DB_NAME"
userName <- getEnv "DB_USER"