Skip to content

Instantly share code, notes, and snippets.

@douglascabral
douglascabral / mongodb-ubuntu-15.10
Created April 18, 2016 12:11
How to install MongoDB in Ubuntu 15.10
#In terminal execute
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install mongodb-org
#Create /lib/systemd/system/mongodb.service with contents:
[Unit]
Description=High-performance, schema-free document-oriented database
@douglascabral
douglascabral / qtranslate_cleanup.sql
Last active April 29, 2016 19:35 — forked from frnhr/qtranslate_cleanup.sql
clean database after qTranslate uninstall
# QTRANSLATE CLEANUP QUERIES
# create temp column to separate post content on <!--more--> tag to simplify queries
ALTER TABLE `wp_posts` ADD `tmp_excerpt` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
# split content
## fill `tmp_exceprt` column
UPDATE wp_posts SET tmp_excerpt =
@douglascabral
douglascabral / functions.php
Last active August 17, 2016 15:19
Clean wp_head
//
// Limpa wp_head().
//
function wp_head_cleanup () {
// Remove Discovery.
remove_action('wp_head', 'rsd_link');
// Remove Feed.
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
@douglascabral
douglascabral / render_css_scripts.php
Created May 30, 2016 12:44
Enqueue Styles e Scripts versioned in WP.
//
// Enqueue Styles e Scripts.
//
function render_css( $name, $path ) {
if ( preg_match('/^(\/\/|http)/', $path ) ) {
wp_enqueue_style( $name, $path );
} else if ( file_exists( get_template_directory() . $path ) ) {
$hash = md5_file( get_template_directory() . $path );
$path = get_template_directory_uri() . $path;
wp_enqueue_style( $name, $path, array(), $hash );
@douglascabral
douglascabral / functions.php
Created May 30, 2016 18:42
Remove updates WP
//
// Remove aviso de atualização
// Obs: Aparenta deixar o admin um pouco mais lento para mudar de página
//
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_core', create_function('$a', "return null;") );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
@douglascabral
douglascabral / functions.php
Created May 30, 2016 18:43
Remove menus admin WP
//
// Remove menus do admin
//
function remove_menus(){
remove_menu_page( 'index.php' ); //Dashboard
//remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
//remove_menu_page( 'edit.php?post_type=page' ); //Pages
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'link-manager.php' ); //Links
@douglascabral
douglascabral / mysql-dump-struct.sql
Last active June 16, 2016 14:25
MySQL Dump with triggers, views and no-lock (No Downtime)
mysqldump <DATABASE> --host=<IP_HOST> \
--user=<USER> \
--password=<PASSWORD> \
--port=3306 \
--single-transaction \
--routines \
--triggers \
--compress \
--no-set-names \
--skip-add-locks \
@douglascabral
douglascabral / mysql-dump-data.sql
Created June 16, 2016 15:01
MySQL Dump data (No Downtime)
mysqldump <DATABASE> --host=<HOST_IP> \
--user=<USER> \
--password=<PASSWORD> \
--port=3306 \
--single-transaction \
--compress \
--skip-comments \
--skip-add-locks \
--skip-triggers \
--no-create-db \
for branch in `git branch -r | cut -d '/' -f2` ; do git checkout $branch && git pull origin $branch ; done
@douglascabral
douglascabral / jwt.php
Last active July 25, 2023 03:44
Example of JWT with Pure PHP
<?php
$key = 'your-secret-key-here';
$header = [
'typ' => 'JWT',
'alg' => 'HS256'
];
$header = json_encode($header);
$header = base64_encode($header);