Skip to content

Instantly share code, notes, and snippets.

View andrewjmead's full-sized avatar

Andrew Mead andrewjmead

View GitHub Profile
@andrewjmead
andrewjmead / jetformbuilder-submit-hook.php
Last active June 22, 2024 21:30
JetFormBuilder form submission hook for WordPress
<?php
/**
* JetFormBuilder has no documentation about what hooks they fire or when they fire them.
*
* I ended up digging into their source code to try and find an action that fires for all
* form submission, even if they don't have a custom "post submit action" set up.
*
* Using jet-form-builder/form-handler/after-send gets the job done.
*/
@andrewjmead
andrewjmead / timezone.php
Last active June 14, 2022 19:37
Calculate timezone offsets for PHP & WordPress
<?php
// This uses the wp option "gmt_offset" as "timezone_string" is not always defined
class Timezone
{
public static function utc_offset()
{
return '+00:00';
}
@andrewjmead
andrewjmead / example.js
Created May 10, 2017 18:02
Example of array find method
const users = [{
name: 'Andrew',
age: 26
}, {
name: 'Jen',
age: 28
}];
const foundUser = users.find((user) => user.name === 'Andrew');
@andrewjmead
andrewjmead / app.js
Created July 15, 2016 20:31
Bert IP Example
var express = require('express');
var app = express();
app.get('/', (req, res) => {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('IP', ip);
console.log('Request object', req);
res.json({
@andrewjmead
andrewjmead / app.js
Created July 7, 2016 18:07
Adam Gist
var someName = {
balance: 0
};
function deposit(account, amount){
account.balance += amount;
}
function withdraw(account, balance){
account.balance -= balance;
}
@andrewjmead
andrewjmead / reducer.js
Created July 6, 2016 13:17
Yann - Reducer
case 'TOGGLE_TODO':
return state.map((todo) => {
if (todo.id === action.id) {
var nextCompleted = !todo.completed;
return {
...todo,
completed: nextCompleted,
completedAt: nextCompleted ? moment().unix() : undefined
};
@andrewjmead
andrewjmead / app.js
Created July 1, 2016 12:49
Jerome Function Example
function add (a, b) {
return a + b;
}
add;
var React = require('react');
var ReactDOM = require('react-dom');
var expect = require('expect');
var $ = require('jQuery');
var TestUtils = require('react-addons-test-utils');
var Countdown = require('Countdown');
describe('Countdown', () => {
it('should exist', () => {
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('./file.pem'),
cert: fs.readFileSync('./file.crt')
};
var serverPort = 443;
@andrewjmead
andrewjmead / app.js
Created May 29, 2016 15:05
Pass By Reference
var users = [{
name: 'Andrew'
}];
var user = users[0];
user.name = 'Mike';
console.log(users); // [ { name: 'Mike' } ]