Skip to content

Instantly share code, notes, and snippets.

View CollectionValidator.cs
using System;
using System.Collections;
namespace Flatten
public class CollectionValidator<T>
public static bool IsNotValidThis(T integerCollection)
return IsNotAnIEnumerable(integerCollection) || IsAString(integerCollection);
danielfoxp2 / flat_anything.exs
Last active July 18, 2018 22:30
Example to flat an nested arrays in Elixir
View flat_anything.exs
defmodule FlatAnything do
def flatten([]), do: []
def flatten(this_collection) when is_list(this_collection) do
[head | tail] = this_collection
flatten(head) ++ flatten(tail)
def flatten(element), do: [element]
danielfoxp2 / flat_anything.js
Last active July 18, 2018 22:24
Example to flat an nested array of integers in Javascript, using Jasmine.js as spec suite
View flat_anything.js
class FlatAnything {
if(itIsNotAnArrayAt(collection)) throw new Error('Only collections are allowed');
if(isAnEmpty(collection)) return [];
const headOfCollection = headOf(collection);
const tailOfCollection = tailOf(collection);
if(itIsNotAnArrayAt(headOfCollection)) return theConcatenationOf([headOfCollection], this.flattenThis(tailOfCollection));
danielfoxp2 /
Last active April 12, 2018 22:32
Javascript Examples

First example

Improving Air Datepicker behavior

Improviments done:

  • When manually inputing a date, the datepicker should follow to show the same date;
  • When insert an invalid date, the datepicker is cleaned;
danielfoxp2 / especializedalternatejsfileinphoenix.vim
Created January 29, 2018 00:29
A especialized piece to alternate spec and production js code inside a phoenix 1.2 project
View especializedalternatejsfileinphoenix.vim
" It has to be put inside the
" in order to work. It is not placed in the plugin because it is very opinionated about where
" the js files will be. So while I can decide if it is good or not to put it in there, I will
" keep it here.
" This let is_javascript_specs = match(current_file, '\.js$') != -1 and
" this
" elseif is_javascript_specs
" let new_file = BuildJavascriptUnitPath()
" is needed in the function AlternateForCurrentFile() then this will do the magic:
function! BuildJavascriptUnitPath()