Skip to content

Instantly share code, notes, and snippets.

@7-fl
7-fl / makefile
Last active March 17, 2017 17:26
Simple erlang makefile
#------------!WARNING!------------------
#makefiles require an actual tab character for the indenting.
#I use macvim as my text editor, and I have it configured
#to convert tabs to spaces for all file types. To make sure
#that doesn't happen to a makefile, I added the following to
# ~/.vimrc:
#
# au FileType make setlocal noexpandtab tabstop=4 shiftwidth=4 softtabstop=0
#
#---------------------------------------
@7-fl
7-fl / review.md
Last active March 6, 2017 19:40
Week 2 Review for: David Paniz
  1. It looks like you aren't handling some of the punctuation correctly. When I try your solution out on my test text, I see some punctuation still on the end of some of the words in the index (see the example below).

  2. It also looks like you are skipping some words.

When I try your solution on a file with a single line:

Hi, there!  What's up?  See you later.

I get the following index:

-module(w2).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
mysort_test() ->
[] = mysort([]),
[1] = mysort([1]),
[-1,0,1] = mysort([0,1,-1]),
[1,2,3,4] = mysort([4,3,1,2]),
[1,1,3,3,3,3] = mysort([3,3,1,3,1,3]),
-module(index).
-export([get_file_contents/1,show_file_contents/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
% Get the contents of a text file into a list of lines.
@7-fl
7-fl / aw2.erl
Last active March 17, 2017 17:35
-module(aw2).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
% I put the code for converting the line numbers into runs in another module
% called runs, and I call the function runs:runs() from this module.
% Variable names:
% Is => Indexes, I => Index
% I => {"word", [1, 3, 7, 9]}
-module(runs).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
% [1, 4, 7, 2, 3]
% [1, 2, 3, 4, 7]
%
% What about [2, 3, 3, 4]??? => Done!
%
%---------------
@7-fl
7-fl / x.erl
Last active March 2, 2017 15:04
Functions over lists
-module(x).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
evens_test() ->
[] = evens([]),
[-2, 0, 2] = evens([-2, -1, 0, 1, 2]),
[4, 2, 0] = evens([4, 3, 2, 1, 0]),
all_tests_passed.
@7-fl
7-fl / review.md
Last active March 1, 2017 04:04
Code review for: Joel Potischman

perimeter():
area():

Well done. Straight forward. Thanks for including tests! It makes it easier to review code.

Critique: The future learn web site is not equipped to handle computer programmers. To preserve the formatting of your code and make it easier to read, consider posting your code someplace off site and include a link. As the next video mentions, you can post to a place called hastebin, which will provide a url, and you don't even need to log in. Or, you can open an account here at github or somewhere similar.

Another suggestion: I thought that writing a test when a float was the return value from one of the functions was a little tricky. I see that you used some floats in your tests. I used the following trick, I don't know if it's the best way, but maybe you will find it useful:

@7-fl
7-fl / review.md
Last active March 15, 2017 09:56
Code Review for: Slava Zipp

bits():
My god. The pure clarity of your bits() code stunned me. My solution involved bit twiddling using band and an ugly hack to get the bit length of the number. I was shocked to see your solution. I just sat there for a few minutes staring at the beauty of the thing.

After getting over my shock, I couldn’t figure out how your solution worked, so I ran it through my tests to make sure it did work, and it passed with flying colors! Next, I ran through a couple of examples in my head, 8, 9, 10, and I’m still not sure how you came up with your solution! But staring at the simplicity of your code has been a balm on my bit frazzled mind.

Critique: What do I do after the bliss disappears, and I’m haunted by doubts that I’ll ever be able to write code like that? What about including some tests with your code? It makes it easier for a reviewer to test changes to your code. I think the problem description mentioned possibly including some tests.

I Forgot to mention this in my submission: Why not u

@7-fl
7-fl / review.md
Last active February 27, 2017 19:00
Code Review for: Reiner Rodriguez

perimeter():
area():

I think you should include tests with your code so that reviewers can make proposed changes and run the tests to make sure everything still works. I apologize if you already know how to create tests.

You can create a test by figuring out in your head what, say, the perimeter of a square with side 3 is, i.e. 12, and then seeing if your code produces the same result:

perimeter_tests() ->
    12 = perimeter({square, 3}),