Skip to content

Instantly share code, notes, and snippets.

@packrat386
packrat386 / ips.rb
Created December 14, 2018 02:54
Some people manage to do everything the hard way
require 'benchmark/ips'
SIZE = 10
Benchmark.ips do |x|
x.report('insane') do
[0].cycle.take(SIZE)
end
x.report('sane') do
@packrat386
packrat386 / customer_notifier_v1.rb
Created December 5, 2018 00:48
What is green may not always be grue
class CustomerNotifier
def initialize(mail_server, templates)
@mail_server = mail_server
@templates = templates
end
def confirm_order(customer, data)
@mail_server.send_mail(customer.email_address, @templates[:confirm_order].render(data))
end
From 46cff894e9de7284395b4df996914221f96fc1ac Mon Sep 17 00:00:00 2001
From: Aidan Coyle <packrat386@gmail.com>
Date: Tue, 20 Nov 2018 21:40:36 -0600
Subject: [PATCH] Bats first attempt
---
src/pv/display.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/pv/display.c b/src/pv/display.c
@packrat386
packrat386 / example.txt
Created October 21, 2018 20:04
Example of tldr -l implementation
[fg-386] tldr-cpp-client > ./tldr -l
Pages for osx
airport
apachectl
archey
as
base64
brew-cask
brew-mas
brew
def myfunc(prog = "")
mystr = "hi there"
eval(prog)
mystr.scream
end
puts 'first'
begin
myfunc
rescue => e
package main
import "fmt"
var true = false
func main() {
fmt.Println(true)
}
@packrat386
packrat386 / errors_test.go
Created June 25, 2018 13:53
fmt.Errorf might not be as bad as I thought
package main
import (
"errors"
"fmt"
"testing"
)
var err error
// pacakge iface is a comparison of two different interfaces for a client
// to a simple REST API. Assume I had access to both `GET /resource`, which
// returns a list of all resources (which may be empty), and `GET /resource/:id`,
// which returns the resource with the given ID, OR a 404 if no resource
// has that ID. Additionally, since these are http requests they could also
// fail with some other non-200 status code for a variety of reasons, and
// we want to be able to distinguish between a request that failed and a
// resource not existing.
//
// The issue I find is that using pointers is nicer in the case of getting a
package main
import (
"fmt"
"time"
)
var access func() int
func init() {
[fg-386] escape > go test -bench=. -benchmem 2> /dev/null
goos: darwin
goarch: amd64
BenchmarkA-8 2000000000 0.28 ns/op 0 B/op 0 allocs/op
BenchmarkAPrint-8 2000000 682 ns/op 8 B/op 1 allocs/op
BenchmarkEmptyPrint-8 2000000 611 ns/op 0 B/op 0 allocs/op
BenchmarkB-8 2000000000 0.27 ns/op 0 B/op 0 allocs/op
PASS
ok _/Users/acoyle/side/escape 5.117s