Skip to content

Instantly share code, notes, and snippets.

View rkaneko's full-sized avatar
🎯
Focusing

Ryota Kaneko rkaneko

🎯
Focusing
View GitHub Profile
@rkaneko
rkaneko / README.md
Created January 31, 2023 09:24
remark-gfm issue for mdast-util-find-and-replace by CommonJS module which may not support all module.exports as named exports
$ npm list mdast-util-find-and-replace
my-app@0.1.0 /home/rkaneko/workspace/axelglobe/docs.axelglobe.com
└─┬ remark-gfm@3.0.1
  └─┬ mdast-util-gfm@2.0.1
    └─┬ mdast-util-gfm-autolink-literal@1.0.3
      └── mdast-util-find-and-replace@2.2.2
@rkaneko
rkaneko / convert_featurecollection_into_multipolygon.sql
Created January 12, 2023 02:10
PostGIS query to convert FeatureCollection GeoJSON into MultiPolygon GeoJSON
WITH original AS (
SELECT
ST_Collect(ST_ShiftLongitude(ST_GeomFromGeoJSON(feat->>'geometry'))) geom
FROM (SELECT json_array_elements('HERE_IS_FEATURE_COLLECTION_GEOJSON'::json->'features') AS feat) AS f
)
SELECT ST_AsGeoJSON(o.geom) FROM original o LIMIT 1;
#!/bin/bash
PROGNAME=$(basename $0)
VERSION="1.0"
usage() {
echo "Usage: $PROGNAME [OPTIONS] FILE"
echo " This script is ~."
echo
echo "Options:"
@rkaneko
rkaneko / qgis.md
Last active February 29, 2020 13:57
Install qgis on Ubuntu 18.04

How to install QGIS on Ubuntu 18.04

$ sudo apt-get install python3-software-properties

$ sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

$ sudo apt-get update
@rkaneko
rkaneko / print_cpu_usage.py
Created February 18, 2020 04:29
Profile CPU usage in Python sing psutil.
import time
import multiprocessing as mp
import psutil
from typing import Any, Callable, List, Tuple
def monitor(target: Callable[..., Any], args: Tuple[Any, ...]) -> List[float]:
worker_process = mp.Process(target=target, args=args)
worker_process.start()
p = psutil.Process(worker_process.pid)
@rkaneko
rkaneko / sample.py
Created February 17, 2020 13:42
Put parquet file on MinIO (S3 compatible storage) using pyarrow and s3fs.
from typing import Any, Dict, List
import s3fs
from pyarrow import Table, parquet as pq
from pandas import DataFrame, Series
def to_df(data: List[Dict[str, Any]]) -> DataFrame:
df = DataFrame()
for item in data:
indexes = []
values = []
@rkaneko
rkaneko / psql-grant.md
Last active December 26, 2019 13:18
psql grant, logs configurations
# display privileges
SELECT grantee, privilege_type FROM information_schema.role_table_grants WHERE table_name='some_table_name';

  grantee  | privilege_type
-----------+----------------
 root      | INSERT
 root      | SELECT
 root      | UPDATE
 root | DELETE
@rkaneko
rkaneko / docker-disk-troubles.md
Last active December 20, 2018 13:00
Docker disk trouble shooting

Case: No space left on device error

# remove unnecessary images
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")

Case: Volumes are full

@rkaneko
rkaneko / README.md
Last active December 19, 2018 14:48
awk sample for mapping some column values in some .csv file

awk command sample for mapping some column values in some .csv file

$ cat origin.csv
id,created,notes
1,1518393600000,blahblah
2,1518393600000,foobar

# Case1: We want to all column2 values (e.g. unix timestamp-ish value) to formatted datetime
$ head -1 origin.csv > /dev/stdout && tail origin.csv -n+2 | awk -F "," '{gsub($2, strftime("%Y-%m-%d %H:%M:%S", substr($2, 0, 10))); print}' >> /dev/stdout
@rkaneko
rkaneko / test_connection.py
Created November 25, 2018 20:56
Verify to get Postgresql connection
import logging
import psycopg2
import sys
import traceback
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__file__)
log.setLevel(logging.INFO)