Skip to content

Instantly share code, notes, and snippets.

View patio11's full-sized avatar

Patrick McKenzie patio11

View GitHub Profile
@patio11
patio11 / gist:fe0abc1c18d09149e6c9
Created June 17, 2015 01:39
Quick sample of Golang and Ruby for string manipulation
#The task is replacing the port number in the URL string
//in golang
import "fmt"
import "strings"
func main() {
url := "http://localhost:8080/foo/bar"
fmt.Println(strings.Replace(url, "8080", "8181", -1))
}
@patio11
patio11 / gist:efc421680aa2fd49c761
Created May 29, 2015 17:29
A comparison of golang and Ruby regular expression use
#In Golang
package main
import (
"fmt"
"regexp"
)
func main() {
cd /tmp
curl -o git-2.2.1.tar.gz "https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.gz"
curl -o git-2.2.1.tar.sign "https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.sign"
# if you want to verify the tar signature
gpg --keyserver hkp://keys.gnupg.net --recv-keys 96AFE6CB
gunzip git-2.2.1.tar.gz
gpg --verify git-2.2.1.tar.sign
@patio11
patio11 / annual-prepay.md
Last active February 23, 2024 11:16
Appointment Reminder Annual Pre-pay copy (2014)

Notes

This is the latest version of an email which I send periodically, offering customers the opportunity to pre-pay for SaaS in return for a discount. The benefits to the SaaS company are better cash flow and reduced churn rate. The benefits to the customer are, well, in the email. This genre of email has produced hundreds of thousands of dollars in pre-pays for some companies I work with, and it rarely requires any more work than this example.

I've put $79 is as a placeholder for the cost of the user's plan. We calculate that for each account, naturally, along with the billing contact's name.

Subject: Save $79 on Appointment Reminder (and get a tax write-off) Formatting: 100% plain text. Gmail automatically links up the central link. From: Patrick McKenzie (Appointment Reminder) patrick@appointmentreminder.org

@patio11
patio11 / Rakefile.rb
Created October 29, 2014 06:42
A snippet from my Rakefile which uses Twilio.
#This Rake task fires every 5 minutes, checking for a particular symptom which signals a critical problem.
#If it finds it, it calls Patrick's cell phone.
#This could probably be done with PagerDuty or similar, but since I already had a Twilio account...
desc "Emails sysadmin if reminders are not going out"
task :check_for_emergency => :environment do
begin
had_emergency = Reminder.check_for_emergency! #Application code checks for a symptom of a critical problem.
if (had_emergency)
twimlet_url = "http://twimlets.com/message?Message%5B0%5D=Appointment%20reminder%20reminders%20in%20processing%20or%20scheduled.%20Appointment%20reminder%20reminders%20in%20processing%20or%20scheduled.%20Appointment%20reminder%20reminders%20in%20processing%20or%20scheduled."
require 'rubygems'
require 'httparty'
require 'fileutils'
require 'json'
USERNAME = ARGV[0] || "patio11"
MAX_TO_FETCH = ARGV[1]
puts "Username: #{USERNAME} max to fetch: #{MAX_TO_FETCH || "all"}"
@patio11
patio11 / SchoolClass.java
Created September 21, 2012 08:33
Java can be fun!
List<Student> studentsWhoHaveNotTakenAtLeastOneTest() {
List<Student> allStudents = this.getStudents().clone(); /* shallow copy to avoid mutation */
Iterator<Student> studentIt = allStudents.iterator();
/* select down to students missing at least one test */
List<Student> studentsMissingAtLeastOneTest = new ArrayList<Student>();
@patio11
patio11 / gist:1493179
Created December 18, 2011 12:04
Makes Twilio safe in non-production environments (for a particular Twilio library)
$MY_PHONE_NUMBERS = [] #Fill this out!
if RAILS_ENV != "production"
require 'twilio'
Twilio::Call.class_eval do
alias_method :old_make, :make
def make(caller, callee, url, options = {})
unless $MY_PHONE_NUMBERS.map {|num| num.gsub(/[^0-9+]/, "")}.include? callee.gsub(/[^0-9+]/, "")
raise "Trying to call a number which you do not own. (Safety measure for non-production environments.)"
@patio11
patio11 / count_rectangle_area.rb
Created August 30, 2011 17:37
Submission for E La Carte coding challenge by @patio11
#Hiya guys,
#I'm Patrick McKenzie (patio11 on HN) and I'm doing this just out of joy of programming puzzles.
#Not really looking for a job at the moment.
#
#I've taken some liberty with standard Ruby programming conventions to make this one file without
#dependencies, for the ease of you actually running it. It is the result of a very hack-in-progress
#sort of workflow. A git repo showing my work in stages might be more interesting but, well,
#hard to submit that into the form.
#This code is MIT licensed.
module ActionView
module Helpers
module AssetTagHelper
require 'jsminlib' #Google it. Paste into RAILS_ROOT/libs. Note: not MIT license (has a "This code should be used for good, not evil" rider -- ask your lawyers if they care).
def compress_css(source)
source.gsub!(/\s+/, " ") # collapse space
source.gsub!(/\/\*(.*?)\*\/ /, "") # remove comments