Skip to content

Instantly share code, notes, and snippets.

View andrezrv's full-sized avatar

Andrés Villarreal andrezrv

View GitHub Profile
@andrezrv
andrezrv / sql-variables.txt
Created June 24, 2013 17:00
How to use MySQL variables
mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0003 | D | 1.25 |
| 0004 | D | 19.95 |
+---------+--------+-------+
@andrezrv
andrezrv / move-wordpress.sql
Created June 24, 2013 21:44
How to Move WordPress Blog to New Domain or Location
SELECT @old_domain := 'http://www.old-domain.com' , @new_domain := 'http://www.new-domain.com';
UPDATE wp_options SET option_value = replace(option_value, @old_domain, @new_domain) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, @old_domain, @new_domain);
UPDATE wp_posts SET post_content = replace(post_content, @old_domain, @new_domain);
@andrezrv
andrezrv / config.rb
Last active December 21, 2015 07:39
Custom configuration file for WP-Stack, loading a new set of tasks from db-tasks.rb and shared-tasks.rb.
# Customize according to your needed configuration
set :application, "Application Name"
set :repository, "git@github.com:user/repo.git"
set :db_repository, 'git@github.com:user/repo-db.git'
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
# This assumes you're using Git. Needed to run tasks in db-tasks.rb
set :git_user_name, "user"
@andrezrv
andrezrv / MyObject.groovy
Last active December 23, 2015 20:29
How to test exceptions in Grails using Spock.
package myapp.mypackage
/**
* Just an example of a domain class.
* @author andrezrv
*/
class MyObject {
String name
@andrezrv
andrezrv / MyBuildTestData.groovy
Last active December 24, 2015 00:39
How to test with Spock using Build Test Data Plugin for Grails. Spock Docs: http://docs.spockframework.org/ Build Test Data Docs & Repo: https://github.com/tednaleid/build-test-data
package myapp.downloads
import grails.test.mixin.TestFor
import spock.lang.Specification
import grails.buildtestdata.mixin.Build
/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor( Download )
@andrezrv
andrezrv / wordpress-admin-notice.php
Last active December 25, 2015 13:29
How to display a notice in the admin section of WordPress.
<?php
/**
* Displays a notice in the admin section under some condition.
*
* @author andrezrv
*/
function my_admin_notice() {
global $current_screen;
@andrezrv
andrezrv / wp-config-no-autoupdates-example.php
Last active December 26, 2015 19:49
Disable autoupdates in WordPress 3.7+.
<?php
# Disables all kind of file modifications:
# core, plugins and themes won't be auto-updated
# and file editors won't appear anymore in wp-admin.
define( 'DISALLOW_FILE_MODS', true );
# Disables all core updates:
define( 'WP_AUTO_UPDATE_CORE', false );
@andrezrv
andrezrv / new-user.sql
Created November 1, 2013 03:33
Create a new MySQL user and grant all privileges.
GRANT ALL PRIVILEGES ON %DB_NAME%.* TO %DB_USER%@%DB_HOST% IDENTIFIED BY '%DB_PASSWORD%';
@andrezrv
andrezrv / varnish-purge-cache.sh
Created November 2, 2013 06:07
Purge all Varnish cache.
# Purge all Varnish cache
varnishadm "ban req.url ~ /"
@andrezrv
andrezrv / nginx-common.conf.c
Created November 2, 2013 06:15
Nginx common configuration for non-WordPress sites.
#server {
# listen 80;
# root /srv/www/mysite;
index index.php index.html index.htm;
# server_name www.mysite.com;
location / {
try_files $uri $uri/ /index.html;
}