Skip to content

Instantly share code, notes, and snippets.

View csymlstd's full-sized avatar

Casey Milstead csymlstd

View GitHub Profile
@csymlstd
csymlstd / commands.sh
Created June 26, 2018 20:51
git commands
# go back to a commit and remove commits ahead
git reset --hard 203b24f
git push origin HEAD --force
@csymlstd
csymlstd / reset.sh
Created July 6, 2018 20:48
Reset MySQL Password on Ubuntu 16.04
# Stop MySQL Service
sudo systmctl stop mysql
# Make service directory and give permission to mysql to write
sudo mkdir /var/run/mysqld
sudo chown mysqld: /var/run/mysqld
# Start MySQL manually
sudo mysqld_safe --skip-grant-tables --skip-networking &
@csymlstd
csymlstd / remove-utf8-bom.js
Created September 26, 2018 19:35 — forked from antic183/remove-utf8-bom.js
remove utf-8 bom with javascript
// remove utf-8 BOM from ressource "res"
// res.charCodeAt(0) === 0xFEFF | res.charCodeAt(0) === 65279
if (res.charCodeAt(0) === 0xFEFF) {
res = res.substr(1);
}
@csymlstd
csymlstd / post_deployment.sh
Created October 23, 2018 22:30
atomic node_modules deployment
if [ -d "releases/${execution.to_revision.revision}" ] && [ "${execution.refresh}" = "true" ]; then echo "Removing: releases/${execution.to_revision.revision}" && rm -rf releases/${execution.to_revision.revision}; fi
if [ ! -d "releases/${execution.to_revision.revision}" ]; then echo "Creating: releases/${execution.to_revision.revision}" && cp -dR deploy-cache releases/${execution.to_revision.revision}; fi
echo "Checking if packages need to be updated"
cmp --silent ./releases/${execution.to_revision.revision}/package.json ./current/package.json || INSTALL_PACKAGES=true
if [ $INSTALL_PACKAGES == true ]; then cp -f ./releases/${execution.to_revision.revision}/package.json .; fi
if [ $INSTALL_PACKAGES == true ]; then echo "Installing packages" && npm install --production; fi
echo "Linking revision packages to cached packages" && cd ./releases/${execution.to_revision.revision} && ln -sfn /var/www/api/node_modules .
echo "Linking current to revision: ${execution.to_revision.revision}"
rm -f current
ln -s releases/
@csymlstd
csymlstd / containers.sh
Created November 8, 2018 18:10
Docker Containers
# Redis
docker run --name some-redis -p6379:6379 -d redis redis-server --appendonly yes
@csymlstd
csymlstd / custom-error.js
Created November 16, 2018 15:37
Custom Error class
// https://levelup.gitconnected.com/the-definite-guide-to-handling-errors-gracefully-in-javascript-58424d9c60e6
class CustomError extends Error {
constructor(code = 'GENERIC', status = 500, ...params) {
super(...params)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, CustomError)
}
@csymlstd
csymlstd / get_node_by_path.php
Created January 15, 2019 14:46 — forked from crittermike/get_node_by_path.php
Drupal 8 Get node ID by path alias
<?php
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');
if(preg_match('/node\/(\d+)/', $path, $matches)) {
$node = \Drupal\node\Entity\Node::load($matches[1]);
}
@csymlstd
csymlstd / stripe_error_handler.php
Created January 28, 2019 17:56
Stripe PHP Error Handling
<?php
# https://stackoverflow.com/questions/17750143/catching-stripe-errors-with-try-catch-php-method
try {
// Use a Stripe PHP library method that may throw an exception....
\Stripe\Customer::create($args);
} catch (\Stripe\Error\Base $e) {
// Code to do something with the $e exception object when an error occurs
echo($e->getMessage());
} catch (Exception $e) {
// Catch any other non-Stripe exceptions
@csymlstd
csymlstd / Form.php
Created February 17, 2019 03:42
Drupal 8: Attach an existing entity field to a custom form
<?php
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class CustomUserForm extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#parents'] = [];
$entity = \Drupal::service('entity_type.manager')->getStorage('user')->create();
@csymlstd
csymlstd / settings.local.php
Created March 26, 2019 15:13
Drupal 8 Local Settings
<?php
// @codingStandardsIgnoreFile
/**
* @file
* Local development override configuration feature.
*
* To activate this feature, copy and rename it such that its path plus
* filename is 'sites/default/settings.local.php'. Then, go to the bottom of