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
<snippet> | |
<content><![CDATA[ | |
Hello, ${1:this} is a ${2:snippet}. | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<!-- <tabTrigger>hello</tabTrigger> --> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<!-- <scope>source.python</scope> --> | |
</snippet> |
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
# -*- coding: utf-8 -*- | |
from selenium import selenium | |
import unittest, time, re | |
server = "http://example.com/" | |
def suite(): | |
suite = unittest.TestSuite() | |
suite.addTest(AssertRouteSelection(u"Montréal-Québec",u"Route Status: MONTRÉAL-QUÉBEC")) | |
suite.addTest(AssertRouteSelection(u"Montréal-Ottawa",u"Route Status: MONTRÉAL-OTTAWA")) |
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 RunLength do | |
def encode(data) do | |
String.graphemes(data) |> do_encode | |
end | |
defp do_encode([]) do | |
"" | |
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
defmodule WordCount do | |
def count(phrase) do | |
String.split(phrase) | |
|> Enum.reduce(%{}, fn(word, map) -> | |
Map.update(map, word, 1, &(&1 + 1)) | |
end) | |
|> Enum.to_list() | |
end | |
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
defmodule HelloWorld do | |
def greet("") do | |
{:ok, "Hello World"} | |
end | |
def greet([]) do | |
{:ok, "Hello World"} | |
end | |
def greet(names) when is_list(names) 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 ListOps do | |
def length(list) do | |
reduce(list,0,fn(item,acc) -> acc + 1 end) | |
end | |
def reduce([], acc, _) do | |
acc | |
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
defmodule ListTruther do | |
def test([],_) do | |
false | |
end | |
def test(list, mode) do | |
case mode do | |
:and -> Enum.reduce_while(list, false, fn(item, _) -> | |
if item, do: {:cont, true}, else: {:halt, false} |
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 Sublist do | |
def compare(a,b) when a === b, do: :equal | |
def compare(a,b) do | |
cond do | |
a === b -> :equal | |
sublist?(a,b) -> :sublist | |
sublist?(b,a) -> :superlist | |
true -> :unequal | |
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
defmodule Anagram do | |
def match(word,words) do | |
Enum.filter(words, fn(w) -> | |
source = String.downcase(word) | |
compare = String.downcase(w) | |
if source === compare do | |
false | |
else | |
a = to_char_list(source) |> Enum.sort | |
b = to_char_list(compare) |> Enum.sort |
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 BracketPush do | |
def check_brackets(""), do: true | |
def check_brackets(s) do | |
do_check_brackets([],String.codepoints(s)) | |
end | |
defp do_check_brackets(stack,[]) do | |
length(stack) === 0 | |
end |
OlderNewer