Skip to content

Instantly share code, notes, and snippets.

@lucymtc
lucymtc / launch.json
Created November 23, 2018 12:16
Visual Studio Code Xdebug config
// Install Extension https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
@lucymtc
lucymtc / normalizeURL.js
Created July 30, 2018 21:23
JavaScript, URL normalization, make sure HTML entities are escaped.
/**
* URL normalization, make sure HTML entities are escaped.
*
* @param String url
*
* @return String
*/
export function normalizeURL(url) {
const fixedEncodeURIComponent = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16)}`);
@lucymtc
lucymtc / toUnicode.js
Created July 30, 2018 10:27
JavaScript - String to Unicode
const toUnicode = (str) => {
let unicodeString = '';
for (var i = 0; i < str.length; i ++) {
let unicodeStr = str.charCodeAt(i).toString(16).toUpperCase();
while (unicodeStr.length < 4) {
unicodeStr = `0${unicodeStr}`;
}
@lucymtc
lucymtc / react-native-clear-cache.txt
Created May 16, 2018 21:18
React Native clear cache
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache
@lucymtc
lucymtc / gist:db00a275706ed971f82477ed648e4a20
Last active May 18, 2018 09:46
Android emulator network connection with Vagrant IP
cd /Users/lucy/Library/Android/sdk
tools/emulator -avd Nexus_5X_API_23 -writable-system&
prepare file /tmp/hosts with contents:
127.0.0.1 localhost
::1 ip6-localhost
192.168.50.4 politico.test
Then execute:
@lucymtc
lucymtc / gist:78306981bce5f04e4b362546b53939e8
Created December 12, 2017 22:32
Creating CA-Signed Certificates for Dev Sites
// Run in the Terminal
-----------------------------------------------
$ openssl genrsa -out mysite.dev.key 2048
$ openssl req -new -key mysite.dev.key -out mysite.dev.csr
-----------------------------------------------
Answer questions after this last command
Then:
Create a mysite.dev.ext
And copy the following.
@lucymtc
lucymtc / git-rename-branch.txt
Created October 3, 2017 20:17
Rename git branch local & remote
git branch -m old_branch new_branch
git push --set-upstream origin new_branch
git push origin :old_branch
@lucymtc
lucymtc / gist:1e5eadf39610e9435f14d602b4655df5
Last active September 28, 2017 10:28
workaround vvv2 with Variable VVV (vv create)
Using vvv2 with vv create from https://github.com/bradp/vv has incomaptibility
Workarund:
First add site to vvv-custom.yml
testvv:
skip_provisioning: false
hosts:
- testvv.dev
@lucymtc
lucymtc / wp_encrypt_decrypts_password.php
Created July 28, 2017 11:19
Encrypt/decrypt passwords
<?php
/**
* Encrypt password using OpenSSL
*
* @param string $password The password to encrypt.
*/
public function encrypt_password( $password ) {
$encryption_key = base64_decode( SECURE_AUTH_KEY );
$iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) );
$encrypted = openssl_encrypt( $password, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv );
@lucymtc
lucymtc / is_edit_screen.php
Created July 27, 2017 11:10
Checks if current screen is Edit screen of a given list of post types.
<?php
/**
* Return true if current screen is edit screen of a post type or list of post types.
*
* @param string|array $post_type Single or list of post types.
* @return boolean
*/
function is_edit_screen( $post_types = array() ) {
global $pagenow;
if ( 'post.php' !== $pagenow ) {