Skip to content

Instantly share code, notes, and snippets.

View macbre's full-sized avatar
🏠
Working from home

Maciej Brencz macbre

🏠
Working from home
View GitHub Profile
@macbre
macbre / example.tsv
Last active December 18, 2017 22:15
data-flow redis ngrep
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
# processed 2000 packets sniffed in 275.36 sec as redis
mq::elecena_products::messages lpop 172.17.0.3
86.105.54.80 rpush mq::elecena_products::messages
mq::elecena_products::messages lpop 86.105.54.80
86.105.54.80 rpush mq::elecena_datasheets::messages
@macbre
macbre / insert_ignore.md
Created December 16, 2017 13:52
INSERT IGNORE example
mysql@geo-db-specials-master.query.consul[specials]>SELECT * from events_local_users where user_id = 1624842 limit 20;
+---------+---------+---------------------+-------+---------------------+---------------+------------+---------------------------+----------------------------+-----------------+----------------+
| wiki_id | user_id | user_name           | edits | editdate            | last_revision | cnt_groups | single_group              | all_groups                 | user_is_blocked | user_is_closed |
+---------+---------+---------------------+-------+---------------------+---------------+------------+---------------------------+----------------------------+-----------------+----------------+
|  604442 | 1624842 |                     |     0 | 2017-12-14 08:04:57 |             0 |          1 | poweruser                 | poweruser                  |               0 |              0 |
|  652499 | 1624842 | 3                   |     0 | 2016-03-28 00:47:55 |        752875 |          0 | sysop          
@macbre
macbre / drop_per_wiki_table.sh
Created December 7, 2017 13:08
Wiki tables cleanup
#!/bin/bash
CLUSTER=$1
TABLE_NAME=user
echo "Will remove per-wiki '${TABLE_NAME}' tables on '${CLUSTER}' cluster..."
WIKICITIES_PARAMS=`dbparams.pl --name wikicities_${CLUSTER} --type=slave`
MASTER_PARAMS=`dbparams.pl --name wikicities_${CLUSTER} --type=master`
for DBNAME in `mysql $WIKICITIES_PARAMS --batch --disable-column-names -e 'select TABLE_SCHEMA as wiki_db FROM information_schema.TABLES WHERE TABLE_NAME="'${TABLE_NAME}'"'`
_sshCompletion () # By convention, the function name
{ #+ starts with an underscore.
local cur
# Pointer to current completion word.
# By convention, it's named "cur" but this isn't strictly necessary.
COMPREPLY=() # Array variable storing the possible completions.
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( compgen -W 'dev-macbre cron-s1 job-s1' -- $cur ) )
@macbre
macbre / gist:f52aa0c19d8b046b278584a88585bb0d
Created November 25, 2017 19:04 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
@macbre
macbre / swap.sh
Created November 20, 2017 21:03
Swap file
$ sudo -i
cd /var
touch swap.img
chmod 600 swap.img
dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
mkswap /var/swap.img
swapon /var/swap.img
echo "/var/swap.img none swap sw 0 0" >> /etc/fstab
@macbre
macbre / events_local_users.tsv
Created November 14, 2017 11:41
events_local_users queries
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
# Query digest for "events_local_users" table, found 502190 queries
backend:events_local_users.pl events_local_users.pl:651 (INSERT) specials:events_local_users 1.00 job, median time: 84.90 ms, count: 24469000
backend:events_local_users.pl events_local_users.pl:646 (DELETE) specials:events_local_users 1.00 job, median time: 77.01 ms, count: 24485000
specials:events_local_users events_local_users.pl:223 (SELECT) backend:events_local_users.pl 0.02 job, median time: 66.78 ms, count: 520100
specials:events_local_users getTopEditors WikiService 0.01 ap, median time: 146.29 ms, count: 158200
specials:events_local_users loadData ListusersData 0.00 ap, median time: 548.60 ms, count: 16400
backend:events_local_users.pl events_local_users.pl:574 (DELETE) specials:events_local_users 0.00 job, median time: 379.60 ms, count: 5800
specials:events_local_users getTopWikisFromDb FavoriteWikisModel 0.00 ap, median time: 36.22 ms, count: 37400
specials:events_local_users GetTopFiveUsers DataProvider 0.00 ap, median time: 150.80
@macbre
macbre / mediawiki.xml
Created November 14, 2017 10:48
PHPStorm MediaWiki code style
<code_scheme name="MediaWiki">
<option name="LINE_SEPARATOR" value="&#xA;" />
<PHPCodeStyleSettings>
<option name="COMMA_AFTER_LAST_ARRAY_ELEMENT" value="true" />
<option name="BLANK_LINE_BEFORE_RETURN_STATEMENT" value="true" />
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
</PHPCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
@macbre
macbre / events.log
Created November 4, 2017 14:35
index-digest
$ index_digest mysql://foo:bar@server/stats
------------------------------------------------------------
Found 5 issue(s) to report for "stats" database
------------------------------------------------------------
MySQL v5.6.24-72.2-log at statsdb-s2
index-digest v0.1.0
------------------------------------------------------------
redundant_indices → table affected: events
✗ "user_id_idx" index can be removed as redundant (covered by "for_editcount_idx")
@macbre
macbre / log.sql
Created October 28, 2017 17:10
Elecena SQL log
-- bots
SELECT * FROM products WHERE prod_id IN (7205887,7895047,7895046,7989641,9369286,9369287,9369890,9369891,9369895,9369896,9552054,9552055,9557908,9631579,1011753,1035788,1212991,1010860,1010861,1009436,2788153,4583962,1012990,1012987,1012985,1009476,1009477,1009478,1009479,1009480,1009481,1009482,1009484,1009485,1009486,1009488,1009487,1009489,1009483,1010957,1011751,1012979,1012957,1012958,1012959,1009504,1010856,1016005,1010142,1009439,1012944,1009490,1012946,1010141,1010149,1014468,1012963,1012962,1011752,1013029,1010858,1012789,1012971,1012973,1012974,1012975,1012976,1012977,1012978,1014431,1012980,1012948,1010863,1009437,1009438,1010857,1012984,1009741,1010864,1012981,1012982,1009428,1010262,1012992,1010139,1012986,1010305,1010306,1009440,1009442,1009441,1009443,1009444,1012942,1010215,1033572,1012964,1212993,1212994,1009433,1212996,1212995,1212992,1012949,1016007,1016009,1016008,1010169,1031334,1009502,1012956,1012960,1212997,1014286,1010148,1010143,1009422,1009423,1009424,1009425,1009426,1009427