Skip to content

Instantly share code, notes, and snippets.

View ilovejs's full-sized avatar
🐡

Hao ilovejs

🐡
  • 23:09 (UTC +10:00)
View GitHub Profile
@ilovejs
ilovejs / CTE_not_fun.sql
Created July 12, 2018 01:10
CTE has limitation
--https://www.citusdata.com/blog/2018/05/15/fun-with-sql-recursive-ctes/
--Return: x
WITH RECURSIVE tens(x) AS (
SELECT 10
UNION
SELECT x + 10 FROM tens WHERE x + 10 <= 100
)
SELECT x FROM tens;
--Without having to drop down to a procedural language like plpgsql or plv8.
@ilovejs
ilovejs / rds.sh
Created July 2, 2018 06:52 — forked from onyxraven/rds.sh
Amazon RDS Performance Tuning Settings
#XLarge DBInstanceClassMemory = 15892177440 = 14.8GB
#/32 = 496630545 = 473MB
#/64 = 248315272 = 236MB
#/128 = 124157636 = 118MB
#/256 = 62078818 = 59MB
#/512 = 31039409 = 29MB
#/12582880 = 1263 #default same divisor as max_connections = 4041.6MB = 4237924762
#/25165760 = 623 # half of max_connections = 1993.6MB
#/50331520 = 315 # quarter of max_connections = 1008MB = 1056964608
#*(3/4) #default innodb pool size = 11922309120
@ilovejs
ilovejs / gist:56b8ef100f1c1572df88b067f61967ec
Created July 2, 2018 06:51 — forked from douglasjarquin/gist:2208690
Amazon RDS Performance Tuning Settings
rds-modify-db-parameter-group {param-group-name} \
--parameters="name=character_set_server, value=utf8, method=pending-reboot" \
--parameters="name=collation_server, value=utf8_general_ci, method=pending-reboot" \
--parameters="name=tmp_table_size, value={DBInstanceClassMemory/16}, method=pending-reboot" \
--parameters="name=max_heap_table_size, value={DBInstanceClassMemory/16}, method=pending-reboot" \
--parameters="name=query_cache_type, value=1, method=pending-reboot" \
--parameters="name=query_cache_size, value=131072, method=pending-reboot" \
--parameters="name=table_open_cache, value=2500, method=pending-reboot" \
--parameters="name=join_buffer_size, value={DBInstanceClassMemory/64}, method=pending-reboot" \
--parameters="name=thread_cache_size, value={DBInstanceClassMemory/12582880}, method=pending-reboot" \
@ilovejs
ilovejs / histogram_in_pg.sql
Created April 12, 2018 00:39
histogram_in_pg.sql
SELECT
x,
WIDTH_BUCKET(x, 1, 10, 9) AS "x In Which Bucket ?"
FROM
generate_series(1, 10) x;
SELECT
ROW_NUMBER() OVER(),
*
FROM
@ilovejs
ilovejs / fuck_reporting.sql
Last active April 22, 2017 08:03
sql server, YTD profit, accumulative sum by product and week. Percentage of increate / decrease
drop table if exists sales;
create table sales (
prod_id int,
month_end varchar(10),
amount int
);
-- need to paddle zero if no sales, but we fill manually here
insert into sales values
(1, '2017-01-31', 100), (1, '2017-02-28', 300),
@ilovejs
ilovejs / isohybrid.pl
Created October 3, 2016 02:38 — forked from jsarenik/isohybrid.pl
isohybrid.pl from Syslinux-6.03
#!/usr/bin/perl
## -----------------------------------------------------------------------
##
## Copyright 2002-2008 H. Peter Anvin - All Rights Reserved
## Copyright 2009 Intel Corporation; author: H. Peter Anvin
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
## Boston MA 02111-1307, USA; either version 2 of the License, or
@ilovejs
ilovejs / video_to_audio.sh
Created August 6, 2016 17:00
strip audio from video using ffmpeg
#!/bin/bash
# usage:
# ls *.avi | ./video_to_audio.sh
# for f in `ls *.avi`;
# do
# echo item: $f
# done
@ilovejs
ilovejs / progress-bar.sh
Created August 6, 2016 16:26 — forked from F1LT3R/progress-bar.sh
Bash Progress Bar
#!/bin/bash
# Bash Progress Bar: https://gist.github.com/F1LT3R/fa7f102b08a514f2c535
progressBarWidth=20
# Function to draw progress bar
progressBar () {
# Calculate number of fill/empty slots in the bar
% !TeX spellcheck = <yes>
\documentclass[14pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\author{MZ}
\title{Share Terms}
\begin{document}
# a slightly more realistic version of the 'Healthy' vs. 'Fever' model is outlined and then generated
import random
states = ('Healthy', 'Fever')
observations = ('normal', 'cold', 'dizzy')
start_probability = {'Healthy': 0.6, 'Fever': 0.4}
transition_probability = {
'Healthy' : {'Healthy': 0.8, 'Fever': 0.2},
'Fever' : {'Healthy': 0.4, 'Fever': 0.6}