Skip to content

Instantly share code, notes, and snippets.

View shawncarr's full-sized avatar

Shawn Carr shawncarr

View GitHub Profile
@shawncarr
shawncarr / zodDecimal.spec.ts
Last active December 12, 2023 14:48
Zod Decimal
import Decimal from 'decimal.js';
import { ZodDecimal } from './zodDecimal.ts';
describe('ZodDecimal', () => {
const schema = ZodDecimal.create();
const gtFive = schema.gt(5);
const gteFive = schema.gte(5);
const minFive = schema.min(5);
const ltFive = schema.lt(5);
@shawncarr
shawncarr / mautic-form-preload.js
Last active April 15, 2020 16:39
Pre-populate Mautic Form Data from Query String Parameters
document.onreadystatechange = function () {
if (document.readyState == 'interactive') {
if (document.forms.length !== 0 && location.search) {
var query = location.search.substr(1);
query.split('&').forEach(function (part) {
if (part.indexOf('=') !== -1) {
var item = part.split('=');
var key = item[0];
var value = decodeURIComponent(item[1]);
var inputs = document.getElementsByName('mauticform[' + key + ']');
@shawncarr
shawncarr / href.js
Created October 13, 2014 15:54
Angular - Prevent default actions on A links with a ngClick or blank href
angular.module('app').directive('href', function() {
return {
restrict: 'A',
compile: function(element, attr) {
return function(scope, element) {
if (attr.ngClick || attr.href === '' || attr.href === '#') {
element.on('click', function(e) {
e.preventDefault();
e.stopPropagation();
});
@shawncarr
shawncarr / keybase.md
Created May 28, 2014 15:23
keybase.md

Keybase proof

I hereby claim:

  • I am shawncarr on github.
  • I am shawncarr (https://keybase.io/shawncarr) on keybase.
  • I have a public key whose fingerprint is C65D 78AE D8FB EC1B 0CC0 BB8F 78C2 9ADC 40BC 771E

To claim this, I am signing this object:

@shawncarr
shawncarr / mandrill_validate_webhook
Last active May 25, 2017 12:07
Validating a Mandrill Webhook request for nodejs
var Crypto = require('crypto');
/**
* validates a mandrill webhook request
* @param url string the url that mandrill sent the request to
* @param key string the web hook key from https://mandrillapp.com/settings/webhooks
* @param params array the request's POST parameters i.e. req.params
* @param compareTo string the x-mandrill-signature header value
*/
var validate = function validate(url, key, params, compareTo) {