I have done this path more than 1 thousand times, just like you have done some path that many times… and today i got this feeling that i needed to record this path, so one day in the future, i can remember why i did it in the first place… and why i stopped.
Moments from the daily path…
Itunes Remove duplicated songs
I’m really bad organizing my music so i end up always with a lot of songs duplicated in my itunes library… and since googling for discovering how itunes can do that for you is less funny that do it yourself, it seemed a nice opportunity to programme some more erlang code for humanity great good!
So you can find on github http://github.com/darkua/Itunes-KISS the code and the how to use it.
i have tested on Mac Osx but it should work in any platform.
4 hours of coding for removing 2GB out of 15GB of duplicated music in less then 1 minute looks good
Special thanks to @citizen428 for the id3tagV1 parser ( http://citizen428.net/archives/993 )
Great Programming Quotations
“Measuring programming progress by lines of code is like measuring
aircraft building progress by weight.“Bill Gates
“Nine people can’t make a baby in a month.” Fred Brooks
“Weeks of coding can save you hours of planning.” unknown
You can find a lot more here
WebSocket Handshake 76 in Erlang
Websocket get update and handshacke get broken… this is not for sure and end version of the protocol, but since newer versions of chrome are using it and its not compatible with previous version its a good option to implement both.
In order to understand what changed, i recommend you to read the great resume done in Axod’s Hack .
Mainly you need to get 3 keys, 2 of them are send in the headers and the 3rd is sent after the headers. Then you need to do some “weird” transformation with the 3 and send them back after the header.
After having the 3 keys, here is the code in erlang to build the challenge to send back to client:
Now that you have the challenge just build the response like this :
Challenge = build_challenge(Key1,Key2,Key3),
HandshakeServer = [
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n",
"Upgrade: WebSocket\r\n",
"Connection: Upgrade\r\n",
"Sec-WebSocket-Origin: ", Origin , "\r\n",
"Sec-WebSocket-Location: ws://", Location , "\r\n\r\n",
Challenge
],
As soon i can i will create a new branch on misultin web server so you can see the code working.
Erlang lists:keyfind VS proplists:get_value
Other Day @fdmananatold me that he discover that lists key find was much more fast then proplists. Since i use a lot of proplists on my code, i did some tests to check how much fast it is and i was shocked!
(af83@dakua.local)34> timer:tc(proplists,get_value,[99999,List]).
{8685,99999}
(af83@dakua.local)35> timer:tc(lists,keyfind,[99999,1,List]).
{829,{99999,99999}}
WOW! for a list of 100.000 elements proplists:get_value can be 10x slower then lists:key_find!
So now i’m using this encapsulation in order to maintain proplists syntax and avoid extra typing
proplist_get_value(Key,List)->
case lists:keyfind(Key,1,List) of
{_K,V}->
V;
false->
undefined
end.
Now the question is Why? why lists is much more faste then proplists? Our guess is that since lists functions are BIF’s, they must be build in C and proplists no, but this is just a guess, if someone has a better explanation please share.
Erlang Code to UnShort Tiny Url’s
A simple erlang gen_server to return original url from short ones.
It accepts any kind of of url, retrieving zero or one redirect location.
Just copy the code and give it a test :
darkua:~ sergioveiga$ erl
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]
Eshell V5.7.4 (abort with ^G)
1> c(unshort_srv).
{ok,unshort_srv}
2> unshort_srv:start_link().
{ok,<0.39.0>}
3> unshort_srv:unshort(”http://tarpipe.com/kE”).
{ok,”http://sergioveiga.com/index.php/2010/02/21/erlang-code-to-unshort-urls/”}
4> unshort_srv:unshort(”http://google.com”).
{ok,”http://www.google.com/”}
5>
Erlang kicks C++ ass
I just read a paper from Ericsson about Productivity and Quality, where they compare Erlang and C++, and guess what… erlang rules with 4 to 10 times less code and less errors!!! You can read the full paper here, but i copy paste some of the conclusions :
“Comparisons between Ericsson-internal development projects indicate similar line/hour
productivity, including all phases of software development, rather independently of which
language (Erlang, PLEX, C, C++ or Java) was used. What differentiates the different
languages then becomes source code volume.
Some concrete comparisons of source code volume have been made, as applications
written in C++ have been rewritten in Erlang, resulting in a ten-fold reduction in the
number of lines of uncommented source code. Other comparisons have indicated a four-
fold reduction. A reasonable conclusion is that productivity increases by the same factor,
given the same line/hour programmer productivity.
When measuring product quality in number of reported errors per 1000 lines of source
code, the same relationship seems to exist: similar error density, but given the difference
in code volume, roughly 4-10 times fewer errors in Erlang-based products.
Furthermore, experiences from maintaining some Erlang-based products in the field
indicates that error corrections usually do not give rise to unwanted side-effects. This is in
line with what one would expect from using a mostly side-effect free declarative
language.
These comparisons do not pretend to hold up to scientific scrutiny, but they are collected
from indicators which show a rather consistent pattern. They also seem consistent with
opinions offered by non-Ericsson developers [one2one],[sendmail].
While AXD 301 consists of programs written in C, C++ and Java as well as Erlang, and
each language is used where it fits best, practically all the complex work is done in
Erlang. This is usually decided by the designers themselves – many of our most skilled C
programmers prefer Erlang for complex tasks, and consider it the obvious choice for
anything that involves concurrency or distribution.
Finally, we have seen that programmers – even those with no previous exposure to
functional languages – learn Erlang quickly, and become productive within a matter of
weeks.”
I had exactly the same feeling when started to code erlang comparing to my previous most used languages, Java and PHP.
Idea 73
Twiiter Im : the idea is transform twitter social relations, into a Distributed Instant Message Network. In other words, we could build something close to facebook chat system, that works in any website by just inserting a simple js script. So you would be able to see what friends are current online, and engage deeper discussions that are not possible in 140 chars.
So mainly its similar to meebo/mashable integration, but without needing to register in any place, and much more simpler.
The best part of this idea, to me, is that would be a great project to push erlang to the max
What you think?
Erlang Web Development with Nitrogen
I willl be presenting @codebits tomorrow by 11am in stage 1, my Erlang On Nitro talk.
It will be a simple introduction to erlang, and how you can use it for building web applications. With erlang and nitrogen you can very easily start building real-time web applications, using comet, that are fault-tolerant. I will assume that you have never heard of erlang before, so don’t be afraid to join us.
The talk will follow the tutorial i published some hours ago
, so i you are attending i suggest a quick read, in order to make the talk more productive!


















