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
-module(count_chars). | |
-export([count_chars/1, count_characters/1]). | |
count_characters(Str) -> | |
count_characters(Str, #{}). | |
%% maps module functions cannot be used as guards (release 17) | |
%% or you'll get "illegal guard expression" error | |
count_characters([H|T], X) -> |
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
# original code | |
gcd=->(_){_.sort_by(&:-@).inject{|p,q|q.nonzero?&&gcd[[q,p-q]]||--p}} | |
$/=' ';gets;puts gcd[[$_,gets].map &(method :Integer)] | |
# original code modified (puts&gets removed, made example explicit, etc.) | |
# === 1st line === | |
gcd=->(_){_.sort_by(&:-@).inject{|p,q|q.nonzero?&&gcd[[q,p-q]]||--p}} | |
# -@ unary minus—returns the receiver’s value, negated. | |
# Numeric.instance_methods(false).grep /@/ #=> [:+@, :-@] |
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
% The cause of the second output is (where the | |
% receive block is commented out) is that because | |
% the process does not expect any messages and it | |
% ends naturally. | |
% | |
% On the other hand, the version with receive | |
% expects messages (spits out any message that | |
% arrives) and it keeps on running until it is | |
% told to stop. |
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
################################################### | |
### Solution to `invalid quoted expression` | |
### short version: use `Macro.escape/1` | |
### | |
### https://elixirforum.com/t/cant-seem-to-unquote-a-map/4009 | |
################################################### | |
######################################## | |
### (1) do smth with map, tuple etc. | |
### but only in the body of the |
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 A do | |
def vmi, do: IO.puts(27) | |
def balabab, do: IO.puts(7) | |
def lofa do | |
f = [&vmi/0, &balabab/0] | |
Enum.each(f, &(&1.())) | |
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
# Partial EEx template application | |
# | |
# As OvermindDL1 and Jose' pointed out, this doesn't cover for | |
# templates like "<%= a + b %>" and why not just simply collect | |
# the assigns, and apply them when we have them all. | |
# https://groups.google.com/forum/#!topic/elixir-lang-core/pYSfP3x7vwc | |
# I still think that there would be a use case for partial application | |
# and it was a nice mind exercise:) |
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
rsync -avz --delete --progress \ | |
-e "ssh -i ~/.ssh/my_private_key" \ # or just `-e ssh` (see below) | |
/SOURCE_PATH username@1.2.3.4:/DESTINATION_PATH | |
# Breaking down: | |
# -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) | |
# | |
# -r, --recursive recurse into directories | |
# -l, --links copy symlinks as symlinks |
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
//////////////////////////////////////////// | |
// NEO4J GRAPH SETUP | |
// | |
// http://console.neo4j.org/?id=jkwe2h | |
//////////////////////////////////////////// | |
CREATE | |
(kilgore:Person {name: 'Kilgore'}), | |
(logan:Person {name: 'Logan'}), | |
(u1:Unit {name: 'Apt 7A'}), |
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
// based on the book, this is somewhat better but without MERGEs, | |
// you'll end up with one extra relationship per new timeline. | |
create | |
(kilgore:Person {name: "Kilgore"}), | |
(e1:Event {event: "Become CORE student"}), | |
(e2:Event {event: "Called SFTB"}), | |
(e3:Event {event: "Donate $2"}), | |
(timeline:Timeline {name: "Kilgore's timeline"}), | |
(sept:Month {name: "September"}),(oct:Month {name: "October"}), | |
(d9:Day {name: '9th'}),(d3:Day {name: '3rd'}), |
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
create | |
(:Timeline)-[:YEAR]->(y:Year {value: 2017})-[:MONTH]->(m9:Month {value: "9"})-[:DAY]->(:Day {value: "12"})-[:EVENT {description: "Called"}]->(sftb:Org {name: "SFTB"}), | |
(m9)-[:DAY]->(:Day {value: "19"})-[:EVENT {description: "Intake"}]->(:Education {name: "vmi"})-[:ORG]->(sftb), | |
(y)-[:MONTH]->(m10:Month {value: "10"})-[:DAY]->(:Day {value: "12"})-[:EVENT {description: "Started learning stuff"}]->(sftb), | |
(m10)-[:DAY]->(:Day {value: "19"})-[:EVENT {description: "donated $2"}]->(sftb); | |
match (:Timeline)-[]->(year),p=(year)-[*2]->()-[r:EVENT]->() | |
with p as event_paths, r as events | |
return nodes(event_paths), events; |
OlderNewer