Skip to content

Instantly share code, notes, and snippets.

View bhubbard's full-sized avatar
:octocat:
Hello

Brandon Hubbard bhubbard

:octocat:
Hello
View GitHub Profile
@dustyfresh
dustyfresh / workerWAF.js
Last active August 24, 2021 14:24
Simple & experimental Web Application Firewall using Cloudflare's edge workers
/*
*
* Web Application Firewall built with Cloudflare workers
*
* Author: < https://twitter.com/dustyfresh >
*
* License: GPLv3 < https://www.gnu.org/licenses/gpl-3.0.en.html >
*
* Cloudflare worker documentation:
* < https://developers.cloudflare.com/workers/about/ >
@Hidden50
Hidden50 / mainpage.js
Last active May 31, 2018 00:04
basic Service Worker example
// ...
window.addEventListener('load', () => {
if('serviceWorker' in navigator) {
navigator.serviceWorker.register( './sw.min.js', { scope: "./" } )
.then( registration => {
const newWorker = registration.installing;
if (newWorker) {
newWorker.onstatechange = function() {
if (newWorker.state == 'activated' && !navigator.serviceWorker.controller) {
@icodeforlove
icodeforlove / worker.js
Last active May 31, 2018 00:02
GDPR Block All European Countries (Cloudflare Worker)
const BLOCKED_COUNTRIES = [
'AL', 'AD', 'AM', 'AT', 'BY', 'BE', 'BA', 'BG', 'CH', 'CY', 'CZ', 'DE',
'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GR', 'HU', 'HR',
'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MC', 'MK', 'MT', 'NO', 'NL', 'PL',
'PT', 'RO', 'RU', 'SE', 'SI', 'SK', 'SM', 'TR', 'UA', 'VA'
];
addEventListener('fetch', event => {
event.respondWith((async request => {
let country = request.headers.get('CF-IpCountry'),
@jakebellacera
jakebellacera / hubspot-adwords-gclid-tracking.js
Last active March 6, 2025 17:25
Simple HubSpot gclid tracking code integration
// The script below will ensure that gclid parameters are associated with
// contacts in HubSpot.
//
// A few things are required before this script will work:
//
// * You will need to have the HubSpot tracking code installed on the page. A
// few modifications will be required if you don't have the tracking code
// installed. Additionally, you will lose out on the built-in cross-domain
// features that the hubspot tracking code uses to store cookies.
// * You will need to have this script installed on every page.
@n-ts
n-ts / worker.js
Created October 3, 2018 20:21
Cloudflare Workers - Load balancing to nearest datacenter from current POP
/*
--------------------------------------------------------
Please note that this grouping is just for example...
You can rearrange POPs, remove or add dacaneters according to your needs.
--------------------------------------------------------
First, we have to get all Cloudflare POP codes (three letter airport codes) from https://www.cloudflarestatus.com/
North America is routed to Chigaco datacenter;
Europe, Africa and Middle East is routed to Amsterdam datacenter;
@robertuniqid
robertuniqid / example.php
Created January 8, 2019 11:07
PHP WordPress Example Nested parent->id mapping
<?php
/**
* If WordPress will ever work smoothly with procedures, we want to refactor this.
* @param $search_term
* @return array
*/
function example_nested_parent_map_search( $search_term ) {
global $wpdb;

WordPress + HubSpot

A Tale of Two Mis-Capitalized Words

Lately we’ve run into some trouble here and there with the Gravity Forms Hubspot Add-On (and/or the Zapier... zap... thing) de-authenticating and losing its connection to the mothership. As a “workaround” we’re being asked to use HubSpot forms instead, but that solution sucks because then we lose all those sweet Gravity Forms styles we worked so hard on during development (not to mention whatever fancy backend stuff we did using filters/actions)

So, I did a little digging and I found that it’s actually super easy to integrate the entire site, forms and all, directly into HubSpot with no Gravity Forms add-on or Zapier integrations. The trick is that you need to install HubSpot’s official plugin: Contact Form Builder for WordPress – Conversion Tools by HubSpot. The title makes it sound like this is something you would use instead of Gravity Forms, but what it actually does is add the Hubspot tracking code to your site and aut

@RiFi2k
RiFi2k / removeContent.js
Created June 21, 2019 18:04
Cloudflare Worker Function to find and replace content on a page
addEventListener("fetch", event => {
event.respondWith(handle(event.request))
})
async function handle(request) {
// Fetch from origin server.
let response = await fetch(request)
// Make sure we only modify text, not images.
let type = response.headers.get("Content-Type") || ""
@brenes
brenes / pagespeed_code.gs
Last active December 29, 2022 16:23
Page SPeed monitorization through Google Spreadsheet
// This script is based on https://ithoughthecamewithyou.com/post/automate-google-pagespeed-insights-with-apps-script
// STEP 0: Create a spreadsheet document on Google Drive, go to the code editor
// (in spanish "Editor de la secuencia de comandos").
// Then paste this code and modify it.
// STEP 1: Insert your pagespeed API KEY
var pageSpeedApiKey = '';
// STEP 2: Insert the monitored URL
@gzalinski
gzalinski / HubSpot & GravityForms
Created March 16, 2020 11:46
HubSpot CURL for Gravity Form
function curl_to_hubspot($entry, $str_post, $form_ID){
$hubspotutk = $_COOKIE['hubspotutk'];
$portalID = '******'; //HubSpot USER ID
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $entry['ip'],
'pageURL' => $entry['source_url'],
'pageName' => get_the_title( $entry['post_id'])