Skip to content

Instantly share code, notes, and snippets.

@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"
@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: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 / 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 / mass_android_app_create.sh
Created November 14, 2013 15:06
Script for creating and building several android app build from single template app. Data for every app should be provided in csv file. Script creates new branch for every app, replaces necessary images (logos, icons, splash screens etc), makes changes in source files (change ids, names, colors etc), renames app, builds it and places final signe…
#! /bin/bash
# path to project dir
base_path=/home/username/apps/android_template/
# path to main app project
proj_path=${base_path}MainActivity/
# path to res dir
res_path=${proj_path}res/
# path to dir with images for all necessary branches
img_path=/home/username/apps/images/
@anscii
anscii / gist:7467721
Last active December 28, 2015 07:58
Loop through git branches and pick specific string from every branch
#!/bin/bash
# list all branches
git for-each-ref --format='%(refname:short)' refs/heads |
while read branch; do
# if [[ $branch == ru_template32 ]]; then
# exit 0
# fi
echo $branch
git checkout $branch
#!/bin/bash
find . -type f -printf '%p\n' | while read file; do
oldfile=$(basename "$file")
newfile=$(echo "$oldfile" | sed 's/OLDNAME.jpg/NEWNAME.jpg/g')
if [ ! "$newfile" == "$oldfile" ]; then
mv "$file" "${file%$oldfile}$newfile"
fi
done
git diff --no-prefix > patchfile
then apply the patch:
patch -p0 < patchfile
If you have an existing "git diff" patch file that was created without the "--no-prefix" option, you can apply that patch via:
patch -p1 < patchfile
this will ignore the default a/ b/ source prefixes.
@anscii
anscii / mass_svn_up.sh
Last active December 20, 2015 06:48
Mass svn up with auto svn+ssh password input via expect
#!/bin/bash
for PROJECT in Proj1 Proj2
do
echo "##############"
echo "Starting ${PROJECT} update..."
cd /home/username/httpdocs/services/projects/${PROJECT}
expect <<- DONE
spawn svn up
expect {
@anscii
anscii / expect_svn_up.sh
Created July 26, 2013 10:49
svn up with auto svn+ssh password input via expect
#!/usr/bin/expect
spawn svn up
expect {
"username@svn.domain.com's password:*" {
send -- "password\r"
exp_continue
}
eof {
exit 0}