Skip to content

Instantly share code, notes, and snippets.

View eksperimental's full-sized avatar

Eksperimental eksperimental

  • Available for hire
  • Remote
View GitHub Profile
import Kernel, except: [length: 1]
defmodule String do
@moduledoc ~S"""
A String in Elixir is a UTF-8 encoded binary.
## Codepoints and graphemes
The functions in this module act according to the Unicode
Standard, version 6.3.0. As per the standard, a codepoint is
@eksperimental
eksperimental / string.ex
Created October 31, 2014 14:53
this one will give no warning
import Kernel, except: [length: 1]
defmodule String do
@moduledoc ~S"""
A String in Elixir is a UTF-8 encoded binary.
## Codepoints and graphemes
The functions in this module act according to the Unicode
Standard, version 6.3.0. As per the standard, a codepoint is
@eksperimental
eksperimental / getting_started
Last active August 29, 2015 14:14
Getting Started Guide: Structure
- title: Getting Started
dir: /getting_started/
pages:
- title: Introduction
slug: introduction
- title: Basic types
slug: basic_types
- title: Basic operators
@eksperimental
eksperimental / Contributing improvements or bug fixes
Last active August 29, 2015 14:15
elixir-lang instructions
1) **Fork and Clone this Repository**
[Fork this repository](https://github.com/elixir-lang/elixir-lang.github.com/fork), and Create a local clone of your fork. You may want to read the [Instructions on how to do that](https://help.github.com/articles/fork-a-repo/).
2) **Install [Ruby](https://www.ruby-lang.org/)**
To setup a development enviroment locally, you need to have Ruby installed. If you are running a Mac, it's probably installed. Run in your shell `ruby --version`. Your Ruby version should begin with `1.9.3` or `2.0.0`. You can follow [this guide](https://www.ruby-lang.org/en/documentation/installation/) if you need to install it.
3) **Install [Bundler](http://bundler.io/)**
```bash
gem install bundler
```
@eksperimental
eksperimental / gist:88596033712d90520a97
Last active August 29, 2015 14:17
Variable assign after regex run
get_number = fn (text) ->
case Regex.run(~r/\w (\d+)/, text) do
[_, number] -> number
_ -> nil
end
end
"10" = _number = get_number.("a 10")
nil = _number = get_number.("a NO")
defmacro is_regex(term) do
quote do
is_tuple(unquote(Macro.escape term)) and (
(elem(unquote(Macro.escape term), 0) in [:sigil_r, :sigil_R, :r, :R]) or
(elem( elem(unquote(Macro.escape term), 2), 0 ) == {:__struct__, Regex})
)
end
end
@eksperimental
eksperimental / check_not_linked_exdoc.sh
Last active September 4, 2015 03:02
Check for references to exiting modules in the documentation, that is actually not being liked by ExDoc, in the documentation for the Elixir project
#!/bin/bash
# ./check_not_linked_exdoc.sh – http://git.io/check_not_linked_exdoc.sh
#
# Description:
# Check for references to exiting modules in the documentation, that is actually not being liked
# by ExDoc.
#
# Instructions
# Run from the root folder in the elixir project – https://github.com/elixir-lang/elixir/
@eksperimental
eksperimental / make-test-file
Last active November 10, 2015 17:05
A script to ease development of the Elixir programming code base. Allowing the developer to run selected tests.
#!/bin/sh
# make-test-file
# https://git.io/make-test-file
#
# DESCRIPTION:
# make-test-file is a script to ease development of the Elixir programming code
# base. Allowing the developer to run selected tests.
#
# INTRODUCTION:
defmodule EnumRandomOriginal do
def random(enumerable) do
case Enum.take_random(enumerable, 1) do
[] -> raise Enum.EmptyError
[e] -> e
end
end
end
defmodule EnumRandomNew do
@eksperimental
eksperimental / 1_enum_fetch_benchmarking_report.md
Last active July 6, 2016 06:15
Enum.fetch/2 optimization for maps, negative indexes, out of bound indexes, empty enumerables, and enumerables with only one element.

Optimize Enum.fetch/2 for maps, negative indexes, out of bound indexes, empty enumerables, and enumerables with only one element.

This function has been highly-optimized, through thorough benchmarking.

There were serious issues when dealing with big lists and maps when an out of bound or a negative index was given. Ex. fetching an out-of-bound index in a 1,000-element map, was reduced to 0.18% of the original item. Or same case with a 1,000-element list time was reduced to a 10,5%.

  • Enumerables are no longer reversed when dealing with negative indexes.