Skip to content

Instantly share code, notes, and snippets.

View anicholson's full-sized avatar

Andy Nicholson anicholson

View GitHub Profile
@anicholson
anicholson / example.rb
Created August 15, 2020 07:44
Dry::Monads::Do::All is broken for singleton classes
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'dry-monads'
gem 'rspec'
end
module ConvertToUpperCase
@anicholson
anicholson / actual.txt
Created April 19, 2020 22:45
Crystal macro generates incorrect syntax?
There was a problem expanding macro 'sequential'
Code in src/minimal_example.cr:8:1
8 | sequential do
^
Called macro defined in src/minimal_example.cr:1:1
1 | macro sequential(&block)
class ResultError < Exception; end
abstract class Result(V, E)
abstract def value : V
abstract def error : E
abstract def ok? : Boolean
abstract def error? : Boolean
abstract def andThen(&block : self -> self) : self
Error in /Users/andy/projects/consider_crystal/macro.cr:6: expanding macro
JSON.mapping(
^~~~~~~
in /Users/andy/projects/consider_crystal/macro.cr:6: expanding macro
JSON.mapping(
^
Error in /Users/andy/projects/consider_crystal/macro.cr:6: expanding macro
JSON.mapping(
^~~~~~~
in /Users/andy/projects/consider_crystal/macro.cr:6: expanding macro
JSON.mapping(
^
require "benchmark"
Benchmark.bm do |x|
(1..10).each do |i|
x.report "ENV[PATH]: in a block" do
# i.times { C.getenv("PATH") }
i.times { 1 * i }
end
end
end
0x87463408915D544Ca4a4dFA90A68e7735024C124
user system total real
Run 0 14.010000 0.470000 14.480000 ( 2.773481)
Run 1 2.700000 0.210000 2.910000 ( 0.635449)
Run 2 1.170000 0.010000 1.180000 ( 0.300033)
Run 3 1.930000 0.080000 2.010000 ( 0.372750)
Run 4 1.430000 0.020000 1.450000 ( 0.325396)
Run 5 1.460000 0.020000 1.480000 ( 0.346627)
Run 6 1.350000 0.060000 1.410000 ( 0.366876)
Run 7 1.230000 0.020000 1.250000 ( 0.356951)
Run 8 1.020000 0.010000 1.030000 ( 0.452953)
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/setup'
require_relative '../config/environment'
require 'rack'
# Take the whole script down if anything goes remotely wrong
Thread.abort_on_exception = true
@anicholson
anicholson / Dockerfile
Last active October 23, 2016 22:24
Crystal Ubuntu package does not install all required dependencies
FROM ubuntu
MAINTAINER Andy Nicholson <andrew@anicholson.net>
RUN apt-get update && \
apt-get install -y apt-transport-https && \
apt-key adv --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54 && \
echo "deb https://dist.crystal-lang.org/apt crystal main" > /etc/apt/sources.list.d/crystal.list && \
apt-get update && \
apt-get install -y crystal