<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tuenti Developers</title>
	<atom:link href="http://blog.tuenti.com/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tuenti.com/dev</link>
	<description>Just another tuenti weblog</description>
	<lastBuildDate>Mon, 12 Dec 2011 09:28:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=tuenti</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>BcnDevCon 2011: Security, Mobile and our Release Process</title>
		<link>http://blog.tuenti.com/dev/bcndevcon-2011-security-mobile-and-our-release-process/</link>
		<comments>http://blog.tuenti.com/dev/bcndevcon-2011-security-mobile-and-our-release-process/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 16:00:10 +0000</pubDate>
		<dc:creator>Luis Peralta</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Talks / Presentations]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[barcelona]]></category>
		<category><![CDATA[bcndevcon]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=609</guid>
		<description><![CDATA[<p><strong>Diego Muñoz<em>Senior Fronted Engineer</em></strong></p>

Two weeks ago we were platinum sponsors of the <a href="http://bcndevcon.org/">Barcelona Developers Conference 2011</a>, spending three days assisting to developer and entrepeneur talks but also speaking on three different tracks.
]]></description>
			<content:encoded><![CDATA[<p><strong>Diego Muñoz<em>Senior Fronted Engineer</em></strong></p>
<p>Two weeks ago we were platinum sponsors of the <a href="http://bcndevcon.org/">Barcelona Developers Conference 2011</a>, spending three days assisting to developer and entrepeneur talks but also speaking on three different tracks.</p>
<p>The 17th I spoke about how Tuenti release workflow works, both from the development perspective and from a broader devops and testing one. I detailed some of the opensource tools we use, the reasons why and some bottlenecks or problems we’ve run into.</p>
<div id="__ss_10239392" style="width: 425px"><strong><a title="Tuenti Release Workflow" href="http://www.slideshare.net/TuentiPresentaciones/tuenti-release-workflow" target="_blank">Tuenti Release Workflow</a></strong></div>
<div style="width: 425px"><strong><br />
</strong></div>
<p>On the 18th our Backend Framework and Security Lead gave a talk about security: Common web attack vectors, how they work, how to prevent them and some specific countermeasures we apply.</p>
<div id="__ss_10254820" style="width: 425px"><strong><a title="Tuenti: Web Application Security" href="http://www.slideshare.net/TuentiPresentaciones/bcn-web-applicationsecurity" target="_blank">Tuenti: Web Application Security</a></strong></div>
<div style="width: 425px"><strong><br />
</strong></div>
<p>And finally, on the 19th our Mobile Core Tech Lead gave an interesting talk about the evolution of Tuenti’s Mobile site, challenges you face when you build for such a broad and varied device segment and how we try to give the best experience on each of them.</p>
<div id="__ss_10257007" style="width: 425px"><strong><a title="Tuenti Mobile Development" href="http://www.slideshare.net/TuentiPresentaciones/tuenti-mobile-development" target="_blank">Tuenti Mobile Development</a></strong></div>
<div style="width: 425px"><strong><br />
</strong></div>
<p>More or less at the same time, Pedro Álvarez and Diana López from the Apps Platform team, gave a presentation at the <a href="http://www.uah.es">Universidad de Alcalá de Henares</a>, during the first national RITSI event on Agile Methodologies and Cloud Computing. Their talk: <em>Tuenti, from idea to the web</em>, was a great success.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/bcndevcon-2011-security-mobile-and-our-release-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FICOD 2011: Tuenti, the Mobile Web, and TU</title>
		<link>http://blog.tuenti.com/dev/ficod-2011-tuenti-the-mobile-web-and-tu/</link>
		<comments>http://blog.tuenti.com/dev/ficod-2011-tuenti-the-mobile-web-and-tu/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 09:56:00 +0000</pubDate>
		<dc:creator>Erik Schultink</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=592</guid>
		<description><![CDATA[<p><strong>Erik Schultink <em>CTO</em></strong></p>

Last week, I had the chance to speak at FICOD - a fantastic event located right here in Madrid.  I spoke about the history of Tuenti, the lessons we’ve learned, the opportunity we see in the Mobile/Web ecosystem, and our vision for TU to address that opportunity.]]></description>
			<content:encoded><![CDATA[<p><strong>Erik Schultink <em>CTO</em></strong></p>
<p>Last week, I had the chance to speak at FICOD &#8211; a fantastic event located right here in Madrid.  I spoke about the history of Tuenti, the lessons we’ve learned, the opportunity we see in the Mobile/Web ecosystem, and our vision for TU to address that opportunity.</p>
<p>You can find the links to the video and slides below &#8211; but there are a few key messages about TU worth highlighting:</p>
<ul>
<li>social networking is becoming less about connecting with people, and more about communicating with them.</li>
<li>TU takes this communication to the next level; keeping you always connected with your friends</li>
<li>TU’s combines content/experience (namely, Tuenti’s social content and apps) with an operator &#8211; and explore what what innovation a social web company can bring to what’s a largely undifferentiated product offering in the Telco market today</li>
</ul>
<p>TU leverages social context in a couple unique ways:</p>
<ul>
<li>the bill (and billing model) is social; through the web, you see who you’re calling and how much it costs; and with most plans, friends on TU are free.</li>
<li>voicemail arrives instantly to the web interface, where you can see the sender’s profile and play, delete, and reply.</li>
</ul>
<p>Check out the video at <a href="http://www.ficodtv.es/index.php?seccion=ver_video&amp;id=1273">FICOD TV</a>.</p>
<p>Find the deck on <a href="http://www.slideshare.net/TuentiPresentaciones/tu-telco-20-at-ficod-2011">Slideshare</a>.</p>
<p>You can check out TU itself at:</p>
<p><a href="http://www.tuenti.com/tu">http://www.tuenti.com/tu</a></p>
<p>I’d like to thank the organizers of FICOD for the invitation to speak &#8211; and our Communications and TU teams for helping me prepare the presentation.</p>
<p>Finally, the mind map FICOD made during the talk:<br />
<a href="http://www.ficod.es/ficod/sites/default/files/u39514/NOTES-FICOD_ErikSchulthink_web.jpg"><img width="700px" src="http://www.ficod.es/ficod/sites/default/files/u39514/NOTES-FICOD_ErikSchulthink_web.jpg" alt="FICOD mind map" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/ficod-2011-tuenti-the-mobile-web-and-tu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Because SSH and &#8220;for&#8221; loop doesn&#8217;t cut it</title>
		<link>http://blog.tuenti.com/dev/because-ssh-and-for-loop-doesnt-cut-it/</link>
		<comments>http://blog.tuenti.com/dev/because-ssh-and-for-loop-doesnt-cut-it/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 16:00:13 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[puppet]]></category>
		<category><![CDATA[bootstrapping]]></category>
		<category><![CDATA[configuration management]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=575</guid>
		<description><![CDATA[Ricardo Bartolomé Senior Systems Engineer
Here at Tuenti we were managing our servers in a old-fashioned way for a long time. We used &#8220;for&#8221; loops in order to replicate changes across different servers, but as we’re grew that became more complex over time and with new people joining the team. Fortunately, now we have an automated [...]]]></description>
			<content:encoded><![CDATA[<div><strong>Ricardo Bartolomé <em>Senior Systems Engineer</em></strong></p>
<p>Here at Tuenti we were managing our servers in a old-fashioned way for a long time. We used &#8220;for&#8221; loops in order to replicate changes across different servers, but as we’re grew that became more complex over time and with new people joining the team. Fortunately, now we have an automated deployment system that deploys a basic image to a server based in its server role. Once the node is up we use Puppet for transforming the node to the desired state, ensuring specific versions of the packages are installed, configuration files are in place and services are running.</p>
<p>We have chosen Puppet because it&#8217;s easy to understand, it&#8217;s straightforward, it’s extensible and it has a very good community around it.</p>
<ul>
<li>Easy to understand: Puppet doesn’t have obscure components that are hard to understand. For example, the communication between client and server is made using a REST API over a SSL channel using client certificates issued by the integrated Puppet CA.</li>
<li>Straightforward: Moving from manual configuration to configuration management system requires a change of mind about how you manage your platform. Nevertheless, you&#8217;ll be able to deploy it and write your automated configurations in minutes. People in the team was able to configure new components and modify existing ones after a brief explanation.</li>
<li>Extensible: At the moment we just created custom facters, but we&#8217;ll need to extend puppet with custom types for easily managing our queue system configurations in a more flexible way. Some people have started to share some custom types and modules in the <a href="http://forge.puppetlabs.com" target="_blank">Puppet Module Forge</a>.</li>
<li>Community: I had the pleasure of attending last PuppetCamp Europe 2011 held in Amsterdam on April 28th. I have met and shared experiences with a lot of developers, people working in systems operations, and even the PuppetLabs engineers. In the open conferences, the strong technical background of the attendees was apparent and you could see how PuppetLabs engineers listened to us about which features we would like to have in Puppet or how to improve them.</li>
</ul>
<div>
<p>When we configure the amount of PHP processes that we spawn in our frontends we base this decision on the amount of CPU power of the server. This has a direct relation with the amount of memory, given that more CPU means more concurrent requests and also more memory usage. For automating the amount of PHP children that should be spawned we use a custom facter. A custom facter is a piece of Ruby code that is executed to return a fact for a node. The default facts are hostname, ip address, netmask, amount of memory, processors, kernel version, etc, and they&#8217;re very useful, but sometimes you need to extend it. In the example displayed below we create a custom fact called &#8220;tuenti_phpchildren&#8221; that will take decisions about the amount of PHP children spawned per server. I use an existing custom facter called &#8220;tuenti_memorysize&#8221; that returns the amount of memory installed in a server as an integer.</p>
<blockquote><p><code>Facter.add("tuenti_phpchildren") do<br />
setcode do<br />
memtotal = Facter.value('tuenti_memorysize')<br />
if memtotal &gt; 20000000<br />
phpchildren = "300"<br />
elsif memtotal &gt; 9000000<br />
phpchildren = "200"<br />
elsif memtotal &gt; 5000000<br />
phpchildren = "100"<br />
else<br />
phpchildren = "50"<br />
end<br />
phpchildren<br />
end<br />
end</code></p></blockquote>
<p>Then we use the custom facter inside a template, to ensure the file contains the proper configuration for the daemon.</p>
<p dir="ltr">max_children = &lt;%= tuenti_phpchildren %&gt;</p>
<p>Automating your whole platform using Puppet is not something you&#8217;ll accomplish in three days (if you have a large fleet of servers with different roles as we have), but it&#8217;s a really worth the effort. Some advantages we got from moving our configuration management to Puppet are:</p>
<ul>
<li>No configuration drifts: Puppet is checking in the background that everything is fine and will revert to the desired state if something has changed (accidentally or on purpose).</li>
<li>Become more agile: We are a fast-moving company that requires changes every day and we can&#8217;t continuously spend our time on repetitive tasks. Now we deploy changes to production within minutes having more control than we use to have in the past.</li>
<li>Save time: We automate once and we could be able to easily bootstrap hundreds of nodes in minutes.</li>
<li>Comply with industry standards: Some law enforcements like Spanish LOPD or PCI Compliance require a list of policies that must be met in all the servers from your company, like access controls, encryption ciphers used in SSL transactions, password management and more.</li>
<li>Document itself: Puppet won&#8217;t excuse you from documenting your platform, but once someone reads a manifest they’ll already understand what that piece of code is doing. No more tedious explanations about what to do or what to execute for configuring a service.</li>
<li>Share knowledge: Now we&#8217;re able to share our Puppet modules with other teams like QA or Dev Tools in order to align our development, testing, and production environments. Also, using different Puppet environments we can have different versions of a module in different stages like development, staging and production, while having a reasonable workflow: First you develop it, then you try it across some servers, and finally you deploy it to the whole platform.</li>
</ul>
<p>Our current Puppet architecture is based in three Puppet Masters that bring configuration management to more than 1k nodes. Scaling this platform is as easy for us as adding extra nodes and adding them to the load balancing pool. Puppet also offers a reporting feature that can be used with the Puppet Dashboard in order to have a view at a glance of your platform. Given that all the reporting data is stored in a database you can integrate it with your internal tools or dashboard in order to detect nodes that are not applying configuration properly or are suffering unexpected changes.</p>
<p>To make the development of manifests easier, a project named Geppetto was born some time ago. Besides the tool itself, it offers a module for Eclipse that will make your life much easier. For hardcore people, you also have Vim syntax highlighting provided by PuppetLabs.</p>
<p>In summary, even if you only have one server you need to be able to reproduce its configuration. So if you have the opportunity, try some configuration management like Puppet and move out from sysadmin hell to operational bliss.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/because-ssh-and-for-loop-doesnt-cut-it/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>EmTech Spain</title>
		<link>http://blog.tuenti.com/dev/emtech-spain/</link>
		<comments>http://blog.tuenti.com/dev/emtech-spain/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 14:39:36 +0000</pubDate>
		<dc:creator>Erik Schultink</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=569</guid>
		<description><![CDATA[<p><strong>Erik Schultink <em>CTO</em></strong></p>

Last week, I had the chance to speak at <a href="http://www.emtechspain.com/en/">EmTech Spain</a> as part of a panel discussion on “The Future of the Internet”. Our challenge as panelists was to envision what the web would look like in 10 years.  I talked mostly about mobile and its implications, which, given the launch of <a href="http://www.tuenti.com/tu">Tu, our MVNO</a>, have occupied a lot of my thinking during the past year.  ]]></description>
			<content:encoded><![CDATA[<p><strong>Erik Schultink <em>CTO</em></strong></p>
<p>Last week, I had the chance to speak at <a href="http://www.emtechspain.com/en/">EmTech Spain</a> as part of a panel discussion on “The Future of the Internet”. Our challenge as panelists was to envision what the web would look like in 10 years.  I talked mostly about mobile and its implications, which, given the launch of <a href="http://www.tuenti.com/tu">Tu, our MVNO</a>, have occupied a lot of my thinking during the past year.  </p>
<p>The biggest change in the mobile web over the last 2-3 years has been the emergence of Apps, driven by the success of the iPhone and its application platform. The signature user experience that the iPhone introduced, with its mass consumer appeal, has earned Apple the market power to control not just the OS and its UX, but to control the App distribution platform as well.  This is without precedent; Apple, a device manufacturer, is in a position to gate the individual apps for UX and functionality, as well as control the payments coming from users to download and transact within those apps.  Other device manufacturers have followed suit &#8211; Android, Blackberry, with Microsoft/Nokia and Amazon soon to follow.  This is the biggest shift we’ve seen producing software products shifted from building native applications to building web applications. Now we must build device applications &#8211; again native &#8211; but with different UX considerations (touch v keyboard, screen resolution, tablet v phone) on each.  Cross-platform development is no longer just a technical challenge of trying to build the same product experience on Mac + Windows or on IE + Netscape/Firefox.  It’s now a product and design challenge to reframe that experience within the unique bounds of each platform/device &#8211; as the signature UX of the device carries through into the product experience.</p>
<p>Consider our case at Tuenti.  Tuenti today builds two HTML clients &#8211; <a href="http://www.tuenti.com">www.tuenti.com</a> and  <a href="http://m.tuenti.com">m.tuenti.com</a> &#8211; and mobile clients on 4 platforms (iPhone/iOS, Android, Blackberry, J2ME).  Already we have two distributions of the J2ME, built to target lower- and higher-end devices.  It’s foreseeable a similar need will emerge for Android, and potentially as the tablet markets for iOS and Android grow, we’ll need to target those with variants targeted towards that specific form factor.  That’s 6 different UXes currently (and more coming) built to let users do the same fundamental things:  chat, view friend’s content, share photos, etc.</p>
<p>The above is without mentioning an entire class of platforms we don’t build for now, but I expect to be an increasingly relevant way for people to access the Web: video game consoles.  Of course, these consoles are increasingly used for a lot more than video games: casual web browsing, video on-demand, etc.  It’s something that Tuenti &#8211; and anyone planning to deliver products that people use multiple times per day &#8211; will need to address.</p>
<p>How this ecosystem evolves in the next few years will dictate what products are brought to market and what types of companies bring them to market (how can start-ups build 6 apps?).  I expect some convergence, driven probably as much by the people building products (eg us) as the dynamics of the consumer markets.  Apps are a major aspect of the user experience of the phone; consumers will be drawn to the platform that has the apps they want to use.  And App makers, particularly start-ups, will need to make tough choices about which platforms they build for.  The next generation of innovative apps won’t be available on every device platform.  I would also guess that the most innovative apps will be built for the most-open platforms &#8211; with the fewest limits on UX and what device functionality the developer can access. </p>
<p>Finally, I want to thank the organizers (<a href="http://www.technologyreview.es/">MIT Tech Review Spain</a>, <a href="http://www.malagavalley.com/">Club Malaga Valley</a>) and sponsors of EmTech Spain for the invitation; <a href="http://twitter.com/ariel">Ariel Poler</a> for moderating the panel; and the fellow panelists &#8211; Geoff Ralston (Co-Founder, Imagine K-12) and <a href="http://twitter.com/othman">Othman Laraki</a> (Director of Growth, Twitter).  </p>
<p><i>On November 24, I’ll be speaking more about the evolution of the mobile web and how Tu fits into that at <a href="http://www.ficod.es/ficod/">FICOD</a>.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/emtech-spain/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Summer Reading</title>
		<link>http://blog.tuenti.com/dev/summer-reading/</link>
		<comments>http://blog.tuenti.com/dev/summer-reading/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 12:21:31 +0000</pubDate>
		<dc:creator>Erik Schultink</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=551</guid>
		<description><![CDATA[<p><strong>Erik Schultink <em>CTO</em></strong></p>

It’s that time of year again - your family/significant other is dragging you to the beach for a week.  It’s a sunny, sandy place that won’t do your laptop any favors.  How to make the best of it?  My suggestion is to bring along some good books - and I’ve devoted this entry to listing some specific recommendations with relevance to our work.]]></description>
			<content:encoded><![CDATA[<p><strong>Erik Schultink <em>CTO</em></strong></p>
<p>It’s that time of year again &#8211; your family/significant other is dragging you to the beach for a week.  It’s a sunny, sandy place that won’t do your laptop any favors.  How to make the best of it?  My suggestion is to bring along some good books &#8211; and I’ve devoted this entry to listing some specific recommendations with relevance to our work.</p>
<p><strong>Dreaming in Code</strong>, by Scott Rosenburg, chronicles the Chandler project &#8211; an effort led by Mitch Kapor to build a personal organization application that seems to do just about everything (which should tip you off to how that ends up working out).  The account reveals a lot of the challenges faced by product dev teams &#8211; most of which I’m sure you’ll find familiar.  If your team’s ever struggled in the face of shifting requirements and attempts to integrate new technologies, you’ll be happy to learn that you definitely are not alone. (<a href="http://dreamingincode.com">link</a>)</p>
<p><strong>Finding Flow</strong>, by Mihaly Csikszentmihalyi, introduces the concept of flow &#8211; optimal engagement in the task at hand &#8211; and discusses how to structure your experiences to create it.  I think you’ll find that most of us are attracted to engineering precisely because it lends itself to engaging us in this way.  Most people find such engagement fulfilling (Csikszentmihalyi equates it with happiness and general life satisfaction) &#8211; but in an engineering context it’s also quite productive.  How can you craft your time, work, and environment to lend themselves to periods of flow?  (note &#8211; he has several newer books, which I have yet to read)</p>
<p><strong>Talent is Overrated</strong>, by Geoff Colvin, debunks a common myth that exceptional performers are blessed with some type of exceptional innate talent for their discipline.  It then advances the concept of “deliberate practice” as an alternative explanation &#8211; arguing that the capability to perform at an exceptional level is acquired only with lots of hard, structured work &#8211; ideally under the guidance of expert teachers.  Such work is not fun, not easy, and requires intense concentration and personal drive to pursue.  (while the first half of this book is quite interesting, the second diverges into some anecdotes about leadership at GE which I don’t think are very relevant to our field).</p>
<p><strong>The Art of Scalability</strong> by Martin L. Abbot and Michael T. Fisher.  This book is unbelievably relevant to actual engineering management &#8211; it is the closest thing I’ve ever found to guide for doing my job.  While it’s focused more on the systems ops/scalability side of things and is occasionally very process heavy, it is a very useful book. (<a href="http://theartofscalability.com/">link</a>)</p>
<p><strong>The Innovator’s Dilemma</strong>, by Clayton M. Christensen.  A classic work analyzing how some companies are able to innovate &#8211; and others aren’t.  Prevailing wisdom in tech is usually that the bigger a company is, the worse it is at innovating.  Christensen illustrates that the size of the company isn’t as important you might think &#8211; the type of technological change and the organizational history are also critical determinants of whether a company can successfully innovate and commercialize the technology.  Big companies do some things very well; start-ups do other things very well; the question is whether your company is in the right position for what it&#8217;s trying to do.</p>
<p><strong>Switch</strong>, by Chip and Dan Heath.  All this summer reading is only valuable if you can leverage this knowledge to change yourself/your team for the better.  So the last book on this list is focused on that: motivating yourself or others to make a change, especially in the face of prevailing attitudes, habits, or organizational inertia.</p>
<p>After reading these books, I hope you’ll return from summer not only well-rested, but also with some new ideas on how to do your work better.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/summer-reading/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How third party software can affect your site: AVG Antivirus and avg_ls_dom.js</title>
		<link>http://blog.tuenti.com/dev/how-third-party-software-affect-site-avg-antivirus-avg_ls_dom-js/</link>
		<comments>http://blog.tuenti.com/dev/how-third-party-software-affect-site-avg-antivirus-avg_ls_dom-js/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 09:05:15 +0000</pubDate>
		<dc:creator>Luis Peralta</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[avg]]></category>
		<category><![CDATA[avg antivirus]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=546</guid>
		<description><![CDATA[<p><strong>Alberto Gragera <em>Frontend Framework Tech Lead</em></strong><br />
<strong>Sergio Cinos <em>Frontend Senior Engineer</em></strong>
</p>

Rule of thumb: your Javascript code might not be the only one executing in your website. Browser extensions and plugins as well as security software might be running their own javascript code before yours and thus, they can potentially break your site. Sadly, that was happening to some of our users with AVG antivirus - the site didn’t work at all for them.
]]></description>
			<content:encoded><![CDATA[<p><strong>Alberto Gragera <em>Frontend Framework Tech Lead</em></strong><br />
<strong>Sergio Cinos <em>Frontend Senior Engineer</em></strong>
</p>
<p>Rule of thumb: your Javascript code might not be the only one executing in your website. Browser extensions and plugins as well as security software might be running their own javascript code before yours and thus, they can potentially break your site. Sadly, that was happening to some of our users with AVG antivirus &#8211; the site didn’t work at all for them.</p>
<p>We tried to reproduce the issue installing the AVG antivirus software in some of our machines, but the site worked perfectly for us. So we went back to the investigation and to our own surprise, the issue was only affecting users that had updated the software recently and not to users with fresh installs.</p>
<p>We managed to reproduce the issue and we discovered that AVG injects a script tag as the first child of the head on every single HTML file. The script src looks like this</p>
<pre>
&lt;script type=”text/javascript” src=”/A2EB891D63C8/avg_ls_dom.js”&gt;&lt;/script&gt;
</pre>
<p>This file is always loaded and executed by the browser before than any custom code that the site might want to load and execute. The javascript code in the file is quite aggressive and can potentially trigger some weird, unexpected and hard to debug issues.</p>
<p>That was the case.</p>
<p>Among other code, the file contains these lines:</p>
<pre>
Chck_Function.prototype = Function.prototype;
Chck_Function.prototype.constructor = Chck_Function;
</pre>
<p>which basically overwrites Function.prototype.constructor assigning it to Chck_Function because both prototype properties now point to the same object. Our TuJS library does strong type checking to ensure that all the parameters are what they are expected to be and these lines being executed before our library was loaded were messing with them miserably.</p>
<p>Tuenti has contacted AVG regarding this bug and a fix is going to be pushed out very soon. In the meantime, we made a very simple workaround: just redefine Function.prototype.constructor again before our library is loaded.</p>
<pre>
&lt;head&gt;
&lt;!-- Automatically injected by AVG →
&lt;script type=”text/javascript” src=”/A2EB891D63C8/avg_ls_dom.js”&gt;&lt;/script&gt;
&lt;script type=”text/javascript”&gt;
        Function.prototype.constructor = Function;
&lt;/script&gt;
… Rest of the page
</pre>
<p>If you are using some external library that does the same kind of type checks, you might be having the same problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/how-third-party-software-affect-site-avg-antivirus-avg_ls_dom-js/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tuenti Programming Contest: round one!</title>
		<link>http://blog.tuenti.com/dev/tuenti-programming-contest-round-one/</link>
		<comments>http://blog.tuenti.com/dev/tuenti-programming-contest-round-one/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 06:14:33 +0000</pubDate>
		<dc:creator>Luis Peralta</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[programming contest]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=533</guid>
		<description><![CDATA[<p><strong>Luis Peralta<em> Tech Lead</em></strong></p>

On Monday last week at 13:37, our first <a href="http://contest.tuenti.net">programming contest</a> came to an end. We sincerely hope that you enjoyed the contest during those seven days you've had to challenge yourself. On our side, it was more than one week to get this: preparing the contest judge, working of defining the problems (and also handing them over to some mates to solve them first!), preparing the submission toolchain, monitoring the contest, ... Even if it was lots of hard work, we have also had tons of fun.]]></description>
			<content:encoded><![CDATA[<p><strong>Luis Peralta<em> Tech Lead</em></strong></p>
<p>On Monday last week at 13:37, our first <a href="http://contest.tuenti.net">programming contest</a> came to an end. We sincerely hope that you enjoyed the contest during those seven days you&#8217;ve had to challenge yourself. On our side, it was more than one week to get this: preparing the contest judge, working to define the problems (and also handing them over to some mates to solve them first!), preparing the submission toolchain, monitoring the contest, &#8230; Even if it was lots of hard work, we also had tons of fun.</p>
<p>During those days, an almost neverending stream of comments on our <a href="http://www.tuenti.com/programacion">contest official page</a> and mentions to our <a href="http://twitter.com/TuentiEng">Tuenti Engineering Twitter account</a> was being received. We tried to solve every issue raised and also gave some small tips. Some really nice write-ups are have been posted already and they are worth taking a look at (for example, Gaspar Fernández has collected a <a href="http://totaki.com/poesiabinaria/category/tuenticontest/">list of them</a>, feel free to add yours in the comments). We will also be linking and/or publishing the outstanding write-ups after the winners are announced.</p>
<p>We have run some basic statistics on the top 75 contestants&#8217; code to see what language has been the most successfully used. Not surprisingly, some have used different languages depending on the problem. Still, the most used language has been Java, closely followed by C++ and Python. Take a look at the following chart:</p>
<p><a href="http://blog.tuenti.com/dev/files/2011/06/langs2.png"><img src="http://blog.tuenti.com/dev/files/2011/06/langs2.png" alt="" title="Programming languages used amongs the top 75" width="441" height="278" class="alignnone size-full wp-image-538" /></a></p>
<p>Remember that the online challenge was just the first round of the Tuenti Programming Contest. We will be contacting every finalist today in order to invite them to our offices next Friday and assist to a one-day workshop about our internal architecture and processes (and some more&#8230; but that&#8217;s still a secret). We will announce the winners just after that, so keep an eye here!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/tuenti-programming-contest-round-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get a Tuenti Engineering Job</title>
		<link>http://blog.tuenti.com/dev/get-a-tuenti-engineering-job/</link>
		<comments>http://blog.tuenti.com/dev/get-a-tuenti-engineering-job/#comments</comments>
		<pubDate>Wed, 25 May 2011 12:43:52 +0000</pubDate>
		<dc:creator>Erik Schultink</dc:creator>
				<category><![CDATA[Recruiting]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=513</guid>
		<description><![CDATA[<p><strong>Erik Schultink<em> CTO</em></strong></p>

Our recruiting team has been working really hard to scale out our Engineering teams in Madrid and Barcelona.  This is a major challenge - as we’re committed to maintaining a very high standard of quality in our team as we grow.  A big obstacle our recruiters face is that many candidates who appear to have significant, applicable work experience don’t end up performing very well in our selection process.  We’ve identified that a lot of the skills we look for, while taught at top universities, aren’t used that commonly in work at many European companies.  As such, candidates who have been out of university for a long time often are out of practice in many of these areas. In this article, I’ll briefly describe a number of topics that will be covered throughout the process.]]></description>
			<content:encoded><![CDATA[<p><strong>Erik Schultink<em> CTO</em></strong></p>
<p>Our recruiting team has been working really hard to scale out our Engineering teams in Madrid and Barcelona.  This is a major challenge &#8211; as we’re committed to maintaining a very high standard of quality in our team as we grow.  A big obstacle our recruiters face is that many candidates who appear to have significant, applicable work experience don’t end up performing very well in our selection process.  We’ve identified that a lot of the skills we look for, while taught at top universities, aren’t used that commonly in work at many European companies.  As such, candidates who have been out of university for a long time often are out of practice in many of these areas. In this article, I’ll briefly describe a number of topics that will be covered throughout the process.</p>
<p><strong>Algorithms and Data Structures </strong>- sorting, searching, trees, lists, hash tables, etc.  You should have a basic understanding of each such that you can apply them in solving different problems, and discuss costs/trade-offs imposed.  If you’re interested in working on more low-level stuff, it’s good to be familiar with the implementation of common open source projects that apply these concepts.  Most of the problem-solving type questions we’ll ask will involve applying these concepts to a practical problem to reach an efficient solution.</p>
<p><strong>OOP design </strong>- design principles, encapsulation, divisions of responsibility, common patterns, etc. This is one of the big things we look for in the code test &#8211; that you know how to structure clean, clear code using inheritance, abstract classes, encapsulation to support your design.  Expect that you’ll be asked to sketch out how you would structure code to implement a particular feature or solve a problem.</p>
<p><strong>Security</strong> &#8211; common attack vectors against web applications and tactics for combating them.  This probably isn’t something you learned in school; if you’re working at a good web company right now, hopefully they require you to be mindful about these vectors and you know the various pitfalls.  We’re pretty skeptical of pen-testing and audits as a way to prevent security problems, and our release cycle (twice per week) is too quick to allow for exhaustive use of such measures.  Our engineers need to be able to think critically about code written by themselves and others to ensure it does not introduce vulnerabilities into our applications.</p>
<p><strong>Database concepts</strong> &#8211; concurrency control, indexes, logical-to-physical mappings, query execution.  Tuenti’s a very data intensive application: our users create a ton of content and we present dynamic, unique views of that content to each visitor to the site.  Doing this efficiently requires us to be very careful about how things are stored, cached, and accessed within our systems.  A strong conceptual understanding of information management systems, as well as familiarity with a variety of implementations of such systems (eg MySQL, MemcacheD, Postgres, etc), is extremely helpful in understanding the design decisions we’ve made already and proving to us that you’ll make good decisions once you’re here.</p>
<p>Several points of the above will be evaluated in a code test.  In particular, for a code test you must present an efficient, correct solution implemented with good OOP design in a manner that is readable (using documentation, if needed). To pass, your solution needn’t be bug-free or have perfect style/syntax &#8211; but you shouldn’t show unusual carelessness either.  We care mostly about how you think, how you can express that in a well-structured solution, and what you can produce in the allotted time.</p>
<p>If you make it through the code test, you can expect to face questions about each of these in the interviews.  Generally speaking, we try to pose questions that are pretty broad and open-ended &#8211; especially as you progress farther in the interview process.  Clearly and concisely explaining your solution is important &#8211; don’t be afraid to sketch out something illustrating your solution and, of course, write code.</p>
<p>I hope that gives you an understanding of some of the broad technical areas we’ll cover.  Frequently, to be well-prepared across all of them requires that you are passionate about building web apps and spend a lot of time reading blogs and books related to these.  Such independence and self-motivation is also something we’re looking for throughout the process, as we try to ensure you’ll succeed in our culture.</p>
<p>If you’re ready, submit your CV at <a href="http://jobs.tuenti.com/">jobs.tuenti.com</a> If not, I’ll be posting more articles about the recruiting process here at Tuenti in coming weeks, so check back.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/get-a-tuenti-engineering-job/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Google IO streaming event</title>
		<link>http://blog.tuenti.com/dev/google-io-streaming-event/</link>
		<comments>http://blog.tuenti.com/dev/google-io-streaming-event/#comments</comments>
		<pubDate>Sun, 08 May 2011 21:25:39 +0000</pubDate>
		<dc:creator>Luis Peralta</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Talks / Presentations]]></category>
		<category><![CDATA[barcelona]]></category>
		<category><![CDATA[google io]]></category>
		<category><![CDATA[madrid]]></category>
		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=505</guid>
		<description><![CDATA[<p><strong>Luis Peralta<em> Tech Lead</em></strong></p>

At many of you know, it is not strange these days to see Tuenti engineers attending some of the tech events happening in Madrid (and Barcelona soon). This time, we are doing it the other way around: we will be opening our offices so that you can follow the <a href="http://www.google.com/events/io/2011/">Google IO</a> event with part of our engineering team and other guests.
]]></description>
			<content:encoded><![CDATA[<p><strong>Luis Peralta<em> Tech Lead</em></strong></p>
<p>As many of you know, it is not strange these days to see Tuenti engineers attending some of the tech events happening in Madrid (and Barcelona soon). This time, we are doing it the other way around: we will be opening our offices so that you can follow the <a href="http://www.google.com/events/io/2011/">Google IO</a> event with part of our engineering team and other guests.</p>
<p>This event will take place next Tuesday, May 10th, in our Madrid and Barcelona offices and below is the coordinated agenda between Google and Tuenti:</p>
<ul>
<li>16h30: Check in</li>
<li>16h50: Introduction</li>
<li>17h00: Presentation from Tuenti Engineering</li>
<li>17h30: Presentation of GTUG Madrid</li>
<li>18h00: Keynote</li>
<li>19h05: Main new announcements discussion</li>
<li>19h30: Time for a beer</li>
</ul>
<p>As can see, we will also be giving a couple of talks <img src='http://blog.tuenti.com/dev/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  If you want to attend (we have only a few slots left), please send an email to <em>googleio (at) tuenti (dot) com</em>. We will then confirm that you got one a nice place in our sofas room and send you over the details. Please remember, <strong><a href="mailto:googleio@tuenti.com">registration is REQUIRED</a></strong> and we won&#8217;t be able to make exceptions.</p>
<p>See you on Tuesday!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/google-io-streaming-event/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Regular expressions in JavaScript: Concepts &amp; Performance Issues</title>
		<link>http://blog.tuenti.com/dev/tips-and-tricks-with-regular-expressions-in-js/</link>
		<comments>http://blog.tuenti.com/dev/tips-and-tricks-with-regular-expressions-in-js/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 14:21:16 +0000</pubDate>
		<dc:creator>Erik Schultink</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tuenti.com/dev/?p=451</guid>
		<description><![CDATA[<strong>Miguel Jiménez Esún<em>Intern, Frontend Framework</em></strong>

<p>
Regular expressions are a sophisticated way to check for patterns. Here we review concepts and performance issues in JavaScript.
</p>]]></description>
			<content:encoded><![CDATA[<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Helvetica} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #100199} span.s1 {color: #100199} span.s2 {font: 11.0px Monaco} span.s3 {font: 11.0px Helvetica} span.s4 {color: #000000} span.Apple-tab-span {white-space:pre} --></p>
<p><strong>Miguel Jiménez Esún <em>Intern, Frontend Framework</em></strong></p>
<p>Regular expressions are a sophisticated way to check patterns against strings. In JavaScript, we have five native functions that can use regular expressions as an argument. These are the JS functions for performing operations with strings:</p>
<ul>
<li><code style="font-family: Courier, monospace">search</code>, <code style="font-family: Courier, monospace">match</code> and <code style="font-family: Courier, monospace">replace</code> methods of the String object (regexp is provided as the method’s argument).</li>
<li><code style="font-family: Courier, monospace">exec</code> and <code style="font-family: Courier, monospace">test</code> methods of the RegExp object.</li>
</ul>
<h2>Construction optimization</h2>
<p>Regular expressions have two sections: the regexp itself, and the modifiers. According to this scheme, they can be generated in two different ways:</p>
<ul>
<li><strong>With a ‘<code style="font-family: Courier, monospace">/</code>’ starter</strong>: the regexp is between two slashes; after the second we place the modifiers.</li>
<li><strong>With the RegExp constructor</strong>: the regexp is passed as a string as the first parameter, and the modifiers as the second parameter also as a string. This method allows building it from any data type  (strings, numbers, etc). However it does have a performance cost. For example, you can make a regexp to change a string in to another one by using a predefined regexp:
<pre>var str = "Hello, John! Today is Monday.";
var regexp = /John/g;
var user = str.match(regexp, 'Mark');</pre>
<p>This will return <code style="font-family: Courier, monospace">"Hello, Mark! Today is Monday."</code>. However in some cases this approach may not possible, i.e. you may need to provide the string to be replaced through a parameter:</p>
<pre>function myReplace(name) {
    var str = "Hello, John! Today is Monday.";
    var regexp = new RegExp(name, "g");
    return user = str.match(regexp, 'Mark');
}</pre>
<p>This will slow down your code by several orders of magnitude. Be extra careful specially if you are running it inside a loop. Here we can see the performance impact across different browsers (less is better):</p>
<p style="text-align: center"><span style="text-align: center"><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-1.png"><img class="size-full wp-image-474 aligncenter" title="Different ways of building a regexp" src="http://blog.tuenti.com/dev/files/2011/03/Graph-1.png" alt="" width="517" height="243" /></a></span></p>
<p style="text-align: center"><strong>Table 1</strong>. Different ways of building a regexp</p>
</li>
</ul>
<h2>Global modifiers optimization</h2>
<p>There are 3 different global modifiers in Javascript, which are described after the regexp closing slash. These can be <code style="font-family: Courier, monospace">g</code>, <code style="font-family: Courier, monospace">i</code>, and <code style="font-family: Courier, monospace">m</code>.</p>
<ul>
<li><strong><code style="font-family: Courier, monospace">g</code></strong>: only used in replace, match and exec methods. It performs a global replace instead of returning just the first occurrence only one.</li>
<li><strong><code style="font-family: Courier, monospace">i</code></strong>: case insensitive when making searches or replacements. For example, <code style="font-family: Courier, monospace">/a/gi</code> will find A and a. Use this modifier instead of a regular expression, because it will be up to 10% faster. E.g. using <code style="font-family: Courier, monospace">/a/gi</code> is faster than <code style="font-family: Courier, monospace">/[Aa]/g</code>. You must take in account that the i modifier is prepared to handle any unicode character, regardless of what code it has.
<p style="text-align: center"><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-2.png"><img class="aligncenter" title="Differences between /i modifier and double matching" src="http://blog.tuenti.com/dev/files/2011/03/Graph-2.png" alt="" width="374" height="242" /></a></p>
<p style="text-align: center"><strong>Table 2</strong>. Differences between using the <code style="font-family: Courier, monospace">/i</code> modifier against double match</p>
</li>
<li><strong><code style="font-family: Courier, monospace">m</code></strong>: multiline modifier, allows <code style="font-family: Courier, monospace">^</code> and <code style="font-family: Courier, monospace">$</code> modifiers to match against a <code style="font-family: Courier, monospace">\n</code> character and a <code style="font-family: Courier, monospace">\r</code> character, instead of just checking at the start or at the end of the string. This is a very useful and fast modifier so it is recommended to apply it whenever possible instead of an alternative regular expression. As seen below it can be almost 3x faster. For example, when parsing code, it is better to use <code style="font-family: Courier, monospace">/^for (.*);/gm</code>, rather than <code style="font-family: Courier, monospace">/(\nfor\s*(.*);)|(^for\s*(.*);)/g</code>.
<p style="text-align: center"><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-3.png"><img class="size-full wp-image-469  aligncenter" title="Differences between using the /m modifier against compound patterns" src="http://blog.tuenti.com/dev/files/2011/03/Graph-3.png" alt="" width="374" height="244" /></a></p>
<p style="text-align: center"><strong>Table 3</strong>. Differences between using the <code style="font-family: Courier, monospace">/m</code> modifier against compound patterns</p>
</li>
</ul>
<h2>Quantity modifiers</h2>
<ul>
<li>Using <code style="font-family: Courier, monospace">{}</code> notation when trying to find a repeated pattern can be marginally slower than using special characters, because the regexp parser engine must evaluate what is inside them. In general, you can substitute them by:
<ul>
<li> <code style="font-family: Courier, monospace">{0,}</code> with a .</li>
<li> <code style="font-family: Courier, monospace">{1,}</code> with a <code style="font-family: Courier, monospace">+</code>.</li>
<li> <code style="font-family: Courier, monospace">{0,1}</code> with a <code style="font-family: Courier, monospace">?</code>.</li>
<li> <code style="font-family: Courier, monospace">{x}</code> with the repeated pattern manually.</li>
<li> <code style="font-family: Courier, monospace">{1}</code> with nothing (this is the default for everything).</li>
</ul>
</li>
<li>The “<code style="font-family: Courier, monospace">+</code>” modifier is slightly slower than using the <code style="font-family: Courier, monospace">*</code>. It makes the regular expression a bit redundant as you have to repeat the pattern, but it gives you a tiny bit of a performance improvement . This gives the backtracking algorithm a fixed pattern that must be present in the string. Not all browsers implement this performance improvement.</li>
</ul>
<p>In the chart below we see the metrics comparing these:</p>
<p style="text-align: center"><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-3.png"></a><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-2.png"></a><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-4.png"><img class="size-full wp-image-467  aligncenter" title="Quantity modifiers" src="http://blog.tuenti.com/dev/files/2011/03/Graph-4.png" alt="" width="704" height="243" /></a></p>
<p style="text-align: center"><strong>Table 4</strong>. Quantity modifiers</p>
<table style="border-collapse: collapse;border-left: solid 1px #000;border-bottom: solid 1px #000;text-align: center" cellpadding="5px">
<tbody>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><strong>IE7</strong></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><strong>IE8</strong></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><strong>Firefox 3.6</strong></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><strong>Chrome</strong></td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">{0,}</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1850,7</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1536,2</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1575,3</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1407,2</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">*</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1817,6</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1653,4</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1490</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1389,1</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">{1,}</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">636,9</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">497,7</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">275,5</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">208,4</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">+</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">650,9</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">523,8</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">269</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">210,6</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">{0,1}</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1824,6</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1650,4</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1843,8</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1391,6</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">?</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1876,4</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1674,4</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1842,7</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">1389,6</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">{3}</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">559,8</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">404,6</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">346,5</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">79,5</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">Repeated</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">506,5</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">361,6</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">122,4</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">78,5</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">(?:text)</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">598,9</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">430,6</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">173,9</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">97,4</td>
</tr>
<tr>
<td style="border-right: solid 1px #000;border-top: solid 1px #000"><code style="font-family: Courier, monospace">text(?:text)*</code></td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">585,8</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">435,6</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">173,3</td>
<td style="border-right: solid 1px #000;border-top: solid 1px #000">97,2</td>
</tr>
</tbody>
</table>
<h2>Back-references</h2>
<p>Back-references are a method to use parts of the regexp matches in a different part of the regexp within the same regexp, or else within the replaced string. They can be used also in the callback method. JavaScript has a maximum number of 9 back-references, and they are stored in the same order as the opening parenthesis appear in the expression.</p>
<ul>
<li>Try to avoid using parentheses when it is not needed to create a backreference; and if needed, append  “<code style="font-family: Courier, monospace">?:</code>” modifier to the parentheses; this will mark the pattern as non capturing, preventing it to be stored in memory, and thus, making the regexp faster.</li>
<li>When using backreferences in the same regexp, you can do so by using the backslash followed by the number; but this process has a performance cost. Do not use it to match strings that can be done without them (e.g.: <code style="font-family: Courier, monospace">/"[^"]*"/g</code> instead of <code style="font-family: Courier, monospace">(")[^"]*(\1)/g</code>).</li>
<li>Backreferences can be used in the replace string in JavaScript by using the symbol <code style="font-family: Courier, monospace">$</code>, followed by the number. This notation allows making a lot of replacements:
<ul>
<li><code style="font-family: Courier, monospace">$$</code> returns the <code style="font-family: Courier, monospace">$</code> symbol.</li>
<li><code style="font-family: Courier, monospace">$n</code> returns the back-reference labeled with number “<code style="font-family: Courier, monospace">n</code>”.</li>
<li><code style="font-family: Courier, monospace">$`</code> returns everything before the matched string.</li>
<li><code style="font-family: Courier, monospace">$'</code> returns everything after the matched string.</li>
<li><code style="font-family: Courier, monospace">$&amp;</code> returns the entire matched string.</li>
</ul>
<p>For example, to delete quotes from strings, you can use the following: <code style="font-family: Courier, monospace">str.replace(/"([^"])*"/g, "$1");</code>. This will be a *lot* faster than doing a function where you make the replacement:</p>
<pre>str.replace(/"([^"])*"/g, function(match) {
    return match.slice(1,-1);
});</pre>
</li>
<li>There are other <code style="font-family: Courier, monospace">$</code> sequences not covered here as they are not fully supported in some browsers such as Opera or IE.</li>
</ul>
<p style="text-align: center"><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-3.png"></a><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-2.png"></a><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-4.png"></a><a href="http://blog.tuenti.com/dev/files/2011/03/Graph-5.png"><img class="size-full wp-image-468  aligncenter" title="Backreferences performance against function substitution" src="http://blog.tuenti.com/dev/files/2011/03/Graph-5.png" alt="" width="372" height="244" /></a></p>
<p style="text-align: center"><strong>Table 5</strong>. Backreferences performance against function substitution</p>
<p style="text-align: center">
<p style="text-align: left">Note: All the charts shown in this article were generated by executing the code 100,000 times, in a page containing a single test.</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tuenti.com/dev/tips-and-tricks-with-regular-expressions-in-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

