Find all indexes in a postgres table
select
t.relname as table_name,
i.relname as index_name,
array_to_string(array_agg(a.attname), ', ') as column_names
from
pg_class t,
pg_class i,
| # -*- coding: utf-8 -*- | |
| """ | |
| Improving approximate nearest neighbour search with k-nearest neigbors. | |
| Using sklearn-KDTree here just for demonstration. You can plugin much faster | |
| nearest neigbour search implementations (flann, annoy to name a few) for | |
| better results. For benchmarks, check out: | |
| 1) Radim Řehůřek (author of gensim) - | |
| http://rare-technologies.com/performance-shootout-of-nearest-neighbours-intro | |
| 2) Erik Bernhardsson (author of annoy) - | |
| https://github.com/erikbern/ann-benchmarks |
| # -*- coding: utf-8 -*- | |
| import string | |
| import random | |
| import os | |
| import re | |
| from unicodedata import normalize | |
| from datetime import datetime | |
| import tempfile |
Find all indexes in a postgres table
select
t.relname as table_name,
i.relname as index_name,
array_to_string(array_agg(a.attname), ', ') as column_names
from
pg_class t,
pg_class i,
| mcn_name=MACHINE_NAME | |
| apt_url='https://apt.dockerproject.org' | |
| lsb_dist='ubuntu' | |
| dist_version='trusty' | |
| arch=$(docker-machine ssh ${mcn_name} dpkg --print-architecture) | |
| repo='main' | |
| docker-machine ssh ${mcn_name} "echo deb [arch=${arch}] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} | sudo tee /etc/apt/sources.list.d/docker.list" | |
| docker-machine ssh ${mcn_name} sudo apt-get update | |
| docker-machine ssh ${mcn_name} sudo apt-get install -y docker-engine | |
| docker-machine regenerate-certs ${mcn_name} |
| for i in $(docker-machine ls | grep digitalocean | awk '{print $1}'); do docker-machine ssh $i -- ls /swapfile || docker-machine ssh $i "fallocate -l 512M /swapfile && chmod 400 /swapfile && mkswap /swapfile" && docker-machine ssh $i "swapon /swapfile && echo '/swapfile none swap defaults 0 0' >> /etc/fstab" &>/dev/null; done |
| #!/usr/bin/env bash | |
| #copy this in a folder from path ex: /usr/local/bin | |
| #usage: docker-machine-rename default my-default | |
| OLD_MACHINE_NAME=${1:-default}; | |
| NEW_MACHINE_NAME=${2:-my-default-2}; | |
| STORE_PATH=`docker-machine inspect $OLD_MACHINE_NAME | grep -m 1 StorePath | cut -d ':' -f 2 | cut -c 3- | rev | cut -c 3- | rev`; | |
| mv "$STORE_PATH/machines/$OLD_MACHINE_NAME" "$STORE_PATH/machines/$NEW_MACHINE_NAME"; | |
| cp "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json" "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json.bak" |
| """ | |
| An OrderedSet is a custom MutableSet that remembers its order, so that every | |
| entry has an index that can be looked up. | |
| Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger, | |
| and released under the MIT license. | |
| Rob Speer's changes are as follows: | |
| - changed the content from a doubly-linked list to a regular Python list. | |
| Seriously, who wants O(1) deletes but O(N) lookups by index? | |
| - add() returns the index of the added item | |
| - index() just returns the index of an item |
| """ | |
| An OrderedSet is a custom MutableSet that remembers its order, so that every | |
| entry has an index that can be looked up. | |
| Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger, | |
| and released under the MIT license. | |
| Rob Speer's changes are as follows: | |
| - changed the content from a doubly-linked list to a regular Python list. | |
| Seriously, who wants O(1) deletes but O(N) lookups by index? | |
| - add() returns the index of the added item | |
| - index() just returns the index of an item |
| """ | |
| Code to evaluate simple boolean logic in python | |
| Taken from: http://stackoverflow.com/a/2472414/2353472 | |
| Examples | |
| >>> print nested_bool_eval('(True and False) or (True and False)') | |
| False | |
| >>> print nested_bool_eval('(True and False) or (True and (True or False))') | |
| True | |
| """ |
| # | |
| # simpleBool.py | |
| # | |
| # Example of defining a boolean logic parser using | |
| # the operatorGrammar helper method in pyparsing. | |
| # | |
| # In this example, parse actions associated with each | |
| # operator expression will "compile" the expression | |
| # into BoolXXX class instances, which can then | |
| # later be evaluated for their boolean value. |