Skip to content

Instantly share code, notes, and snippets.

View strukturedkaos's full-sized avatar

Don Pottinger strukturedkaos

View GitHub Profile
@strukturedkaos
strukturedkaos / mailchimp-popup-for-wordpress.md
Created April 8, 2016 15:11 — forked from nickcernis/mailchimp-popup-for-wordpress.md
MailChimp Popup Script that works with WordPress sites

MailChimp's default popup scripts can break on WordPress sites that use jQuery/jQuery UI unless you include their embed code as the final elements before the closing body tag.

Including them in this way isn't always possible or easy with WordPress.

The code below is an alternative implementation of the loader that forces MailChimp's popup scripts to appear below all other scripts upon page load.

To use it, modify the baseUrl, uuid, and lid attributes with the ones from the original popup script that MailChimp supplies.

@strukturedkaos
strukturedkaos / nginx.conf
Created October 27, 2015 18:04 — forked from jeffrafter/nginx.conf
Nginx proxy pass to localhost:3000 for development
worker_processes 1;
error_log /usr/local/var/log/nginx.error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
import Ember from 'ember';
// ==========================================================================
// Project: Ember EasyForm
// Copyright: Copyright 2013 DockYard, LLC. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
// Version: 1.0.0.beta.1
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR
# make database backup

Data Integrity

Programming is hard. We must valiantly fight complexity on a daily basis. Conditional statements quickly increase the complexity of a system. Every time we’re unsure about a value, we add a conditions to decide how to proceed. If only we could become more confident with the state of the system…

Hurrah! Data integrity can give us this confidence. By constraining our data, we can make some assumptions about the state of the system. Gone are the days of guarding potentially nil values. Out with orphaned and duplicate records! Data is the [life] of our software. Let’s take [life] by the reigns.

# encoding: binary
require 'active_model/validator'
class EmailValidator < ActiveModel::EachValidator
EmailAddress = begin
qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' +
'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
## This gist is intended to provide a code example for the
# 'Making Signed Requests' section of the 'Authentication Overview' document.
# (http://developer.netflix.com/docs/Security).
#
# We are going to make a catalog request. The hardest part of
# it is figuring out how to generate the oauth_signature.
require 'cgi'
require 'base64'
require 'openssl'
class PdfMerger
def merge(pdf_paths, destination)
first_pdf_path = pdf_paths.delete_at(0)
Prawn::Document.generate(destination, :template => first_pdf_path) do |pdf|
pdf_paths.each do |pdf_path|
pdf.go_to_page(pdf.page_count)
@strukturedkaos
strukturedkaos / select2_helper.rb
Created October 29, 2012 00:20 — forked from sbeam/gist:3849340
capybara helper for select2-ajax elements
# select2_ajax helper to make capybara work with ajax-enabled Select2 elements
# assumes 'placeholder' option is used in Select2 (if it is using ajax, it should be)
#
# usage:
#
# it "should have a select2 field for searching by team name" do
# @team = Factory :team
# select2_ajax @team.name, :from => "Select a Team", :minlength => 4
# click_button "Join"
# page.should have_content "You are now on '#{@team.name}'."
@strukturedkaos
strukturedkaos / gist:3801641
Created September 28, 2012 19:17 — forked from jkassemi/gist:3797001
Select2.js capybara
def select2_select(text, options)
page.find("#s2id_#{options[:from]} a").click
page.all("ul.select2-results li").each do |e|
if e.text == text
e.click
return
end
end
end