Skip to content

Instantly share code, notes, and snippets.

View tomazzaman's full-sized avatar

Tomaž Zaman tomazzaman

  • Codeable ApS
  • Slovenia
View GitHub Profile
@tomazzaman
tomazzaman / class-watermark-image.php
Created April 7, 2015 19:30
Watermarking uploads in WordPress with Imagemagick
function register_watermarked_size() {
add_image_size( 'watermarked', 550, 550, true ); // This is what should be uploaded
}
add_action( 'init', 'register_watermarked_size' );
class Watermark_Image {
// The attachment meta array
public $meta = array();
@tomazzaman
tomazzaman / acf-gravity-forms-v5.php
Created April 9, 2015 17:48
Gravity forms and Sidebar selector for Advanced Custom Fields V5
<?php
class acf_field_gravity_forms extends acf_field {
function __construct() {
$this->name = 'gravity_forms_field';
$this->label = __( 'Gravity Forms', 'acf' );
$this->category = __( "Relational", 'acf');
$this->defaults = array(
'multiple' => 0,
@tomazzaman
tomazzaman / admin-testimonials.js
Last active July 28, 2018 07:34
How to create a testimonial widget with Backbone
var myWidgets = myWidgets || {};
// Model for a single testimonial
myWidgets.Testimonial = Backbone.Model.extend({
defaults: { 'quote': '', 'author': '' }
});
// Single view, responsible for rendering and manipulation of each single testimonial
myWidgets.TestimonialView = Backbone.View.extend( {
@tomazzaman
tomazzaman / README.md
Last active March 31, 2021 06:30
Simple WordPress Optin form with CURL support

Simple Optin form example for WordPress

This is a simplified showcase of how you can easily build your own Optin form in WordPress.

It can connect to any API that supports cURL (most of them do). There is no error reporting implemented. It uses exit intent detection script called Ouibounce, which needs to be enqueued in your functions.php

See the tutorial here: How to build your own WordPress email form

import fs from 'fs';
import path, { resolve } from 'path';
import assert from 'assert';
import Module from 'module';
import jsdom from 'jsdom';
import Mocha from 'mocha';
import chokidar from 'chokidar';
// Let's import and globalize testing tools so
// there's no need to require them in each test
@tomazzaman
tomazzaman / runner.js
Created October 28, 2015 11:00
Fast mocha runner with instrumentation support. Run it with `babel-node runner.js`
import fs from 'fs';
import path, { resolve } from 'path';
import assert from 'assert';
import Module from 'module';
import jsdom from 'jsdom';
import Mocha from 'mocha';
import chokidar from 'chokidar';
import { isMatch } from 'micromatch';
import log from 'fancy-log';
import async from 'async';
var crypto = require("crypto");
var SECRET_KEY = 'MY_AWS_SECRET_KEY';
var POLICY_JSON = {
"expiration": "2030-12-01T12:00:00.000Z",
"conditions": [
{"bucket": "my-bucket-name"},
["starts-with", "$key", ""],
{"acl": "public-read"},
["starts-with", "$Content-Type", ""],
@tomazzaman
tomazzaman / generateSVG.js
Created January 16, 2016 19:33
Generate PNG from a React-powered SVG. Server-side.
/**
* Run this with `babel-node generateSVG.js`
*/
import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';
import childProcess from 'child_process';
import phantomjs from 'phantomjs';
import im from 'imagemagick';
import tmp from 'tmp';
import superagent from 'superagent';
import merge from 'lodash/merge';
import { camelizeKeys, decamelizeKeys } from 'humps';
import config from 'config';
const CALL_API = Symbol.for('Call API');
/**
* Prepare headers for each request and include the token for authentication.
* @param {Boolean} token Authentication token
@tomazzaman
tomazzaman / README.md
Last active April 19, 2024 17:01
Kill supervisor on Docker when any of the services fail

Killing supervisor if any of it's child processes fail

The trick is to only register the listener for events that indicate failure, namely

  • PROCESS_STATE_STOPPED
  • PROCESS_STATE_EXITED
  • PROCESS_STATE_FATAL

Once they do, we should send a SIGQUIT to Supervisor.