1
0
mirror of https://github.com/balkian/balkian.github.com.git synced 2024-12-26 02:08:13 +00:00
balkian.github.com/updating-eurolovemap.html

260 lines
15 KiB
HTML
Raw Normal View History

2015-01-22 22:05:35 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="viewport" content="width=device-width">
<!-- syntax highlighting CSS -->
2015-01-22 23:22:30 +00:00
<link rel="stylesheet" href="/theme/css/solarized.css">
2015-01-22 22:05:35 +00:00
<!--<link href="/css/bootstrap.css" rel="stylesheet">-->
<link rel="stylesheet" href="/theme/font-awesome/css/font-awesome.min.css">
<!--<link rel="stylesheet" href="/css/bootstrap-responsive.min.css">-->
<!-- Custom CSS -->
<link rel="stylesheet" media="only screen" href="/theme/css/main.css">
<link rel="stylesheet" media="only screen and (min-width: 0px) and (max-width: 599px)" href="/theme/css/main-xs.css">
<link rel="stylesheet" media="only screen and (min-width: 600px) and (max-width: 1199px)" href="/theme/css/main-medium.css">
<link rel="stylesheet" media="only screen and (min-width: 1200px)" href="/theme/css/main-desktop.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300|Comfortaa' rel='stylesheet' type='text/css'>
2015-12-08 03:37:10 +00:00
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//piwik.sinpapel.es/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 2]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//piwik.sinpapel.es/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
2015-01-22 22:05:35 +00:00
</head>
<body>
<div id="container" class="container">
<header id="header">
<div id="navbar" class="navbar navbar-inverse navbar-static-bottom">
<div class="container">
<div class="navbar-header">
<ul class="nav navbar-nav">
<li class="active" >
2015-12-07 20:57:42 +00:00
<a href="/"><i class="icon-home icon-large"></i></a>
</li>
2015-12-07 22:12:27 +00:00
<li >
<a href="/pages/about.html">About</a>
</li>
<li >
<a href="/pages/projects.html">Projects</a>
</li>
<li >
<a href="/pages/to-do.html">To-Do</a>
</li>
2015-12-07 20:57:42 +00:00
<li>
2015-12-08 00:06:02 +00:00
<a href="//jfernando.es" target="_blank">CV</a>
2015-12-07 20:57:42 +00:00
</li>
2015-01-22 22:05:35 +00:00
</ul>
2015-12-07 22:12:27 +00:00
</div>
2015-01-22 22:05:35 +00:00
</div>
</div>
</header>
<div id="contentwrapper">
<div id="sidebar" >
<div id="badge" class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper sticky">
<div class="front">
<!-- front content -->
<img id="avatar" width=100% src="/theme/img/me.png">
</div>
<div class="back">
<!-- back content -->
2015-12-07 20:57:42 +00:00
<img id="picture" width=100% src="/theme/img/me-bat.png">
2015-01-22 22:05:35 +00:00
</div>
</div>
</div>
<div class="entries">
<h1 class="title">Latest entries</h1>
<dl>
2015-03-11 01:55:29 +00:00
<dt><a href="/sharing-dotfiles.html">Sharing dotfiles</a></dt>
<a class="tag" href="/tag/github.html"><dd class="label label-default">github</dd></a>
<a class="tag" href="/tag/git.html"><dd class="label label-default">git</dd></a>
<a class="tag" href="/tag/dotfiles.html"><dd class="label label-default">dotfiles</dd></a>
2015-01-22 22:28:51 +00:00
<dt><a href="/zotero.html">Zotero</a></dt>
2015-01-22 22:05:35 +00:00
<a class="tag" href="/tag/zotero.html"><dd class="label label-default">zotero</dd></a>
<a class="tag" href="/tag/webdav.html"><dd class="label label-default">webdav</dd></a>
<a class="tag" href="/tag/nginx.html"><dd class="label label-default">nginx</dd></a>
<a class="tag" href="/tag/apache.html"><dd class="label label-default">apache</dd></a>
2015-01-22 22:28:51 +00:00
<dt><a href="/proxies-with-apache-and-python.html">Proxies with Apache and python</a></dt>
2015-01-22 22:05:35 +00:00
<a class="tag" href="/tag/python.html"><dd class="label label-default">python</dd></a>
<a class="tag" href="/tag/apache.html"><dd class="label label-default">apache</dd></a>
<a class="tag" href="/tag/proxy.html"><dd class="label label-default">proxy</dd></a>
<a class="tag" href="/tag/gunicorn.html"><dd class="label label-default">gunicorn</dd></a>
<a class="tag" href="/tag/uwsgi.html"><dd class="label label-default">uwsgi</dd></a>
2015-01-22 22:51:14 +00:00
<dt><a href="/publishing-in-pypi.html">Publishing in PyPi</a></dt>
<a class="tag" href="/tag/github.html"><dd class="label label-default">github</dd></a>
<a class="tag" href="/tag/python.html"><dd class="label label-default">python</dd></a>
<a class="tag" href="/tag/pypi.html"><dd class="label label-default">pypi</dd></a>
<dt><a href="/updating-eurolovemap.html">Updating EuroLoveMap</a></dt>
<a class="tag" href="/tag/javascript.html"><dd class="label label-default">javascript</dd></a>
<a class="tag" href="/tag/python.html"><dd class="label label-default">python</dd></a>
<a class="tag" href="/tag/heroku.html"><dd class="label label-default">heroku</dd></a>
2015-01-22 22:05:35 +00:00
</dl>
</div>
<!--Sidebar content-->
</div>
<div id="content">
<!--Body content-->
<div class="postnav">
<a href="remove-git-files-with-globbing.html"><span class="previouspost"><i class="icon-chevron-sign-left"></i> Remove git files with globbing</a></span>
<span class='nextpost'><a href="/publishing-in-pypi.html">Publishing in PyPi <i class="icon-chevron-sign-right"></i></span></a>
</div>
<div class="posthead">
<h2 class="title">Updating EuroLoveMap</h2>
<span class="meta date">2014-03-27</span>
<a class="tag" href="/tag/javascript.html"><span class="label label-default">javascript</span></a>
<a class="tag" href="/tag/python.html"><span class="label label-default">python</span></a>
<a class="tag" href="/tag/heroku.html"><span class="label label-default">heroku</span></a>
</div>
<div class="post">
<p>As part of the <a class="reference external" href="http://www.opener-project.org/2013/07/18/opener-hackathon-in-amsterdam/">OpeNER
hackathon</a>
we decided to build a prototype that would allow us to compare how
different countries feel about several topics. We used the OpeNER
pipeline to get the sentiment from a set of newspaper articles we
gathered from media in several languages. Then we aggregated those
articles by category and country (using the source of the article or the
language it was written in), obtaining the &quot;overall feeling&quot; of each
country about each topic. Then, we used some fancy JavaScript to make
sense out of the raw information.</p>
<p>It didn't go too bad, it turns out <a class="reference external" href="http://eurosentiment.eu/wp-content/uploads/2013/07/BOLv9qnCIAAJEek.jpg">we
won</a>.</p>
<p>Now, it was time for a face-lift. I used this opportunity to play with
new technologies and improve it:</p>
<ul class="simple">
<li>Using Flask, this time using python 3.3 and Bootstrap 3.0</li>
<li>Cool HTML5+JS cards (thanks to
<a class="reference external" href="http://pastetophone.com">pastetophone</a>)</li>
<li>Automatic generation of fake personal data to test the interface</li>
<li>Obfuscation of personal emails</li>
</ul>
2015-12-08 00:39:33 +00:00
<p>The result can be <a class="reference external" href="http://eurolovemap.herokuapp.com/">seen here</a>.</p>
2015-01-22 22:05:35 +00:00
<div class="section" id="publishing-a-python-3-app-on-heroku">
<h2>Publishing a Python 3 app on Heroku</h2>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>mkvirtualenv -p /usr/bin/python3.3 eurolovemap
</pre></div>
</td></tr></table><p>Since Heroku uses python 2.7 by default, we have to tell it which
version we want, although it supports python 3.4 as well. I couldn't get
python 3.4 working using the
<a class="reference external" href="https://launchpad.net/~fkrull/+archive/deadsnakes">deadsnakes</a> ppa,
so I used python 3.3 instead, which works fine but is not officially
supported. Just create a file named <em>runtime.txt</em> in your project root,
with the python version you want to use:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>python-3.3.1
</pre></div>
</td></tr></table><p>Don't forget to freeze your dependencies so Heroku can install them:
<tt class="docutils literal">bash pip freze &gt; requirements.txt</tt></p>
</div>
<div class="section" id="publishing-personal-emails">
<h2>Publishing personal emails</h2>
<p>There are really sophisticated and effective ways to obfuscate personal
emails so that spammers cannot easily grab yours. However, this time I
needed something really simple to hide our emails from the simplest form
of crawlers. Most of the team are in academia somehow, so in the end all
our emails are available in sites like Google Scholar. Anyway, nobody
likes getting spammed so I settled for a custom <a class="reference external" href="http://en.wikipedia.org/wiki/Caesar_cipher">Caesar
cipher</a>. Please, don't
use it for any serious application if you are concerned about being
spammed.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">def</span> <span class="nf">blur_email</span><span class="p">(</span><span class="n">email</span><span class="p">):</span>
<span class="k">return</span> <span class="s">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">+</span><span class="mi">5</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">email</span><span class="p">])</span>
</pre></div>
</td></tr></table><p>And this is the client side:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12</pre></div></td><td class="code"><div class="highlight"><pre><span class="nb">window</span><span class="p">.</span><span class="nx">onload</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span>
<span class="nx">elems</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByClassName</span><span class="p">(</span><span class="s1">&#39;profile-email&#39;</span><span class="p">);</span>
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">e</span> <span class="k">in</span> <span class="nx">elems</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">blur</span> <span class="o">=</span> <span class="nx">elems</span><span class="p">[</span><span class="nx">e</span><span class="p">].</span><span class="nx">innerHTML</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">email</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">;</span>
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">s</span> <span class="k">in</span> <span class="nx">blur</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">blur</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">s</span><span class="p">)</span>
<span class="nx">email</span> <span class="o">=</span> <span class="nx">email</span><span class="o">+</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">a</span><span class="o">-</span><span class="mi">5</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">elems</span><span class="p">[</span><span class="nx">e</span><span class="p">].</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">email</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</td></tr></table><p>Unfortunately, this approach does not hide your email from anyone using
<a class="reference external" href="http://phantomjs.org/">PhantomJS</a>,
<a class="reference external" href="http://zombie.labnotes.org/">ZombieJS</a> or similar. For that, other
approaches like generating a picture with the address would be
necessary. Nevertheless, it is overkill for a really simple ad-hoc
application with custom formatting and just a bunch of emails that would
easily be grabbed manually.</p>
</div>
<div class="section" id="generation-of-fake-data">
<h2>Generation of fake data</h2>
<p>To test the contact section of the site, I wanted to populate it with
fake data. <a class="reference external" href="https://github.com/joke2k/faker">Fake-Factory</a> is an
amazing library that can generate fake data of almost any kind: emails,
association names, acronyms... It even lets you localise the results
(get Spanish names, for instance) and generate factories for certain
classes (à la Django).</p>
<p>But I also wanted pictures, enter <a class="reference external" href="http://lorempixel.com/">Lorem
Pixel</a>. With its API you can generate
pictures of almost any size, for different topics (e.g. nightlife,
people) and with a custom text. You can even use an index, so it will
always show the same picture.</p>
<p>For instance, the picture below is served through Lorem Pixel.</p>
<div class="figure">
<img alt="This picture is generated with LoremIpsum" src="http://lorempixel.com/400/200/nightlife/" />
</div>
<p>By the way, if you only want cat pictures, take a look at
<a class="reference external" href="http://placekitten.com/">Placekitten</a>. And for NSFW text, there's
the <a class="reference external" href="http://slipsum.com/">Samuel L. Jackson Ipsum</a></p>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<footer role="contentinfo">
<div class="contact">
<p>
J. Fernando Sánchez Rada | balkian
</p>
</div>
<ul id="social">
<li><a href="http://github.com/balkian"><i class="icon-github"></i></a></li>
<li><a href="http://bitbucket.com/balkian"><i class="icon-bitbucket"></i></a></li>
<li><a href="http://twitter.com/balkian"><i class="icon-twitter"></i></a></li>
<li><a href="https://plus.google.com/u/0/111897020957944410316"><i class="icon-google-plus"></i></a></li>
<li><a href="http://linkedin.com/in/jfsanchezrada"><i class="icon-linkedin"></i></a></li>
<li><a href="http://facebook.com/balkian"><i class="icon-facebook-sign"></i></a></li>
</ul>
<p>
Creative Commons A-SA-NC
</p>
</footer>
</div>
<script src="/theme/js/jquery-2.0.2.min.js"></script>
<!--<script src="/js/bootstrap.min.js"></script>-->
</body>
</html>