Skip to content

Instantly share code, notes, and snippets.

View wjlroe's full-sized avatar
📷

William Roe wjlroe

📷
View GitHub Profile
@wjlroe
wjlroe / test_have_attributes_and.rb
Created March 20, 2023 13:59
Show RSpec's unhelpful error output when combining matchers
require 'rspec'
Person = Struct.new(:name, :age)
RSpec.describe do
subject { Person.new("Bob", 32) }
it { is_expected.to have_attributes(name: "Bob", age: 33) }
# ^ This failure prints the attributes diff as follows:
const std = @import("std");
pub fn main() !void {
const allocator = std.heap.c_allocator;
const cwd = try std.process.getCwdAlloc(allocator);
defer allocator.free(cwd);
var paths = std.ArrayList([]const u8).init(allocator);
{
@wjlroe
wjlroe / playing_with_threads.c
Last active April 30, 2019 14:35
Playing with C11's stdatomics like atomic_compare_exchange and atomic_fetch_add for thread-safe global counters
#include <stdatomic.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#define NUM_THREADS 1000
pthread_t threads[NUM_THREADS];
@wjlroe
wjlroe / composable_sort.rb
Created April 25, 2018 16:10
Riddle me this: How can you compose sort_by in Ruby?
require 'minitest/autorun'
class ComposableSort
def initialize(stuff)
@stuff = stuff
end
def sorted
@stuff.sort_by { |item|
criteria.flat_map { |criterium| criterium.call(item) }
@wjlroe
wjlroe / keybase.md
Created January 3, 2018 17:58
keybase.md

Keybase proof

I hereby claim:

  • I am wjlroe on github.
  • I am willroe (https://keybase.io/willroe) on keybase.
  • I have a public key ASCQHZg1eVUWgaxWCRTjheQvY_6LhcuTDpJu8pdi-a3AnAo

To claim this, I am signing this object:

Process: itch [17240]
Path: /Applications/itch.app/Contents/MacOS/itch
Identifier: io.itch.mac
Version: 18.10.1 (18.10.1)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: itch [17240]
User ID: 501
Date/Time: 2016-10-23 21:56:40.220 +0100
@wjlroe
wjlroe / compile_error.txt
Created May 12, 2016 13:12
A Rust type error has me confounded
cargo build
Compiling piston_game v0.1.0 (file:///Users/will/Code/play/games/piston_game)
src/main.rs:17:19: 17:23 error: type mismatch resolving `<gfx_graphics::back_end::GfxGraphics<'_, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer> as graphics::graphics::Graphics>::Texture == I`:
expected struct `gfx_texture::Texture`,
found type parameter [E0271]
src/main.rs:17 scene.draw(c.transform, g);
^~~~
src/main.rs:17:19: 17:23 help: run `rustc --explain E0271` to see a detailed explanation
error: aborting due to previous error
@wjlroe
wjlroe / emacs
Created February 25, 2016 01:31
; -*- mode: emacs-lisp; -*-
; vim:ft=lisp
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes
(quote
@wjlroe
wjlroe / try.clj
Created November 16, 2015 10:03
Ruby's (2.3.0) dig and Clojure's get-in
(def people [{:name "Will"
:health 1}
{:name "Not Will"
:health -10}])
(get-in people [0 :name]) #=> "Will"
@wjlroe
wjlroe / react-native-stacktrace.txt
Created April 7, 2015 16:37
Programming can be fun again with ReactJS Native!
RCTJSLog> "Error:
stack:
getComponentClassForElement index.ios.bundle:5802
_processProps index.ios.bundle:16220
mountComponent index.ios.bundle:15949
ReactCompositeComponent_mountComponent index.ios.bundle:4849
mountComponent index.ios.bundle:4918
mountChildren index.ios.bundle:19591
initializeChildren index.ios.bundle:17904
mountComponent index.ios.bundle:18058