Skip to content

Instantly share code, notes, and snippets.

View islander's full-sized avatar

kiba islander

  • Innova Distribution
  • Moscow | Saint Petersburg
View GitHub Profile
@islander
islander / gist:631e9ca9b4d1c6443332
Created August 26, 2015 04:34
Python MySQL driver installation
apt-get install python-dev
apt-get install libmysqlclient-dev # libmariadbclient-dev
pip install MySQL-python
@islander
islander / month_range.py
Created September 9, 2015 07:12
Get the start and end date for the month
import datetime
import calendar
def get_month_day_range(date):
"""
For a date 'date' returns the start and end date for the month of 'date'.
Month with 31 days:
>>> date = datetime.date(2011, 7, 27)
>>> get_month_day_range(date)
@islander
islander / mysql_tables_size.sql
Last active June 6, 2019 06:23
Top 20 MySQL tables sorted by size
-- MySQL: Check table size, index size, number of rows and total size
-- (c)http://blog.kuroichiaki.com/2011/07/mysql-check-table-size-index-size-number-of-rows-and-total-size/
-- (c)https://www.percona.com/blog/2008/03/17/researching-your-mysql-table-sizes/
-- Top 20 tables
SELECT CONCAT(table_schema,'.',table_name) tables,
CONCAT(ROUND(table_rows/1000000,2),'M') rows_cnt,
CONCAT(ROUND(data_length/(1024*1024*1024),2),'G') data_size,
CONCAT(ROUND(index_length/(1024*1024*1024),2),'G') index_size,
@islander
islander / mysql_fast_drop_table.sql
Created October 15, 2015 04:44
MySQL fast drop big table
CREATE TABLE new_foo LIKE foo;
ALTER TABLE new_foo AUTO_INCREMENT = 1;
RENAME TABLE foo TO old_foo, new_foo TO foo;
DROP TABLE old_foo;
-A FORWARD -m string --string "BitTorrent" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string "BitTorrent protocol" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string "peer_id=" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string ".torrent" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string "announce.php?passkey=" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string "torrent" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string "announce" --algo bm --to 65535 -j DROP
-A FORWARD -m string --string "info_hash" --algo bm --to 65535 -j DROP
@islander
islander / fix_russian_sounds.sh
Created November 18, 2015 04:30
Fix russian language voicemail prompts for asterisk 11 in Ubuntu 14.04
#!/bin/sh
SOUNDS_DIR="/usr/share/asterisk/sounds/ru"
mkdir -p ${SOUNDS_DIR}
wget -q --no-check-certificate https://github.com/pbxware/asterisk-sounds/tarball/master -O- \
| tar xzv --strip-components 1 -C ${SOUNDS_DIR}
wget -q --no-check-certificate https://github.com/pbxware/asterisk-sounds-additional/tarball/master -O- \
| tar xzv --strip-components 1 -C ${SOUNDS_DIR}
@islander
islander / gist:e21555396045ee07eacd
Created November 24, 2015 02:33
Debian Jessie enable persistent journald
mkdir /var/log/journal
chgrp systemd-journal /var/log/journal
chmod 2755 /var/log/journal
#!/bin/bash
for filename in {moh,ivr}/*.wav; do
sox -V "$filename" -r 8000 -c 1 -t al ${filename/.wav/.alaw/} # IVR
sox -V "$filename" -r 8000 -c 1 -t gsm ${filename/.wav/.gsm/} # music on hold
done

Persist specific events into Redis datastore:

  1. Clone the Riemann Git repository (clones into directory riemann):
    $ git clone https://github.com/aphyr/riemann.git

  2. Checkout the last stable version (0.2.2 in our case):
    $ cd riemann
    $ git checkout tags/0.2.2

  3. Add Carmine dependency to riemann/project.clj:

@islander
islander / asterisk.cdr.sql
Last active February 15, 2023 00:27
Asterisk import Master.csv CDR ot MySQL
USE asterisk;
GRANT ALL PRIVILEGES ON asterisk.* TO 'asterisk'@'localhost' IDENTIFIED BY 'change_me';
FLUSH PRIVILEGES;
CREATE TABLE IF NOT EXISTS cdr (
id BIGINT(20) NOT NULL AUTO_INCREMENT,
accountcode VARCHAR(30),
src VARCHAR(64),
dst VARCHAR(64),
dcontext VARCHAR(32),
clid VARCHAR(64),