Skip to content

Instantly share code, notes, and snippets.

@rutgerhensel
rutgerhensel / .htaccess
Created October 3, 2023 12:54
redirect all to another website
RewriteEngine on
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
@rutgerhensel
rutgerhensel / gist:cf76a3e09b63c2c4713723d4370d1d5e
Last active June 14, 2023 06:05
Find files, find contents in files, replace contents in files
# find all .env files and store in env_files.txt
find . -name \.env -type f > env_files.txt
# find oldstring in these files
for i in `cat env_files.txt`;do
grep -i "oldstring" $i
done
# find oldstring just with grep and no list of files
grep -ir --include \.env "oldstring"
@rutgerhensel
rutgerhensel / gist:7c753e5e848a59e67e3e269f7f970952
Created January 28, 2022 04:59
find files with zero byte null byte character
grep -irobUaP "\x00" *
@rutgerhensel
rutgerhensel / wordpress-url-replace.sql
Created September 11, 2021 07:27
Replace URL in WordPress via Database Query
UPDATE wp_options SET option_value = replace(option_value, 'oldurl.com', 'newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'oldurl.com','newurl.com');
UPDATE wp_posts SET post_content = replace(post_content, 'oldurl.com', 'newurl.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl.com','newurl.com');
git reflog expire --all --expire=now
git gc --prune=now --aggressive
-- select database first, update ID '999' 3x below, update user and password xxxxxxxxxxxxxxxx also
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('999', 'demo', MD5('xxxxxxxxxxxxxxxx'), 'Your Name', 'test@example.com', 'http://www.test.com/', '2020-05-15 00:00:00', '', '0', 'Your Name');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '999', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '999', 'wp_user_level', '10');
@rutgerhensel
rutgerhensel / split_and_stitch.sh
Last active October 7, 2018 13:07
split and stitch back
# split a file into 1GB chuncks foo.000 foo.001 etc.
split -b 1GB -d -a 3 my.tar.gz foo.
# to compare
md5sum my.tar.gz
# stitch files back together
cat foo.* > my.tar.gz
# stitch files back together (more specific)
cat foo.{000..012} > my.tar.gz
@rutgerhensel
rutgerhensel / email to me.sh
Created August 10, 2018 06:23
email a file to yourself
cat file.log | mail -s "subject.." my@example.com
@rutgerhensel
rutgerhensel / setpermissions.sh
Last active June 29, 2017 10:20
Set correct directory and file permissions recursively
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
@rutgerhensel
rutgerhensel / rename-directory-mac-os-x.git
Created February 17, 2016 23:53
git rename directory on mac os x
mv foo foo2
git add -A
git commit -m "renaming"
mv foo2 FOO
git add -A
git commit --amend -m "renamed foo to FOO"