Skip to content

Instantly share code, notes, and snippets.

View alexandreservian's full-sized avatar

Alexandre Servian alexandreservian

View GitHub Profile
@SolidAlloy
SolidAlloy / BoxCastDrawer.cs
Created May 17, 2020 14:36
A class that allows to visualize Unity Physics2D.BoxCast() method.
using UnityEngine;
/// <summary>
/// A class that allows to visualize the Physics2D.BoxCast() method.
/// </summary>
/// <remarks>
/// Use Draw() to visualize an already cast box,
/// and BoxCastAndDraw() to cast a box AND visualize it at the same time.
/// </remarks>
@bradtraversy
bradtraversy / js_linked_list.js
Last active May 21, 2024 17:52
JS Linked List Class
// Construct Single Node
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
}
}
// Create/Get/Remove Nodes From Linked List
class LinkedList {
@andrewhao
andrewhao / game.ex
Last active August 7, 2023 21:37
Dynamic Supervisors in Elixir
defmodule Game do
use GenServer
def init(game_id) do
{:ok, %{game_id: game_id}}
end
def start_link(game_id) do
GenServer.start_link(__MODULE__, game_id, name: {:global, "game:#{game_id}"})
end
@mike-north
mike-north / user.ex
Created May 28, 2016 04:58
ELIXIR - Validating a password for length and complexity in Ecto
defmodule MyApp.User do
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
|> validate_format(:email, ~r/@/)
|> validate_length(:password, min: 8)
|> validate_format(:password, ~r/[0-9]+/, message: "Password must contain a number") # has a number
|> validate_format(:password, ~r/[A-Z]+/, message: "Password must contain an upper-case letter") # has an upper case letter
|> validate_format(:password, ~r/[a-z]+/, message: "Password must contain a lower-case letter") # has a lower case letter
|> validate_format(:password, ~r/[#\!\?&@\$%^&*\(\)]+/, message: "Password must contain a symbol") # Has a symbol