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
#!/bin/bash | |
sql_list="select table_schema, table_name from information_schema.tables where lower(engine) = 'myisam' and table_schema not in ('mysql', 'information_schema', 'performance_schema') order by data_length;" | |
mysql --batch --silent -e "$sql_list" |while read -r d t; do | |
printf "\n---\n$d.$t " | |
mysql --batch --silent -e "select (data_length+index_length)/1e6 from information_schema.tables where table_schema='$d' and table_name='$t';" | |
time mysql --batch --silent -e "alter table $d.$t engine='innodb';" | |
done |
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
#!/bin/bash | |
# https://gist.github.com/temoto/efc4cf36fe388b41715b | |
set -e | |
umask 0077 | |
cookie_path='/tmp/megafon-jar' | |
output_path=~/megafon-account.csv | |
username='EDIT' | |
password='EDIT' | |
url_base='https://EDIT' | |
url_path_init='/sc_cp_apps/login' |
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
#!/bin/bash | |
set -e | |
find . -print0 |fgrep -v --null-data --null '/.hg/' >tmp-asset-clean-all | |
egrep -hIor "/\w+/\w+\.(gif|jpg|jpeg|png|eot|svg|ttf|woff|webm|webp)" |sort -u >tmp-asset-clean-refs | |
for f in $(cat tmp-asset-clean-refs); do | |
dir=${f%%/*} | |
name=${f##*/} | |
if ! egrep --max-count=1 --null-data -q $f tmp-asset-clean-all; then | |
echo -e "\n\n$f not found. References:\n $(egrep -Inr $f)\n\n" | |
fi |
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
#include <stdbool.h> // bool, required | |
#include <stdio.h> // printf, only for debug | |
#include <stdlib.h> // uint8_t, required | |
#include <string.h> // memset, required | |
#define RING_BUFFER_SIZE 4 | |
#if RING_BUFFER_SIZE > 256 | |
#error "RING_BUFFER_SIZE must be <=256" | |
#endif |
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 multiprocessing as mp | |
import sys | |
import resource | |
def memory(): | |
self = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss | |
children = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss | |
return self + children |
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
# I will eat you family and your dog if you use FROM ubuntu for container that runs a service in production | |
# Reading: http://phusion.github.io/baseimage-docker/ | |
FROM phusion/baseimage:0.9.15 | |
# inspired by https://github.com/progrium/buildstep | |
RUN mkdir /build | |
ADD ./files-build/ /build/ | |
RUN chmod --recursive go-rwx /build | |
RUN LC_ALL=C DEBIAN_FRONTEND=noninteractive /bin/bash /build/prepare | |
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
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 shinglize(s): | |
return frozenset(s[i:i + 3] for i in xrange(len(s) - 2)) | |
def shingle_compare(sh1, string): | |
'''set(shingle), 'string' -> float 0..1 | |
''' | |
sh2 = shinglize(string) | |
if not sh1 or not sh2: | |
return 0 |
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
#!/usr/bin/env python3 | |
''' | |
каждый день{tab}13:45{tab}игнорируется{tab}http://ping.url/ | |
-> | |
45 13 * * *{tab}/usr/bin/curl -fsS 'http://ping.url/' | |
''' | |
import re | |
import sys |
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 django.db.models.sql import Query | |
from functools import wraps | |
import inspect | |
TRACE_THIS_QUERY = u'SELECT "blog_group"."id", "blog_group"."name", "blog_group"."arg" FROM "blog_group" INNER JOIN "blog_group_members" ON ("blog_group"."id" = "blog_group_members"."group_id") WHERE "blog_group_members"."user_id" = %s ' | |
def trace_get_compiler(fun): | |
@wraps(fun) |
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
try: | |
# DB profiling. | |
# TODO: extract this to separate module. | |
TERMINAL_WIDTH = 124 # fine for 15" in 12px mono font. | |
SHOW_TOP_N_QUERIES = 5 | |
import itertools | |
import textwrap | |
queries = django.db.connection.queries | |
if queries: |