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 pareto_coef(data, is_already_sorted = False): | |
"""https://en.wikipedia.org/wiki/Pareto_principle""" | |
if not is_already_sorted: | |
data.sort(reverse=True) | |
data_len = len(data) | |
data_sum = sum(data) | |
acum = 0 | |
for i, value in enumerate(data,1): | |
acum += value | |
i_pct = 100*i/data_len |
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
MERGE targettable AS target | |
USING | |
( | |
select id, sub_id, somevalue from sometable_or_query | |
) | |
AS source | |
ON (target.id = source.id AND target.sub_id = source.sub_id) | |
WHEN NOT MATCHED BY SOURCE THEN | |
DELETE | |
WHEN MATCHED THEN |
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
WITH SpeciesCounts AS ( | |
SELECT | |
SpecieType, | |
COUNT(*) AS CountPerSpecies | |
FROM | |
Table | |
GROUP BY | |
SpecieType | |
), |
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
// This script loops though all collections of all db in a MongoDB and runs the compact operation on them | |
// Simply paste this into the Mongo shell | |
rs.secondaryOk(); // db.slaveOk(); for early versions | |
db.getMongo().getDBNames().forEach(function(dbName) { | |
if ("local" != dbName && "admin" != dbName && "system" != dbName && "config" != dbName /* use this to (re-)start: && dbName > "am"*/) { | |
var subject = db.getSiblingDB(dbName); | |
subject.getCollectionNames().forEach(function (collectionName) { | |
print(new Date() + ': Compacting: ' + dbName + " - " + collectionName); | |
sleep(1000); // assure a cancel (CTRL-C) after "done" is executed before compact command |
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
#!/bin/python3 | |
import re | |
import requests | |
SIZE_SUFFIX = {'tb': 1024*1024*1024*1024,'gb': 1024*1024*1024, 'mb': 1024*1024, 'kb': 1024, 'b': 1} | |
def read_size_data(url='http://127.0.0.1:9200/_cat/indices?h=index,pri.store.size'): | |
response = requests.get(url) | |
if response.status_code == 200: | |
return response.text |
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 time import sleep | |
import os | |
import json | |
def uncollapse(inp): | |
""" '0-2,6-8,9,10,23' -> 0,1,2,6,7,8,9,10,23 """ | |
res = [] | |
for items in inp.split(','): | |
if '-' in items: |
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 split_combination(s): | |
"iterative algorythm O(N) = 2**N. based on binary represenation split" | |
l = len(s)-1 | |
all_comb = [] | |
for i in range(2**l): | |
splitmap = bin(i)[2:].rjust(l,'0') | |
combination = [] | |
substr = s[0] | |
for splitflag, char in zip(splitmap, s[1:]): |
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
import ldap | |
login, password = 'login', 'password' | |
ctx = {} | |
ctx['action'] = 'initializing LDAP connection' | |
ldap_obj = ldap.initialize('ldap://active.directory.local') | |
ldap_obj.protocol_version=ldap.VERSION3 | |
ldap_obj.set_option(ldap.OPT_REFERRALS, 0) # ???? | |
ldap_obj.bind_s('ldap_bind_user', 'ldap_bind_password', ldap.AUTH_SIMPLE) | |
searchfilter = '(sAMAccountName=%(username)s)' % {'username': login} |
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
MAXJOBS=20 | |
for i in `seq 1 $MAXJOBS` ; do nice -n 19 gzip -c /dev/zero > /dev/null & done | |
while true | |
do | |
LA=`</proc/loadavg` && LA=${LA// */} | |
H=$(date +%M) && H=${H/0/} | |
G=`echo "(${MAXJOBS}/2)*(s(2*3.14159*${H}/60) +1 ) <= ${LA}" | bc -l` | |
test ${G} -lt 1 && for i in `seq 1 $MAXJOBS` ; do kill -SIGCONT %$i ; done || for i in `seq 1 $MAXJOBS` ; do kill -SIGSTOP %$i; done | |
sleep 1 |
NewerOlder