Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections;
namespace Flatten
{
public class CollectionValidator<T>
{
public static bool IsNotValidThis(T integerCollection)
{
return IsNotAnIEnumerable(integerCollection) || IsAString(integerCollection);
@danielfoxp2
danielfoxp2 / flat_anything.exs
Last active July 18, 2018 22:30
Example to flat an nested arrays in Elixir
defmodule FlatAnything do
def flatten([]), do: []
def flatten(this_collection) when is_list(this_collection) do
[head | tail] = this_collection
flatten(head) ++ flatten(tail)
end
def flatten(element), do: [element]
end
@danielfoxp2
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
class FlatAnything {
flattenThis(collection){
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
danielfoxp2 / example-js.md
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
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
" It has to be put inside the https://github.com/danielfoxp2/vim-openalternatefile-phx1.2
" 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()