This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Sanitize do | |
# Unicode sets are defined at https://unicode-org.github.io/icu/userguide/strings/unicodeset.html | |
require Unicode.Set | |
# Defines a guard that is the intersection of alphanumerics and the latin script plus the | |
# space and underscore characters. Note that the set is resolved at compile time into an | |
# integer expression and is therefore acceptably performant at runtime. | |
defguard latin_alphanum(c) when Unicode.Set.match?(c, "[[:Alnum:]&[:script=Latin:][_\\ ]]") | |
def sanitize_string(<<"">>), do: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Acc do | |
@moduledoc """ | |
Recurses through a list of maps summing the amount. | |
If the max is exceeded it returns the list up to this point. | |
""" | |
@list [ | |
%{amount: 23, asset: "USD"}, | |
%{amount: 40, asset: "USD"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule NimbleSplit do | |
@moduledoc """ | |
Split text at a separator using [nimble_parsec](https://hex.pm/packages/nimble_parsec) | |
""" | |
import NimbleParsec | |
def test_string do | |
""" | |
some text, may also contain character "=", which is part of the separator | |
can be any number of lines long until the first separator line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts a list of atoms into a typespec | |
type = &Enum.reduce(&1, fn x, acc -> {:|, [], [x, acc]} end) | |
@grammatical_gender [ | |
:animate, | |
:inanimate, | |
:personal, | |
:common, | |
:feminine, | |
:masculine, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule StringIndex do | |
@newline 10 | |
@doc """ | |
Returns a map of line numbers to | |
a 2-tuple that is the index at which | |
the line starts in `string` and the | |
length of the line. | |
### Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Distance do | |
@moduledoc """ | |
Ensure that you have the following in your mix.exs | |
file: | |
def deps do | |
{:libgraph, "~> 0.13"} | |
end | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if Code.ensure_loaded?(Ecto.Type) do | |
defmodule Bitstring do | |
@moduledoc """ | |
Implements the Ecto.Type behaviour for the Postgres | |
type "bit varying" | |
""" | |
use Ecto.Type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> org.unicode.cldr.tool.GenerateProductionData | |
[-s, /Users/kip/Development/cldr_repo/common, -d, /Users/kip/Development/cldr_staging_data/common] | |
#-s sourceDirectory ≔ /Users/kip/Development/cldr_repo/common | |
#-d destinationDirectory ≔ /Users/kip/Development/cldr_staging_data/common | |
#-l logicalGroups ≝ true | |
#-t time ≝ true | |
#-S Sideways ≝ true | |
#-r root ≝ true | |
#-c constrainedRestoration ≝ true | |
#-i includeComprehensive ≝ true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Channel do | |
@input [{0, 190}, {1, 0}, {2, 0}, {3, 0}, {6, 220}, {9, 90}] | |
@doc """ | |
Map a list of {index, value} pairs | |
into a binary, filling in any gaps in | |
the index sequence with <<0>> as | |
the list is built. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Extract do | |
@moduledoc """ | |
Split into words only when the words have a "%" as a prefix | |
or a suffix | |
""" | |
# Empty string returns empty list | |
def words("") do | |
[] |
NewerOlder