Skip to content

Instantly share code, notes, and snippets.

View alecho's full-sized avatar
♟️

Andrew Lechowicz alecho

♟️
View GitHub Profile
@alecho
alecho / cose_key.ex
Created February 22, 2021 18:54
Store and retrieve a json object as a map with interlay and some binary values.
defmodule CoseKey do
use Ecto.Type
def type, do: :map
# Case the COSE Key x and y coordinates to base 64 encoded binaries.
def cast(%{-2 => x_coord, -3 => y_coord} = map) do
{:ok,
map
|> Map.put(-2, Base.encode64(x_coord))
|> Map.put(-3, Base.encode64(y_coord))}
defmodule NaturalNums do
import Enum
import List
def print(n) when not is_integer(n), do: {:error, "input must be an integer"}
def print(n) when n < 1, do: {:error, "integer must be positive"}
def print(n) do
1..n
|> map(&IO.puts/1)

Keybase proof

I hereby claim:

  • I am alecho on github.
  • I am alecho (https://keybase.io/alecho) on keybase.
  • I have a public key ASCL5IwoJppAv_1BT00PUc8useiNpwsoDvKuJCoLfdouVAo

To claim this, I am signing this object:

<?php
$gameName = 'War';
class Deck
{
public $suits = ['S', 'H', 'C', 'D'];
public $indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
protected $deck = [];
@alecho
alecho / 1bird2stones.php
Last active August 29, 2015 14:11
Solving the 1 Route 2 Controllers problem
<?php
// Given you want to perform one of two or more actions with a single url.
//
// in Config/routes.php
Router::connect('/:username/:action', array('controller' => 'users', 'action' => 'userOrShop'));
// Your UsersController.php might look something like this then.
class UsersController extends AppController {

ROOT/webroot/index.php line 37 → Cake\Routing\Dispatcher->dispatch(Cake\Network\Request, Cake\Network\Response)

$dispatcher->dispatch(
    Request::createFromGlobals(),
    new Response()
);