Skip to content

Instantly share code, notes, and snippets.

@sixertoy
Last active February 25, 2020 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixertoy/d202c94dd5ac7ee0ff7e569aded4f264 to your computer and use it in GitHub Desktop.
Save sixertoy/d202c94dd5ac7ee0ff7e569aded4f264 to your computer and use it in GitHub Desktop.
Some OSX tricks

macOS Tricks (maxOS Sierra 10.12.x)

Bash

  • Yes/No Prompt
  • Kill all node process killall node
  • Colors in Bash
  • Sublime Text Command Line
  • Load .env file in Bash
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

UI Configuration

  • Change default screenshots names
  • Mac Icons /System/Library/CoreServices/C­oreTypes.bundle/Contents/Resources

NodeJS

  • Kill all NodeJS Instances

Apache + PHP + MySQL

  • Apache
  • Virtual Hosts
  • MySQL
  • PHP

Apache

Create current user vhost file into home directory

cd ~
mkdir www
cd /etc/apache2/users
sudo nano username.conf

Edit username.conf file

Include /Users/username/vhosts.conf
sudo chmod 644 username.conf
cd /etc/apache2
sudo cp httpd.conf httpd.conf.bak
sudo nano httpd.conf

Edit httpd.conf file

#ServerName www.example.com
ServerName localhost

# modules
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

Include /private/etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf

Make a copy of http-userdir.conf file before modify

cd /etc/apache2/extra
sudo cp httpd-userdir.conf httpd-userdir.conf.bak
sudo nano httpd-userdir.conf

Edit httpd-userdir.conf file

# Settings for user home directories
#
# Required module: mod_authz_core, mod_authz_host, mod_userdir

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.  Note that you must also set
# the default access control for these directories, as in the example below.
#
UserDir www

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<IfModule bonjour_module>
       RegisterUserSite customized-users
</IfModule>

# load users apache configuration
Include /private/etc/apache2/users/*.conf

Restart apache/Reaload config

sudo apachectl -k restart

vhost file example

<Directory "/Users/username/workspaces/www">
  AllowOverride All
  Require all granted
  FallbackResource /index.php
  Options Indexes MultiViews FollowSymLinks
</Directory>

<VirtualHost *:80>
  ServerName mydomain.loc
  DocumentRoot "/Users/username/workspaces/www/myproject/wordpress/dist"
  # ErrorLog "/Users/matthieu/www/apache-error.log"
  # CustomLog "/Users/matthieu/www/apache-access.log" common
</VirtualHost>
```bash
if [ -f .env ];
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
#
if [ -f .env ];
then
unset $(cat .env | sed -E 's/(.*)=.*/\1/' | xargs)
fi
```

Extended 256 colors

printf '\e[48;5;%dm ' {0..255}; printf '\e[0m \n'

MySQL

brew install mysql
brew tap homebrew/services

Connect to MySQL

mysql -uroot -proot

Change password

mysqladmin -u root password 'yourpassword'

Start MySQL

brew services start mysql

Restart MySQL

brew services restart mysql

Stop MySQL

brew services stop mysql

MySQL Command Line

Show MySQL Port

mysql> SHOW VARIABLES WHERE Variable_name = 'port';

Show Databases

mysql> SHOW DATABASES;

Sequel Pro

Kill All NodeJS Instances

killall node

PHP

Edit httpd.conf file

cd /etc/apache2
sudo nano httpd.conf

# uncomment
LoadModule php5_module libexec/apache2/libphp5.so

Edit httpd-vhosts.conf file

cd /etc/apache2/extra
sudo nano httpd-vhosts.conf

# Add this block of code to the very top of the file:
<FilesMatch ".+\.html$">
  SetHandler application/x-httpd-php
</FilesMatch>

Restart apache/Reaload config

sudo apachectl -k restart

Default screenshots names

defaults write com.apple.screencapture name "whatever_"
killall SystemUIServer

Virtual Hosts in User Directory

Users/username/vhosts.conf

#Virtual Host Entry for projectfolder.localhost
<VirtualHost *:80>
  DocumentRoot "/Users/username/www/projectfolder"
  ServerName projectfolder.localhost
  ErrorLog "/Users/username/www/apache-error.log"
  CustomLog "/Users/username/www/apache-access.log" common
</VirtualHost>
cd /etc
sudo nano hosts

/etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
#Local sites
127.0.0.1       projectfolder.localhost
sudo apachectl restart

Prompt yes/no user

read -p "Upgrade package version ? (y/N)" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
  echo
  yarn version
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment