Skip to content

Instantly share code, notes, and snippets.

View patio11's full-sized avatar

Patrick McKenzie patio11

View GitHub Profile
@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."
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 / 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() {
@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 / example.go
Created June 22, 2015 08:21
An easy way to shoot yourself in the foot with go
// The wrong way to do things:
for {
switch {
case <- channelA:
doSomething()
case <- channelB:
doSomethingElse()
default:
// Do nothing.
@patio11
patio11 / untrusted-lvl13-solution.js
Last active August 29, 2015 14:25 — forked from anonymous/untrusted-lvl13-solution.js
Patio11's solution to level 13 in Untrusted: http://alex.nisnevich.com/untrusted/
/*
* robotMaze.js
*
* The blue key is inside a labyrinth, and extracting
* it will not be easy.
*
* It's a good thing that you're a AI expert, or
* we would have to leave empty-handed.
*/
hoge = "これは例である。"
puts hoge[1]
#This solves the maze using regular expressions, because I am too
#lazy to worry about arrays, darn it. It is inefficient as heck and designed
#purely to demonstrate perversion of sound CS principals.
#
# Code by Patrick McKenzie, 2010. I release this work unto the public domain.
class Maze
def initialize(maze_string)
@width = maze_string.split("\n")[0].length #width of maze in characters
@guts = maze_string.gsub("\n", "") #maze as a flat string -- no newlines
def open_flash_chart(height, width, data_url, div_name = nil)
options = {}
options[:height] = height
options[:width] = width
options[:swf_file_name] = "flash/open-flash-chart.swf"
options[:div_name] = div_name unless div_name.nil?
open_flash_chart_object_from_hash(data_url, options)
end
@patio11
patio11 / react-flummox-reduce-boilerplate.js
Created June 26, 2015 13:39
Got tired of all the boilerplate with hooking up Stores/Actions so...
// When I was working on our React/Flummox app I got to the point where, per the docs, I had ~100 lines of code
// which were substantially predictable boilerplate, so I used some JS metaprogramming to condense them by 80%.
// Flummox docs: http://acdlite.github.io/flummox
// I use underscore.js below for utility but you can also just do a for loop.
class AppFlux extends Flux {
constructor() {