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
danielfoxp2 / flat_anything.exs
Last active Jul 18, 2018
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)
end
def flatten(element), do: [element]
end
@danielfoxp2
danielfoxp2 / flat_anything.js
Last active Jul 18, 2018
Example to flat an nested array of integers in Javascript, using Jasmine.js as spec suite
View flat_anything.js
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 Apr 12, 2018
Javascript Examples
View example-js.md

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 Jan 29, 2018
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 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()