Skip to content

Instantly share code, notes, and snippets.

@jazio
jazio / gist:8afeb1e470453a72f2cf
Last active April 8, 2016 11:56
Make sure a JSON is valid
// Make sure that the media JSON is valid.
try {
parsed_json = JSON.parse(unparsed_json);
}
catch (err) {
parsed_json = null;
}
if (parsed_json) {
// Display its content
@jazio
jazio / gist:825997543f45ed55d6cffdc46feace02
Created July 11, 2016 12:13
Efficiently save database dumps with Drush
dump_dir="${HOME}/your/tmp/dumps" && project_name="SITE_NAME" && environment="production"
drush sql-dump > ${dump_dir}/${project_name}-${environment}.$(date '+%F-%H%M%S').sql
@jazio
jazio / README.md
Created May 18, 2017 08:32 — forked from chrisjacob/README.md
Setup GitHub Pages "gh-pages" branch as a subfolder within the "master" project on your local checkout - a step-by-step guide.

Intro

Setup GitHub Pages "gh-pages" branch as a subfolder within the "master" project on your local checkout.

IMPORTANT

If you plan on switching between different branches (e.g. git checkout master-experiment then revert back with git checkout master) you will loose your child folder from this tutorial (because it's in your .gitignore and is not part of your master branch).

@jazio
jazio / gist:cdd80d161e99bce5033afdbf97beeaef
Last active July 17, 2017 06:45
Simulate mySQL commands
# Simulate a deletion from database;
mysql> SELECT entity_id, language FROM field_data_body where language = 'und' AND entity_id IN (SELECT entity_id from field_data_body where language='en');
156 rows in set (0.05 sec)
# Need to delete 156 items but unsure if is a good idea
mysql> START TRANSACTION;
# Perform risky operation
mysql> DELETE FROM field_data_body WHERE language='und' AND entity_id IN (SELECT entity_id from (SELECT entity_id from field_data_body where language ='en') x);
mysql> SELECT entity_id, language FROM field_data_body where language = 'und' AND entity_id IN (SELECT entity_id from field_data_body where language='en');
0 rows in set (0.05 sec)
# Now, rollback will rollback changes. The opposite is COMMIT, when changes are commited and transaction is closed.
@jazio
jazio / gist:d53dc5f05d5c875bfec100ece1c499f1
Last active March 6, 2018 11:17
Using mySQL subqueries for selective deleting
mysql> select entity_id, language from field_data_body where entity_id = 9311;
+-----------+----------+
| entity_id | language |
+-----------+----------+
| 9311 | en |
| 9311 | und |
+-----------+----------+
2 rows in set (0.00 sec)
# I need to delete only those entries with language 'und'
# See which nodes
@jazio
jazio / gist:84c834a720875b4e389c703d473ab3f7
Created July 17, 2017 08:57
Keeping a fork up to date
git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
git pull upstream master
@jazio
jazio / docker-install.sh
Created March 5, 2018 14:09
Install Docker
apt-get update
apt-get -y install apt-transport-https ca-certificates
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get purge lxc-docker
apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
apt-get install -y docker-engine
service docker start
##################################
# Checkout the CentOS version
##################################
cat /etc/redhat-release
cat /etc/os-release
##################################
# Find out hostname and external IP
##################################
hostname
#!/bin/bash
#
# Install Docker, Docker Compose and DDEV on Ubuntu/Linux Mint
# Notes: Installing Docker with snap resulted into faulted issues.
# Basics
#```````````````````````````
@jazio
jazio / mint_goodies.sh
Created December 24, 2019 17:04
Install Goodies on Linux Mint/Ubuntu
#!/usr/bin/env bash
#############################################################
# Scope: Install goodies on linux mint.
#############################################################
# debug on/off.
# set -x
# Colors. 0 = Normal; 1 = Bold.