This file contains 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
# Related graphql-js issue: https://github.com/graphql/graphql-js/issues/2262 | |
const rewire = require('rewire'); | |
const rewiredExecuteModule = rewire('graphql/execution/execute'); | |
const completeValue = rewiredExecuteModule.__get__('completeValue'); | |
const handleFieldError = rewiredExecuteModule.__get__('handleFieldError'); | |
const { GraphQLError } = require('graphql'); | |
const { addPath, pathToArray } = require('graphql/jsutils/Path'); |
This file contains 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
ALTER TABLE my_table ADD COLUMN tsdoc tsvector; | |
CREATE INDEX my_table_tsvec_idx ON my_table USING GIN (customer_id, tsdoc); | |
-- Full text search for datafield specs | |
CREATE FUNCTION my_table_tsvec_trigger() RETURNS trigger AS $$ | |
BEGIN | |
NEW.tsdoc := | |
setweight(to_tsvector('simple', coalesce(NEW.name,'')), 'A') || | |
setweight(to_tsvector('simple', coalesce(NEW.description,'')), 'B'); | |
return NEW; |
This file contains 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
import re | |
from notion.client import NotionClient | |
def enumerate_notion_items( | |
view_url, id_col, created_at_col="created_time", token=None, client=None | |
): | |
""" | |
Given that a property with name e.g. "Item ID" exists for a notion dataset, | |
and that at least one item has a value for that property, this function |
This file contains 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
# Find python imports in current directory that are not part of the python standard library | |
function non-stdlib-imports () { | |
# Requires isort to be pip-installed | |
stdlib_mods=`python -c "import isort, sys; sys.stdout.write('|'.join(isort.settings.default['known_standard_library']))"` | |
non_stdlib_used_mods=`grep "import " $(find . -name "*.py") | cut -f2 -d ' ' | cut -f1 -d'.' | sort | uniq | grep -v -E $stdlib_mods` | |
grep -nRE "$non_stdlib_used_mods" | grep -e "import.* " -e "from.* " | |
} |
This file contains 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 archive_to_bytes(archive): | |
def to_seconds(s): | |
SECONDS_IN_A = { | |
's': 1, | |
'm': 1 * 60, | |
'h': 1 * 60 * 60, | |
'd': 1 * 60 * 60 * 24, | |
'y': 1 * 60 * 60 * 24 * 365, | |
} |
This file contains 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 IPython.core.history import HistoryAccessor | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
hist_access = HistoryAccessor() | |
start_times, n_cmds = zip(*list(hist_access.db.execute('select start, num_cmds from sessions'))) | |
num_cmds = pd.Series(n_cmds, index=start_times) | |
cmds_hod = num_cmds.groupby(num_cmds.index.hour).agg(sum) | |
starts = pd.Series(np.ones(len(start_times)), index=start_times) |
This file contains 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 __future__ import print_function | |
from collections import Iterable, Sized | |
def deprint(obj, depth=5, indent=0, size_limit=10, index=""): | |
if not depth: | |
print("".join([" "*indent,"[reached depth limit]"])) | |
return | |
type_str = type(obj).__name__ | |
if type(obj).__module__ != '__builtin__': | |
type_str = ".".join([type(obj).__module__, type_str]) |