Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@ethangardner
ethangardner / .ctags
Created December 17, 2019 20:46
ctags support for SCSS files and other config.
# Exclude directories
--exclude=node_modules
--exclude=.DS_Store
--exclude=.git
--exclude=*.zip
--exclude=tags
--exclude=build
--exclude=dist
--langdef=scss
@ethangardner
ethangardner / prettier_file.js
Created August 20, 2019 17:25
Komodo userscript to format files with prettier.
var view = require("ko/views").current();
var shell = require("ko/shell");
var filename = view.title;
var filePath = view.filePath;
var types = [
'scss',
'js',
'jsx'
];
@ethangardner
ethangardner / wp-rest-api-error-log.php
Created April 9, 2019 19:06
Log WordPress REST API Errors
<?php
/**
* Log REST API errors
*
* @param WP_REST_Response $result Result that will be sent to the client.
* @param WP_REST_Server $server The API server instance.
* @param WP_REST_Request $request The request used to generate the response.
*/
function log_rest_api_errors( $result, $server, $request ) {
if ( $result->is_error() ) {
@ethangardner
ethangardner / wp-rest-api-query-log.php
Created April 9, 2019 19:05
Log WordPress REST API Queries
<?php
/**
* Log REST API queries
*
* @param WP_REST_Response $result Result that will be sent to the client.
* @param WP_REST_Server $server The API server instance.
* @param WP_REST_Request $request The request used to generate the response.
*/
function log_rest_api_queries( $result, $server, $request ) {
global $wpdb;
@ethangardner
ethangardner / user-owner.sh
Created January 9, 2019 14:16
Find files not owned by a specific user
find . \! -user foo -print
@ethangardner
ethangardner / awk-commands.md
Last active June 28, 2023 19:04
Useful awk commands for extracting data from logs

$1 is the first column. awk separates columns by spaces by default. delimiters can be specified with -F. In the examples below '[: ]' means that columns are delimited by spaces or colons.

99.56.8.181 10.0.1.239 - - [16/Nov/2018:20:45:59 +0000] "GET /app/themes/finecooking/dist/img/marketing-hero-cover.jpg HTTP/1.0" 200 38808 "https://www.finecooking.com/sw.js" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0"

Print IP and user agent for requests between the hours of 18 and 19

cat /var/log/httpd/access_log | awk -F'[: ]' '$6 >= 18 && $6 <= 19 { print }' | awk -F\" '{print $1,$6}' | more

@ethangardner
ethangardner / content-security-policy.conf
Last active January 9, 2019 14:14
Sample content security policy generated by the Mozilla Laboratory plugin
default-src 'none'; connect-src 'self' http://a.teads.tv/page/13273/ad http://bid.contextweb.com/header/tag http://c.brightcove.com/services/mobile/streaming/index/master.m3u8 http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8 http://f1.media.brightcove.com/1/51745662001/5705104670001/51745662001_5705104670001_s-1.ts http://f1.media.brightcove.com/1/51745662001/5705104670001/51745662001_5705104670001_s-2.ts http://f1.media.brightcove.com/1/51745662001/5705104670001/51745662001_5705104670001_s-3.ts http://f1.media.brightcove.com/1/51745662001/5705104670001/51745662001_5705104670001_s-4.ts http://f1.media.brightcove.com/1/51745662001/5726670397001/51745662001_5726670397001_s-2.ts http://f1.media.brightcove.com/1/51745662001/5726674484001/51745662001_5726674484001_s-1.ts http://f1.media.brightcove.com/1/51745662001/5726674484001/51745662001_5726674484001_s-2.ts http://f1.media.brightcove.com/1/51745662001/5726674484001/51745662001_5726674484001_s-3.ts http://f1.media.brightcove.com/3/5174566
@ethangardner
ethangardner / fix-wordpress-permissions.sh
Created February 8, 2018 15:51 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@ethangardner
ethangardner / facebook_leads.md
Last active April 4, 2018 21:28 — forked from tixastronauta/facebook_leads.md
Receiving Facebook Leads on a Webhook

Receiving Facebook Leads on a Webhook

1 - Create an App

Head over to developer.facebook.com and create an App

2 - Setup the webhook

On your server, create a facebook webhook that will handle facebook calls. Then create a "leadgen" webhook on you App: https://developers.facebook.com/docs/graph-api/webhooks/v2.11

# Based on https://develop.svn.wordpress.org/trunk/.editorconfig
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/
root = true