Skip to content

Instantly share code, notes, and snippets.

@anscii
anscii / svn_check_debug.sh
Last active December 29, 2015 17:29
Manual developer-side svn pre-commit hook. Put it inside your .bashrc and use "svnci -m 'some message' somefile anotherfile" instead of usual "svn ci -m 'some message' somefile anotherfile". All arguments for 'svnci' will be carefully redirected to actual 'svn ci' call. The function will 'rise error' if your diff contains var_dump or other debug…
svnci() {
greprc=$(svn diff | grep -wc -E '(echo|var_dump|print_r|var_export)')
if [[ $greprc == 1 ]] ; then
echo '###############################'
echo '### WARNING! DEBUG DETECTED ###'
echo '###############################'
svn diff | grep -E '(echo|var_dump|print_r|var_export|\+\+\+)'
else
if [[ $greprc == 0 ]] ; then
@anscii
anscii / gist:7786087
Last active December 30, 2015 05:59
Count mongo subarrays with filter by _id and subarray type
myres = db.tag_ru.aggregate(
{ $match: {_id: 1354987}},
{ $unwind: '$items'},
{ $match: {'items.type': "news"}},
{ $group: {_id: '$_id', items: {$sum: '$items'}}})
myres.result[0].items.length
@anscii
anscii / gist:8040820
Last active December 31, 2015 20:29
Count mongo subarrays with subarray field matching for all possible _ids
db.tag_ru.aggregate({ $unwind: '$items'}, { $match: { "items.type":"news"}}, { $group: {_id: '$_id', count: {$sum: 1}}}, {$group: {_id:null, cnt:{$sum:"$count"} } } )
@anscii
anscii / gist:8313678
Created January 8, 2014 08:41
Find all *.php files containing table_name AND any of words "insert|update|delete".
grep --include="*.php" -l -R table_name . | xargs egrep -l -i "insert|update|delete"