Skip to content

Instantly share code, notes, and snippets.

class AutoresponderReaction < ActiveRecord::Base
### Modules ###
include Jobs::DatabaseQueue
### Constants ###
### Relations ###
@alexmchale
alexmchale / genpass.sh
Created September 16, 2014 16:25
TextExpander script to generate a random password, paste it into your current input, and write it to your pasteboard
#!/bin/bash
pw=`curl -k -2 https://mail.drh.net/cgi-bin/get_password.cgi 2> /dev/null | head -3 | tail -1 | cut -d ' ' -f 3`
echo -n "$pw" | pbcopy
echo -n "$pw"
@alexmchale
alexmchale / jobs.rake
Created September 1, 2014 01:26
A rake task used to connect a local copy of an app to a remote Postgres database over SSH
require 'net/ssh/gateway'
namespace :jobs do
task :create_port_tunnel do
# Make sure the use rhas specified where we're connecting.
(username, hostname) = ENV["REMOTE_HOST"].to_s.split("@", 2)
if [ username, hostname ].any? &:blank?
puts "Please specify env var REMOTE_HOST containing a hostname like 'bob@example.com'."
exit 1
@alexmchale
alexmchale / gist:4ead92de00ff03e90cd6
Last active July 12, 2023 12:15
JavaScript Bookmarklet to Watch YouTube Videos in Full Window
javascript: (function () {
var hasYouTube = function (url) {
return url.indexOf("youtube.com/") >= 0;
};
var redirect = function (url) {
if ( url.indexOf("youtube.com/watch?") >= 0 ) {
window.location.href = url.replace(/\/watch\?/, "/watch_popup?");
return true;
} else if ( url.indexOf("youtube.com/embed/") >= 0 ) {
class JustEchoSomethingFun_20140805211326 < GreenArrow::Migration
# The `before_up` method runs the specified command or Ruby block. If a shell
# command returns non-success or if the Ruby command returns false then the
# migration chain will not be run. The `before_up` logic is executed before
# an UP migration is executed, but not before a DOWN.
### before_up "ls /"
### before_up "echo 'Hello, world!'"
### before_up { [ 1, 2, 3 ].include? 2 }
class MigrateOldCreditTrackingData < ActiveRecord::Migration
def up
if ActiveRecord::Base.connection.tables.include? "credit_usage_daily_log"
execute <<-SQL
INSERT INTO s_credit_daily_usages ( date, organization_id, name, num_subscribers, num_users, credits )
SELECT date::date, id, MAX(name), MAX(num_subscribers), MAX(num_users), MAX(credits)
FROM credit_usage_daily_log
WHERE date::date NOT IN (SELECT date FROM s_credit_daily_usages)
GROUP BY id, date::date;
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/module/aliasing'
require 'monitor'
# This is my variation on Tom Meier's monkey-patch to fix a problem in Rails
# I've run into with RSpec. I've tweaked it a bit to use `alias_method_chain`
# instead of just overloading the original method and copying its code.
#
# See the original Gist here:
#
# The following tables will be initialized when the testing framework starts up.
input:
ss_banned_emails:
-
banid: 1
emailaddress: "ace@drh.net"
list: "g"
bandate: 1405079491
-
banid:
@alexmchale
alexmchale / s4_create_campaign.php
Last active August 29, 2015 14:02
Example for creating a GreenArrow Studio 4 Campaign with the API in PHP
<?php
define('GAS_BASE_URL', 'http://localhost:3000/api');
define('GAS_API_KEY', '1:2768cac8a813c4419f167749e58219bfe4bca2d7');
function greenarrow_studio_create_campaign($params) {
// Gather parameters needed to communicate with GA Studio.
$listID = $params['mailing_list_id'];
$url = GAS_BASE_URL.'/v2/mailing_lists/'.$listID.'/campaigns';
$ch = curl_init($url);
@alexmchale
alexmchale / 20140417202724_replace_newlines_in_links.rb
Last active August 29, 2015 14:01
A hot-fix for servers that fail on migration 20140417202724_replace_newlines_in_links.rb