Skip to content

Instantly share code, notes, and snippets.

View chadhutchins's full-sized avatar

Chad Hutchins chadhutchins

View GitHub Profile
@chadhutchins
chadhutchins / mailchimp-v3-batch-updates.php
Created December 4, 2015 17:35
This script shows how to use the MailChimp v3 API to re-subscribe a large group of mistakingly unsubscribed email addresses in a MailChimp List. There are a couple examples commented out that can be used. The first shows how to look up the status of a batch API call sent to MailChimp. And the second shows how to make a batch API call to re-subsc…
<?php
// replace this with your mailchimp api key
$mailchimp_apikey = "mailchimp-api-key-goes-here";
// create mailchimp api object that is used later to make api calls
$mcapi = new MailChimp_API($mailchimp_apikey);
/**
// Use the following code if you want to look up the status of a batch call
@chadhutchins
chadhutchins / gist:1440602
Created December 6, 2011 23:36
Tarjan's strongly connected components algorithm in Javascript - followed pseudocode from http://en.wikipedia.org/wiki/Tarjan%E2%80%99s_strongly_connected_components_algorithm
window.onload = function() {
var v0 = new Vertex("0");
var v1 = new Vertex("1");
var v2 = new Vertex("2");
var v3 = new Vertex("3");
var v4 = new Vertex("4");
var v5 = new Vertex("5");
var v6 = new Vertex("6");
var v7 = new Vertex("7");
@chadhutchins
chadhutchins / AccountButtons.php
Created December 13, 2012 15:11
An easy way to add items to the action buttons used throughout the SugarCRM UI.
<?php
class AccountButtons {
function add()
{
// Based on what action we're in, add some buttons!
switch ($GLOBALS['app']->controller->action)
{
case "DetailView": // Add buttons to Detail View
@chadhutchins
chadhutchins / proxy.php
Last active December 6, 2019 18:00
Proxy Script to allow Sugar to Receive MailChimp Webhooks using SugarChimp
<?php
/**
If you want to keep your SugarCRM server non-accessible from the outside web
But you still want to receive MailChimp updates with SugarChimp, this script will help you do so
You need to make this script accessible from the outside web and it will allow MailChimp to connect to Sugar through the SuagrChimpWebhook entrypoint
All other Sugar requests will get ignored
Be sure to change the $sugar_url variable to the path of your index.php script inside your Sugar folder
*/
<?php
// given a proper $token and $consumer...
require_once('include/api/RestService.php');
require_once('clients/base/api/OAuth2Api.php');
$service = new RestService();
$api = new OAuth2Api();
client = ZAFClient.init();
var settings = {
url: '{{setting.sugarUrl}}',
headers: {'oauth-token': '{{setting.sugarOauthAccessToken}}'},
secure: true,
type: 'GET',
dataType: 'json',
contentType: 'application/json',
};
client.request(settings).then(function(data){console.log(data);});
@chadhutchins
chadhutchins / script.php
Last active June 29, 2016 05:32
SugarOutfitters Starter Webhook Script
<?php
// get the webhook response
$body = @file_get_contents('php://input');
// decode the json data into a php object
$response = json_decode($body);
// the webhook property tells us exactly which webhook event was fired
// so let's create a case for a few webhooks
-- works in MySQL, fails in MSSQL
SELECT * FROM contacts WHERE IFNULL(title,’’)=’CEO’;
-- works in MSSQL
SELECT * FROM contacts WHERE ISNULL(title,’’)=’CEO’;
-- works in MySQL, fails in MSSQL
SELECT * FROM contacts WHERE title=’CEO’ && title=’CTO’;
-- works in both MySQL and MSSQL
SELECT * FROM contacts WHERE title=’CEO’ AND title=’CTO’;
<?php
global $db;
echo $db->dbType;
if ($db->dbType == ‘mysql’) echo “MySQL is being used”;
if ($db->dbType == ‘mssql’) echo “MSSQL is being used”;