Skip to content

Instantly share code, notes, and snippets.

@packrat386
packrat386 / bad_jit.out
Last active October 7, 2015 16:15
Reproduction of good and bad jit
FG-386:rubinius acoyle$ ruby -Xjit.inline.debug repro.rb
JIT: compiling Array#include? (1440519539.55320)
| inline slot read: offset: 40
| inline slot read: offset: 24
| inlining: Fixnum#+ into include?. primitive fixnum_add (Fixnum)
| inline slot read: offset: 32
| inlining: Fixnum#< into include?. primitive fixnum_compare_operation (Fixnum)
| inlining: Rubinius::Tuple#[] into include?. primitive tuple_at (Rubinius::Tuple)
| inlining: Kernel#equal? into include?. primitive object_equal (Symbol)
| inlining: String#== into include?. generic primitive: jit_stub_string_equal (String)
@packrat386
packrat386 / filter.pl
Last active September 23, 2015 04:39
Filter everything but digits
$str = "1-800-123-4567";
print "$str\n";
$str =~ s/[^0-9]//g;
print "$str\n";
package benchtest
import (
"encoding/json"
"fmt"
"strconv"
"testing"
"time"
)
@packrat386
packrat386 / lolwut_test.go
Created November 15, 2016 20:02
Assert panics comparing number to nil
package lolwut
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEqual(t *testing.T) {
assert.Equal(t, 1, nil)
@packrat386
packrat386 / p1_fsm.rb
Last active June 4, 2017 02:20
Doing day 7 in a single pass
STATE_MAP = {
outside_intial: 'Outside a bracket. Nothing Interesting',
outside_a: 'Outside a bracket. We found a character <a>',
outside_ab: 'Outside a bracket. After finding <a>, we found a <b> which was not the same as <a>',
outside_abb: 'Outside a bracket. After finding a sequence <a><b>, we found <b>',
solved_initial: 'Outside a bracket. We found a sequence <a><b><b><a>',
inside_intial: 'Inside a bracket. Nothing Interesting',
inside_a: 'Inside a bracket. We found a character <a>',
inside_ab: 'Inside a bracket. After finding <a>, we found a <b> which was not the same as <a>',
inside_abb: 'Inside a bracket. After finding a sequence <a><b>, we found <b>',
package main
import (
"fmt"
"log"
"net/http"
"strings"
"time"
"github.com/dgrijalva/jwt-go"
[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
package main
import (
"fmt"
"time"
)
var access func() int
func init() {
// 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
@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