Skip to content

Instantly share code, notes, and snippets.

View twfahey1's full-sized avatar

Tyler Fahey twfahey1

View GitHub Profile
@nullvariable
nullvariable / private-files.php
Created September 29, 2020 18:43
Private Files Example for Pantheon
<?php
/**
* Plugin Name: Example Private Files
* Author: Doug Cone
* Description: Auth for Pantheon Private files
* Version: 0.1.0
*/
/**
* This doesn't protect direct access, you must move your files to a folder not accessible to the public, but accessible to this script.
@tannerhodges
tannerhodges / nginx-security-headers.conf
Last active August 7, 2020 15:21
HTTP Security Headers for Nginx & PHP
# Add HTTP Headers to improve site security.
# https://owasp.org/www-project-secure-headers/#tab=Headers
# X-Frame-Options: Stop people from loading your site in an iframe on their own site.
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
add_header X-Frame-Options "SAMEORIGIN";
# X-XSS-Protection: Stop pages from loading when the browser detects cross-site scripting (XSS) attacks.
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
add_header X-XSS-Protection "1; mode=block";
# Purge the Heroku Build Cache using the terminal. This requires a new deployment FYI.
# Replace appname with name of application on Heroku.
heroku plugins:install heroku-repo
heroku repo:purge_cache -a appname
git commit --allow-empty -m "Purge cache"
git push heroku master
@whoisryosuke
whoisryosuke / api-form-submit.js
Created October 3, 2018 17:14
React - Handling forms and submitting POST data to API -- @see: https://reactjs.org/docs/forms.html
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = { name: '' };
}
handleChange = (event) => {
this.setState({[event.target.name]: event.target.value});
}
/* This will work for any text entry except the forms */
Qualtrics.SurveyEngine.addOnload(function() {
var qid = this.questionId;
var placeholderText = 'I am different text';
jQuery('#' + qid + ' input[type="text"], #' + qid + ' textarea').attr('placeholder',placeholderText);
});
/*
This will work on a Form question (where there are multiple inputs)
@7rin0
7rin0 / test_parse_yaml_file.sh
Last active August 20, 2021 09:29
Parse yaml file using php cli and yaml mod
# Requirements: php, php-yaml (pecl extention)
php -r 'echo print_r(yaml_parse_file(__DIR__ . "/app/config/parameters.yml"), 1);'
@tokland
tokland / puppeteer-click-by-text.js
Last active August 11, 2023 03:48
Click link by text in Puppeteer
const puppeteer = require('puppeteer');
const escapeXpathString = str => {
const splitedQuotes = str.replace(/'/g, `', "'", '`);
return `concat('${splitedQuotes}', '')`;
};
const clickByText = async (page, text) => {
const escapedText = escapeXpathString(text);
const linkHandlers = await page.$x(`//a[contains(text(), ${escapedText})]`);
<?php
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$group_class = 'group-order-weight';
$items = [
1 => [
'id' => 2,
@jleehr
jleehr / README.md
Last active August 13, 2020 13:59
[Drupal 8] Alter route (permissions) for taxonomy vocabulary page

[Drupal 8] Alter route (permissions) for taxonomy vocabulary page

Needs the patch: https://www.drupal.org/node/1848686

Split "Administer vocabularies and terms" permission: Access the taxonomy overview page and Add terms in vocabulary name

File structure:

mymodule
|- src
@crittermike
crittermike / ExampleModuleController.php
Last active June 17, 2021 12:55
Example of overriding a route controller in Drupal 8
<?php
/**
* @file
* Contains \Drupal\example_module\Controller\ExampleModuleController.
*/
// THIS FILE BELONGS AT /example_module/src/Controller/ExampleModuleController.php
namespace Drupal\example_module\Controller;