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 / 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_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 / 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 / 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
_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 / 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}'"'`
@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 / 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 / bots.tsv
Last active December 22, 2017 12:34
Elecena crawling bots data flow
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 4 in line 1.
# processed 500 packets sniffed in 4346.42 sec as None
s0 bots-server 1.0000
bjornoya bots-server 0.9847
sphinx bots-server 0.5663
# processed 2000 packets sniffed in 275.36 sec as redis
mq::elecena_products::messages lpop consumer:bjornoya 1.0000
mq::elecena_products::messages lpop consumer:svalbard 0.5018
bots-server rpush mq::elecena_datasheets::messages 0.1816
bots-server rpush mq::elecena_products::messages 0.0073
@macbre
macbre / remove_dangling_images.sh
Created December 29, 2017 13:53
Docker helpers
#!/bin/bash
docker rmi -f $(docker images -f "dangling=true" --format "{{.ID}}")