Skip to content

Instantly share code, notes, and snippets.

View ajm188's full-sized avatar

Andrew Mason ajm188

View GitHub Profile
@ajm188
ajm188 / .travis.yml
Created April 19, 2015 01:38
Travis CI: Postgres relation not found
language: ruby
rvm:
- 2.2.0
before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test;' -U postgres
@ajm188
ajm188 / courses_controller.rb
Created July 7, 2015 03:01
example of controller code that has been bloated by needing to check many query parameters
class CoursesController < ApplicationController
def index
@semesters = Semester.all
@courses = Course.all
if params[:search].present?
@courses = @courses.search(params[:search])
end
if params[:semester].present?
@courses =
@courses.joins(:course_instances)
@ajm188
ajm188 / better_hash.rb
Created October 24, 2015 13:42
Don't let your hashes return nil, raise errors instead!
class BetterHash < Hash
def initialize(*args)
super { |_, _| raise KeyError }
end
end
@ajm188
ajm188 / hello.rb.m
Created February 2, 2016 21:21
hello world in matlab and ruby (also incidentally prints 3)
a = 3 % 1; def disp(text); puts text; end; puts 3
disp('Hello World!');
@ajm188
ajm188 / blow_the_stack.rb
Created September 5, 2016 02:18
Blow up your ruby stack in a single line!
Hash.new { |h, k| h[k] ||= 0 }[:kaboom!]
def compose(*functions):
assert functions
def f(*args, **kwargs):
return reduce(functions[1:], __call__, functions[0](*args, **kwargs))
return f
@ajm188
ajm188 / bionic
Created July 5, 2020 20:45
post-install broken in mysql-server-5.7 ubuntu:bionic
❯ docker run -it --rm ubuntu:bionic /bin/bash -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends mysql-server-5.7"
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:3 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [9282 B]
Get:4 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [866 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
Get:8 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [87.8 kB]
@ajm188
ajm188 / gh-ost.itest
Created July 6, 2020 23:12
gh-ost itest output
❯ docker run --rm -it itest
Creating replication sandbox
Installing and starting master
. sandbox server started
Installing and starting slave1
. sandbox server started
Installing and starting slave2
. sandbox server started
$HOME/sandboxes/gh-ost-test/initialize_slaves
initializing slave 1
@ajm188
ajm188 / vtgate.pb.go.diff
Created August 10, 2020 03:05
proto diff
diff --git a/go/vt/proto/vtgate/vtgate.pb.go b/go/vt/proto/vtgate/vtgate.pb.go
index 420d6e33c..8e4c6ab7a 100644
--- a/go/vt/proto/vtgate/vtgate.pb.go
+++ b/go/vt/proto/vtgate/vtgate.pb.go
@@ -1,29 +1,51 @@
+//
+//Copyright 2019 The Vitess Authors.
+//
+//Licensed under the Apache License, Version 2.0 (the "License");
+//you may not use this file except in compliance with the License.
@ajm188
ajm188 / padding_bench_test.go
Last active November 22, 2020 18:54
Zero padding benchmarks
package strings
import (
"bytes"
"fmt"
"strings"
"testing"
)
var (