This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 传入轨迹抽样点,获取整条轨迹穿越地区 | |
* 300: 执行时间184.992ms | |
* 1000: 执行时间587.400ms | |
* 5000: 执行时间2834.339ms | |
* 10000:执行时间5526.228ms | |
*/ | |
CREATE OR REPLACE FUNCTION getAddressFromPoints(points_str text) | |
RETURNS text AS $$ | |
import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create extension plpythonu; | |
create type py_environ_type as (name text, value text); | |
create or replace function py_environ(name varchar DEFAULT NULL) | |
returns setof py_environ_type | |
as $$ | |
import os | |
aev = [] | |
if name is None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.proxy import Proxy | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
import zipfile | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER person_notify AFTER INSERT OR UPDATE OR DELETE ON income | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger( | |
'id', | |
'email', | |
'username' | |
); | |
CREATE TRIGGER income_notify AFTER INSERT OR UPDATE OR DELETE ON income | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger( | |
'id', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION add_timestamps_to_table(_table text, _type text) RETURNS void AS $$ | |
BEGIN | |
EXECUTE format('ALTER TABLE %I ADD COLUMN IF NOT EXISTS created_at %s', _table, _type); | |
EXECUTE format('ALTER TABLE %I ADD COLUMN IF NOT EXISTS updated_at %s', _table, _type); | |
END; | |
$$ LANGUAGE 'plpgsql'; | |
CREATE OR REPLACE FUNCTION set_timestamps_not_null_on_table(_table text) RETURNS void AS $$ | |
BEGIN | |
EXECUTE format('ALTER TABLE %I ALTER COLUMN created_at SET NOT NULL', _table); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION day_begin(dt timestamp with time zone DEFAULT CURRENT_TIMESTAMP) | |
RETURNS timestamp with time zone AS $$ | |
BEGIN | |
RETURN date_trunc('day', dt); | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE OR REPLACE FUNCTION day_end(dt timestamp with time zone DEFAULT CURRENT_TIMESTAMP) | |
RETURNS timestamp with time zone AS $$ | |
BEGIN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def interval_to_milliseconds(interval): | |
"""Convert a Binance interval string to milliseconds | |
:param interval: Binance interval string 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w | |
:type interval: str | |
:return: | |
None if unit not one of m, h, d or w | |
None if string not in correct format | |
int value of interval in milliseconds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uses the date_to_milliseconds and interval_to_milliseconds functions | |
# https://gist.github.com/sammchardy/3547cfab1faf78e385b3fcb83ad86395 | |
# https://gist.github.com/sammchardy/fcbb2b836d1f694f39bddd569d1c16fe | |
from binance.client import Client | |
import time | |
def get_historical_klines(symbol, interval, start_str, end_str=None): | |
"""Get Historical Klines from Binance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function customer_search_email_insert() | |
returns trigger | |
security definer | |
language plpgsql | |
as $$ | |
begin | |
insert into customer_search(customer_id, contact_method, is_stale, term, contact_id) | |
values(new.customer_id, 'Email', true, new.email_address, new.id); | |
return new; | |
end; |