Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
🎯
Focusing

Jose Robinson jrobinsonc

🎯
Focusing
View GitHub Profile
@jrobinsonc
jrobinsonc / sw-await.js
Last active May 7, 2020 12:22 — forked from bakoushin/sw-await.js
Service Worker: Promises vs Async/Await
const version = 1;
const appPrefix = 'myApp-';
const staticCacheName = appPrefix + 'static-v' + version;
const imagesCacheName = appPrefix + 'content-imgs';
var allCaches = [
staticCacheName,
imagesCacheName
];
self.addEventListener('message', event => {

Drupal Drush Cheatsheet

Generate snapshot of the database

drush sql-dump > db.sql

Import database

<?php
# Tested on Drupal 7
$user = user_load(1);
$user->mail = 'asdf@asdf.com';
$user->pass = '123';
user_save((object) array('uid' => $user->uid), (array) $user);
<?php
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$special_query_results = new WP_Query( 'cat=5&order=random&tag=tech' );
set_transient( 'special_query_results', $special_query_results );
}
var_dump($special_query_results);
@jrobinsonc
jrobinsonc / get_current_url.php
Created March 2, 2020 14:49
Wordpress helper: Get current URL
<?php
/**
* Returns the current url.
*
* @return string
*/
function get_current_url() {
global $wp;
<?php
/**
* array_merge_recursive does indeed merge arrays, but it converts values with duplicate
* keys to arrays rather than overwriting the value in the first array with the duplicate
* value in the second array, as array_merge does. I.e., with array_merge_recursive,
* this happens (documented behavior):
*
* array_merge_recursive(array('key' => 'org value'), array('key' => 'new value'));
* => array('key' => array('org value', 'new value'));
@jrobinsonc
jrobinsonc / hidewpadminbar.php
Last active February 12, 2020 17:11
WordPress Plugin: Hide WP Admin Bar
<?php
/*
Plugin Name: Hide WP Admin Bar
Plugin URI: https://gist.github.com/jrobinsonc/fd229cef8df0e38205c0b96f2e455d16
Description: Hides the WordPress admin bar by clicking on the logo of the admin bar.
Author: Jose Robinsosn
Version: 1.0
Author URI: https://joserobinson.com
*/
@jrobinsonc
jrobinsonc / get_the_url.php
Last active February 10, 2020 22:10
Wordpress helper: Get the slug - Get the slug of a post or page.
<?php
function get_current_url() {
global $wp;
return home_url( $wp->request );
}
```shell
grep DB_NAME wp-config.php | awk -F "'" '{print $4}'
grep DB_USER wp-config.php | awk -F "'" '{print $4}'
grep DB_PASSWORD wp-config.php | awk -F "'" '{print $4}'
```