Count lines of code
The following counts all the lines in all *.rb
files in the app
directory. Run several of these commands to get a rough estimate of the LOC.
find app -name *.rb -exec wc {} \; | awk '{a+=$1;print a}' | tail -1
Related cards:
Video transcoding: Web and native playback overview (April 2020)
Intro
Embedding videos on a website is very easy, add a <video>
tag to your source code and it just works. Most of the time.
The thing is: Both the **operating system and Browser of your client must support the container ...
Ruby: Counting occurrences of an item in an array / enumerable
Enumerable#count
can do three things.
- With no argument provided, it returns the number of items.
- With an argument, it returns the number of items matching the given value.
- With a block, ...
hatful of hollow - Reading Code: In praise of superficial beauty
Good programmers know that a lack of superficial code quality and consistency is the best indicator of deeper systemic problems in a project. If you ever need a quick estimate of the quality of a codebase, this is what you should look at first.
Project maintenance: four levels of code quality
Code quality can be measured in four levels:
- (Working code)
- Reliable code (minimum)
- Readable code (ok for short-lived code)
- Changeable code (standard level)
The code quality of a project directly impacts its maintainability.
General...
Grep the number of occurences in a file, counting multiple hits per line
Grep prints one line per match. To return the number if matches, use the -c
switch:
grep -c "something" filename
However, if a word appears more than once in a line, it is only counted once.
To count every match, you can use [sed
](http:...
Get Rid of That Code Smell – Duplication
Removing duplication from the code is a seemingly easy task. In many cases it is pretty straight-forward – you look at similar bits of code and you move them to a common method or class that is reusable in other places. Right? No, not really. It i...
Measuring sql query time of a piece of code using ActiveSupport::Notifications
ActiveSupport::Notifications provides an instrumentation API for Ruby. It is used throughout rails to publish instrumentation events that include information about each part of a request/response cycle.
Have a look at your application log file -...
The challenging setup of an offshore project
After managing a few agile projects from India and learning the tricks of the trade, I have been wondering why life is much easier when you are working closely with the client as compared to working offshore. What worried me more was that I had to...
Take care of indentation and blank lines when using .erb for plain text emails
Building plain text emails with an .erb template doesn't allow you to indent code like you normally do in HTML mails.
DON'T
<%= 'foo' if bar %>
"\n"
if bar is false
"foo\n"
if bar is true
<%= nil %>
"\n"
-...
Deal with different ways of counting weeks and weekdays in Ruby
Depending on where you live, different rules are used to determine the number of the week and a weekday. You have no chance whatsoever to get this...