Skip to content

Instantly share code, notes, and snippets.

View viniciusalonso's full-sized avatar

Vinícius Alonso viniciusalonso

View GitHub Profile
@viniciusalonso
viniciusalonso / elixir_type_system_examples.ex
Last active April 27, 2024 18:04
Elixir Type System Examples
# Based on framework semantic subtyping: https://www.irif.fr/~gc/papers/icalp-ppdp05.pdf
# CDude implements this framework: https://www.cduce.org/
# Why?
## 1. aid documentation
## 2. ensure correct contracts
# Code examples
$ integer() -> integer()
<?php
$iterator = test_generator();
echo $iterator->current() . "\n";
$iterator->next();
echo $iterator->current() . "\n";
$iterator->next();
<?php
function test_generator()
{
yield "a";
yield "b";
}
<?php
foreach (range(1, 9, 2) as $number) {
echo "$number ";
}
foreach (xrange(1, 9, 2) as $number) {
echo "$number ";
}
<?php
function xrange($start, $limit, $step = 1) {
if ($start <= $limit) {
for ($i = $start; $i <= $limit; $i += $step) {
yield $i;
}
} else {
for ($i = $start; $i >= $limit; $i += $step) {
yield $i;
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Money;
class Product extends Model
{
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable => [
'name',
<?php
class Money
{
private $value;
private $currency;
public function __construct($value, $currency)
{
$this->value = $value;
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client sudo
EXPOSE 3000
RUN useradd -ms /bin/bash eichef
RUN usermod -aG sudo eichef
RUN echo "eichef ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER eichef
set wildmenu
set wildmode=full
set history=200
q: // open command line history screen