Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrés Villarreal andrezrv

View GitHub Profile
@andrezrv
andrezrv / sql-variables.txt
Created Jun 24, 2013
How to use MySQL variables
View sql-variables.txt
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 Jun 24, 2013
How to Move WordPress Blog to New Domain or Location
View move-wordpress.sql
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 Dec 21, 2015
Custom configuration file for WP-Stack, loading a new set of tasks from db-tasks.rb and shared-tasks.rb.
View config.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 Dec 23, 2015
How to test exceptions in Grails using Spock.
View MyObject.groovy
package myapp.mypackage
/**
* Just an example of a domain class.
* @author andrezrv
*/
class MyObject {
String name
@andrezrv
andrezrv / MyBuildTestData.groovy
Last active Dec 24, 2015
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
View MyBuildTestData.groovy
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 Dec 25, 2015
How to display a notice in the admin section of WordPress.
View wordpress-admin-notice.php
<?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 Dec 26, 2015
Disable autoupdates in WordPress 3.7+.
View wp-config-no-autoupdates-example.php
<?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 Nov 1, 2013
Create a new MySQL user and grant all privileges.
View new-user.sql
GRANT ALL PRIVILEGES ON %DB_NAME%.* TO %DB_USER%@%DB_HOST% IDENTIFIED BY '%DB_PASSWORD%';
@andrezrv
andrezrv / varnish-purge-cache.sh
Created Nov 2, 2013
Purge all Varnish cache.
View varnish-purge-cache.sh
# Purge all Varnish cache
varnishadm "ban req.url ~ /"
@andrezrv
andrezrv / nginx-common.conf.c
Created Nov 2, 2013
Nginx common configuration for non-WordPress sites.
View nginx-common.conf.c
#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;
}