Skip to content

Instantly share code, notes, and snippets.

View Lakret's full-sized avatar

Dmitry Slutsky ‮ ‮ Lakret

View GitHub Profile
@Lakret
Lakret / chess.ex
Created February 28, 2019 01:14
Level 1. Initial naming
defmodule Chess do
alias Chess.{Board, Player, Move, Interaction}
def play() do
play(Board.init_board(), Player.first_turn_player(), 0)
end
def play(board, player, turn) do
move = Interaction.read_move(player)
@Lakret
Lakret / board.ex
Created February 28, 2019 01:08
Level 1 - Board module draft
defmodule Chess.Board do
defstruct [:white_pieces, :black_pieces, :cells]
def init_board() do
pieces = all_pieces()
%__MODULE__{
white_pieces: Enum.map(pieces, fn p -> {:white, p} end),
black_pieces: Enum.map(pieces, fn p -> {:black, p} end),
cells: init_cells()
@Lakret
Lakret / chess.ex
Created February 28, 2019 00:41
Level 0. Single module
defmodule Chess do
def play() do
play(init_board(), first_turn_player(), 0)
end
def play(board, player, turn) do
move = read_move(player)
case execute_move(move, board, player) do
{:ok, new_board} ->
# Elixir script to calculate final grades
defmodule Test do
@max_grade 100
def grade(questions, right_answers)
when is_integer(questions) and is_integer(right_answers) do
balls_per_question =
if questions == 0 do
0
module type BusinessLogic = sig
type t
type u
val decode: string -> t
val compute: t -> u
val encode: u -> string
end
module BL1 : BusinessLogic = struct
@Lakret
Lakret / iterm2_hotkeyprofile
Created May 9, 2018 15:16
iTerm2 hotkey profile exported as json
{
"Working Directory" : "\/Users\/lakret",
"Prompt Before Closing 2" : 2,
"Selected Text Color" : {
"Green Component" : 0,
"Red Component" : 0,
"Blue Component" : 0
},
"Rows" : 25,
"Ansi 11 Color" : {
@Lakret
Lakret / limits.scala
Created May 3, 2018 19:51
Limiting concurrency with actors and futures
package example
import java.util.UUID
import scala.concurrent.{Future, Await}
import scala.concurrent.duration._
import scala.util.{Success, Failure}
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout

Let's specify an alias for vendor_id columns (vendor_alias). Note, that you'll need to resubmit the whole list of columns to update it:

curl -v -X PUT -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer eyJhb...IQ' \
  127.0.0.1:8082/datasetMetadata/trip_fare --data '{
  "current": {
    "columns": [
 {"type":"dimension","name":"vendor_id", "synonym": "vendor_alias"},
@Lakret
Lakret / puzzle.ex
Last active February 17, 2018 07:29
Pretty-Print sample Sudoku (lib/sudoku/puzzle/puzzle.ex)
defmodule Sudoku.Puzzle.Puzzle do
@enforce_keys [:rows]
defstruct [:rows]
alias Sudoku.Puzzle.Puzzle
def get_example_sudoku() do
%Puzzle{
rows: [
[nil, nil, 2, nil, nil, 1, nil, 4, nil],
// This code caused old Scala compiler to kindly ask you to send it to then Typesafe for analysis; it was not compiling
// With Scala 2.12 it compiles without any problems
trait Acceptable {}
trait Connector[NextPage <: Acceptable] {
def proceed(): NextPage
}
trait MinimalRequiredFiller {