Skip to content

Instantly share code, notes, and snippets.

@ByoungInKim
ByoungInKim / gist:0ef3ff04dfcef63f988ece638fdcea55
Last active July 1, 2019 02:44
Getting a percentage from MySql with a group by condition
SET @total=0;
SELECT
column_a,
column_b,
COUNT(*) AS cnt,
COUNT(*) / @total * 100 as p,
@total AS total
FROM
(
SELECT
@ByoungInKim
ByoungInKim / gist:f47e8956cc2740540e9fc448df2bb18a
Created May 21, 2019 09:56
move git repository with git history
# 1. Copy histroy from source repository
$ git clone --mirror [source repository]
# 2. move dir
$ cd [source repository].git
# 3. set dest repository
$ git remote set-url --push origin [dest repository]
# 4. push to dest repository
@ByoungInKim
ByoungInKim / executable_jar_pom.xml
Created May 12, 2017 09:32
How to Create Executable JAR file with resources and dependencies using Maven
<project ....>
<modelVersion>4.0.0</modelVersion>
<groupId>com.inventory</groupId>
<artifactId>Inventory</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Inventory Management</name>
<dependencies>
SELECT A.columnA
FROM TableA AS A
LEFT JOIN TableB AS B ON (A.columnA = B.columnA)
WHERE B.columnA IS NULL
@ByoungInKim
ByoungInKim / extract_recent_data_with_deduplicate_date.sql
Last active February 22, 2017 17:37
deduplicate data and then select recent data
-- deduplicate with recent data
SELECT * FROM
(
SELECT ROW_NUMBER() OVER(PARTITION BY date_key,CountryName ORDER BY regdatetime DESC) AS ROWNUM, *
FROM temp where packageName = 'com.test'
) A
WHERE ROWNUM = 1 AND date_key > '2017-01-10' order by date_key asc
-- example
/*
@ByoungInKim
ByoungInKim / get_row_count.sql
Created January 25, 2017 03:33
BigQeury - get partition table and table row count
-- strandard SQL
-- normal table
SELECT COUNT(*) `project_id.data_set.table_name`
-- partition table
SELECT COUNT(*) `project_id.data_set.table_name` Where _PARTITIONTIME = '2017-01-02'
@ByoungInKim
ByoungInKim / read_file.py
Created January 24, 2017 11:39
python - read file
import codecs
with codecs.open('filename.txt', 'r', 'utf-8') as f:
f.read()
@ByoungInKim
ByoungInKim / create_directory.py
Last active November 21, 2023 03:45
python - create directory if path if it doesn`t exist for file write
import os
directory = '/home/kenny/gist'
if not os.path.exists(directory):
os.makedirs(directory)