Skip to content

Instantly share code, notes, and snippets.

@virullius
virullius / gist:6136098
Created August 1, 2013 22:59
Search MySQL schema for a string
#!/usr/bin/env php
<?php
$usage = array(
'min_args' => '5',
'message' => "$argv[0] --host=example.com --schema=MyDB --user=user_name [--pass=\"secret\"] --search=\"any string\""
);
if( $argc < $usage['min_args'] ){
exit("{$usage['message']}\n");
}
@virullius
virullius / randomtip.sh
Last active December 21, 2015 20:10
BSD compatible random tool tip based on a Linux version from I-don't-know-where. Append to ~/.bashrc
echo "Did you know that:"; whatis $(ls -1 /bin | head -$(echo "$RANDOM % `ls -1 /bin | wc -l`" | bc) | tail -1)
@virullius
virullius / gist:6771935
Last active December 24, 2015 08:39
Prompt for password on linux/unix (BSD?) in terminal with ruby
def prompt_for_password(prompt = "Enter Password:")
print prompt
`stty -echo`
password = STDIN.gets
`stty echo`
print "\n"
password.chomp
end
password = prompt_for_password
@virullius
virullius / hidden_files.sh
Created January 3, 2014 06:02
Show or hide hidden files in Finder on Mac.
#!/bin/bash
if [ -n "$1" ]
then
if [ "$1" == "show" ]
then
defaults write com.apple.finder AppleShowAllFiles -boolean true
elif [ "$1" == "hide" ]
then
defaults delete com.apple.finder AppleShowAllFiles
fi
@virullius
virullius / extract-jpeg.rb
Created April 1, 2014 01:15
Extract JPEG files from disc image, block device or any other file.
if ARGV.empty?
puts "ERROR: missing arguments
usage: ruby #{$0} file [output]
\tfile\tthe file to scan; could be a regular file, disc image or block device
\toutput\t(optional) directory to save extracted files to. Default value is ./jpeg-files"
exit 1
end
file_path = ARGV[0]
file = File.open(file_path)
@virullius
virullius / gist:3d5e98936dcfe50e05a0
Created June 13, 2014 21:26
Number of cores (or threads if hyperthreaded) and CPU model name
echo $(grep processor /proc/cpuinfo | wc -l)"x" $(grep 'model name' /proc/cpuinfo | head --lines=1 | awk -F':' '{gsub(/^[ ]+/, "", $2);print $2}')
@virullius
virullius / hostname-to-lower.sh
Created June 18, 2014 16:39
Make hostname lowercase on linux
# set hostname to lower in /etc/hosts file
sed -i "s/$(hostname)/$(hostname | tr '[:upper:]' '[:lower:]')/" /etc/hosts
# set runtime hostname to lowercase
hostname $(hostname | tr '[:upper:]' '[:lower:]')
# save lowercase hostname to /etc/hostname file
hostname > /etc/hostname
@virullius
virullius / transfer_mysql_db.sh
Created August 27, 2014 21:29
Copy and rename MySQL database
#!/usr/bin/env bash
# transfer mysql database to different server with a new name
# such as production database to test database
read -p "source host:" SRC_HOST
read -p "user for host $SRC_HOST:" SRC_USER
read -p "password for $SRC_USER@$SRC_HOST:" -s SRC_PW; echo
read -p "source database name:" SRC_DB
read -p "target host:" TGT_HOST
@virullius
virullius / extract-site.php
Last active August 29, 2015 14:05
Convert / Extract EE+MSM site to single site EE database. (ExpressionEngine,MultiSiteManager)
#!/usr/bin/env php
<?php
/* convert Multi Site Manager (MSM) ExpressionEngine (EE) database to single site database.
* used to split a site to own EE instance without MSM.
* Deletes all sites other than site_id specified then changes specified sites id to 1.
* Ignores site_id 0, although I don't rememeber why.
* I ran it from Linux command line, no idea if it will run the same on Window or Mac.
*/
@virullius
virullius / args.sh
Created October 28, 2014 15:54
Shell argument examples (bash, sh, zsh)
echo "\$# is the number of arguments"
echo "$# arguments"
echo
echo "\$* is list of arguments joined into a string"
echo $*
echo
echo "\$@ is a sequence of strings, well suited to a for loop"
echo $@