Skip to content

Instantly share code, notes, and snippets.

@niku
niku / .README.md
Last active February 17, 2024 20:48
a sample repository of prop_check with test-unit

This repository is working sample of prop_check with test-unit.

$ ruby run_test.rb
Loaded suite 6dec8e397943cdc372b969fff26299e7
Started
E
================================================================================================================================================
Error: test_that_it_returns_an_integer_for_any_input(TestNaiveAverage):
 ZeroDivisionError:
@Qqwy
Qqwy / benchmarks.exs
Last active September 7, 2023 11:29
Elixir benchmark of different implementations of the 'subarray sum' problem
Mix.install([
:benchee,
{:okasaki, "~> 1.0"}, # <- used by Qqwy's Okasaki solution
:nx, # <- used by Qqwy's Nx solution
{:exla, "~> 0.5"}, # <- used by Qqwy's Nx solution
],
config: [nx: [default_backend: EXLA.Backend]] # <- used by Qqwy's Nx solution
)
inputs = %{
@Janiczek
Janiczek / Main.elm
Last active September 11, 2023 00:27
Free Monad + Interpreter in Elm
module Main exposing (..)
{-| Free monad + interpreter in Elm
-}
import Dict exposing (Dict)
{-| Dict String Int-like structure
@Qqwy
Qqwy / doctest-minitest.rb
Created March 9, 2022 23:38
Example of how to integrate doctests with Ruby Minitest
# Example of how to integrate doctests with Ruby Minitest
#
# Besides depending on `minitest`,
# this functionality depends on the `doctest-core` gem, c.f. https://www.rubydoc.info/gems/doctest-core/
class YourAppName::TestCase < MiniTest::Test
# To be used inside the body of a tests-class
# It will automatically create test cases for all
# 'documentation test' snippets that exist in the comments
@akoutmos
akoutmos / json
Created January 30, 2022 04:15
Pretty print JSON passed via STDIN using Elixir shell script
#! /usr/bin/env elixir
# Install required deps
Mix.install([:jason])
# The pretty printing module
defmodule JsonPrettyPrinter do
def get_stdin_data do
# Fetch data from STDIN and decode JSON
:stdio
*> Compile using GNU Cobol, e.g.: `cobc -x gcd_maxmin.cob`
IDENTIFICATION DIVISION.
PROGRAM-ID. gcd-maxmin.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUMS.
05 NUMS-ELEMS PIC 9(9)
OCCURS 0 TO 9999 TIMES DEPENDING ON NUMS-LEN.
77 NUMS-IDX PIC 9(9) COMP.
@aphyr
aphyr / minikanren.pl
Created October 12, 2020 22:10
Minikanren in Lisp in Prolog
:- use_module(library(pairs)).
:- use_module(library(reif)).
not_in_list(K, L) :-
if_((L = []),
true,
([X | More] = L,
dif(K, X),
not_in_list(K, More))).
@Qqwy
Qqwy / Example.ex
Created July 11, 2020 21:51
Elixir 'safe macro override' example implementation
defmodule Example do
use OverrideExample1
use OverrideExample2
@a 1
@b 2
end
# Prints at compile-time:
#
# yaay: {:a, [line: 4], [1]}
# wooh: {:a, [line: 4, context: OverrideExample2], [1]}
@Qqwy
Qqwy / addition.beam_disasm.ex
Last active July 8, 2020 14:34
An example of what BEAM code ends up being generated for a simple TypeCheck spec.
{:beam_file, Addition,
[
{:__info__, 1, 2},
{:"__type_check_spec_for_add/2__", 0, 18},
{:add, 2, 8},
{:baseline_add, 2, 16},
{:module_info, 0, 20},
{:module_info, 1, 22}
], [vsn: [337339698024769425821845159222917769638]],
[
@eksperimental
eksperimental / typespec_example.ex
Last active July 2, 2020 18:36
Broken types in Elixir Issue #10140
# Downloaded from: https://gist.github.com/eksperimental/55f1e207ab5878a668668546f57a3f90
#
# Lists all the types that have the problem reported in
# https://github.com/elixir-lang/elixir/issues/10140
# create an Elixir project, and save this file in lib/typespec_example.ex
# Start IEx with: iex -S mix
# then run: TypespecExample.types()
# and paste the output into the shell.
defmodule TypespecExample do