Skip to content

Instantly share code, notes, and snippets.

View andrezrv's full-sized avatar

Andrés Villarreal andrezrv

View GitHub Profile
@andrezrv
andrezrv / add-to-bin.sh
Last active December 27, 2015 10:39
Make a complete backup of your production website.
# Add scripts to /usr/bin
ln -s /srv/www/website/tasks/website-backup-applications.sh /usr/bin/website-backup-applications
ln -s /srv/www/website/tasks/website-backup-database.sh /usr/bin/website-backup-database
ln -s /srv/www/website/tasks/website-full-backup.sh /usr/bin/website-full-backup
ln -s /srv/www/website/tasks/website-switch.sh /usr/bin/website-switch
@andrezrv
andrezrv / parallax.js
Last active December 28, 2015 16:39
How to slow the scrolling of an HTML element to create a simple parallax effect using jQuery.
jQuery( document ).ready( function( $ ) {
var scrollable = $('#branding .navbar-inner');
var difference = 5;
if ( scrollable.length ) {
var a = document.body;
var e = document.documentElement;
@andrezrv
andrezrv / matrix.sh
Created December 19, 2013 00:42
Trigger a Matrix effect in your command line. Very unuseful, but nice and cool.
echo -e "\e[32m";
while :; do for i in {1..16};
do r="$(($RANDOM % 2))";
if [[ $(($RANDOM % 5)) == 1 ]]; then
if [[ $(($RANDOM % 4)) == 1 ]]; then
v+="\e[1m $r ";
else
v+="\e[2m $r ";
fi;
else
@andrezrv
andrezrv / tar-examples.sh
Created December 24, 2013 19:03
Examples on how to compress and uncompress using Tar.
###################
# Compress a folder
###################
tar czfv test.tar.gz test/
# "czfv" stands for "Compress Zip File Verbose"
# If you want bzip files, use "j" instead of "z".
###################
# Uncompress a file
###################
@andrezrv
andrezrv / upload-public-key.sh
Created December 26, 2013 12:00
Upload your public key to a remote server without using ssh-copy-id (i.e. for Windows/MINGW32 systems).
# Create ssh directory if it doesn't exist
mkdir -p ~/.ssh
# Go to ssh directory
cd !$
# Create public and private keys
ssh-keygen
# Upload your publick key to some server
cat ~/.ssh/id_rsa.pub | ssh user@host -p 22 "cat - >> ~/.ssh/authorized_keys"
@andrezrv
andrezrv / vvv-init-setup-plugins-post.sh
Last active August 29, 2015 13:55
Sample additional tasks for WordPress plugins installed via Peasant.
#!/bin/bash
#
# vvv-init-setup-plugins-post.sh
#
# This file will perform some additional tasks on installed plugins.
# Get Peasant from https://github.com/andrezrv/peasant-vvv-provider.
# Include config file.
this_dir="$(dirname `readlink -f $(dirname $0)/vvv-init.sh`)"
. "${this_dir}/config.sh"
@andrezrv
andrezrv / Vagrantfile.rb
Created February 11, 2014 21:11
Add CPUs to Vagrant VM
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", "3072"]
v.customize ["modifyvm", :id, "--cpus", "4"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
@andrezrv
andrezrv / jquery.animate-number.js
Last active August 29, 2015 13:57
A very simple animation for numbers.
jQuery( document ).ready( function( $ ) {
$.fn.animate_number = function( options ) {
options.fromNumber = options.fromNumber ? options.fromNumber : 0;
options.toNumber = options.toNumber ? options.toNumber : 0;
options.rounding = options.rounding ? options.rounding : 0;
options.thousands = options.thousands ? options.thousands : '';
options.decimals = options.decimals ? options.decimals : '.';
options.element = this;
@andrezrv
andrezrv / local-plugins.php
Last active August 29, 2015 13:58
A loader for plugins that should run only in local stages. Have a local-plugins folder containing plugins into wp-content, and a local-config.php called from wp-config.php in your local stage. Then declare the relative path of your local plugins and load them.
<?php
/*
Plugin name: Local Plugins
Description: A loader for plugins that should run only in local stages.
Author: Andrés Villarreal
Author URI: http://about.me/andrezrv
Version: 1.0
License: GPL2
*/
function local_plugins_setup() {
@andrezrv
andrezrv / avoid-wp-mail-when-local.php
Created April 7, 2014 19:40
Avoid sending mails when working locally.
<?php
/**
* Avoid sending mails when working locally.
*/
if ( ! function_exists( 'wp_mail' )
&& defined( 'WP_STAGE' )
&& 'local' == WP_STAGE
&& ( ! defined( 'WP_MAIL_LOCAL' ) || true !== WP_MAIL_LOCAL )
) {
function wp_mail( $to, $subject, $message, $headers = '' ) {