<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description>Tech, Data, Progress</description><title>Ellimilial</title><generator>Tumblr (3.0; @ellimilial)</generator><link>http://ellimilial.com/</link><item><title>Python - weighted random selection</title><description>&lt;p&gt;&lt;script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"&gt;&lt;/script&gt;

I recently had a need for weighted random sampling, evaluated several approaches. This is just the eventual product, approaches stolen from several places, tested and implementing the same &lt;b&gt;list(item, weight)&lt;/b&gt; interface (albeit non consistent in return type).

&lt;/p&gt;&lt;h3&gt;Weighted sample - no replacement&lt;/h3&gt;&lt;br/&gt;&lt;code class="prettyprint lang-py"&gt;
def weightedSampleNoReplacement(items, n):&lt;br/&gt;
        """&lt;br/&gt;
        Selects without replacement n random elements from a list of (item, weight) tuples.&lt;br/&gt;
        """&lt;br/&gt;
        randomised = [(item[0], random.random() * item[1]) for item in items]&lt;br/&gt;
        sorted_ordered = sorted(randomised, key=lambda item: item[1])[-n:]&lt;br/&gt;
        return [item for item, _ in sorted_ordered]&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;&lt;h3&gt;Weighted sample - replacement&lt;/h3&gt;&lt;br/&gt;&lt;code class="prettyprint lang-py"&gt;
def weightedSampleReplacement(items, n):&lt;br/&gt;
    """&lt;br/&gt;
        Expects an iterable in form (item,weight).&lt;br/&gt;
        """&lt;br/&gt;
        total = float(sum(weight for item, weight in items))&lt;br/&gt;
        index = 0&lt;br/&gt;
        item, weight = items[0]&lt;br/&gt;
        while n:&lt;br/&gt;
                x = total * (1 - random.random() ** (1.0 / n))&lt;br/&gt;
                total -= x&lt;br/&gt;
                while x &amp;gt; weight:&lt;br/&gt;
                        x -= weight&lt;br/&gt;
                        index += 1&lt;br/&gt;
                        item, weight = items[index]&lt;br/&gt;
                weight -= x&lt;br/&gt;
                yield item&lt;br/&gt;
               n -= 1&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;&lt;h3&gt;Weighted sample - hybrid&lt;/h3&gt;&lt;br/&gt;
When you want to penalise the already selected items, this is the one I used for the project.
&lt;br/&gt;&lt;code class="prettyprint lang-py"&gt;
def weightedSampleHybridReplacement(items, n):&lt;br/&gt;
        """&lt;br/&gt;
        Expect an iterable in form (item,weight).&lt;br/&gt;
        Based on roulette-wheel implementation. A bit expensive.&lt;br/&gt;
        Returns a sample with replacement but each time&lt;br/&gt;
        an item is selected, it penalises it by cutting its weight by half.&lt;br/&gt;
        """&lt;br/&gt;
        total = float(sum(weight for item, weight in items))&lt;br/&gt;&lt;br/&gt;
        #Sort items to optimise traversal from 0.0,&lt;br/&gt;
        items = sorted(items, key=lambda item: item[1])&lt;br/&gt;&lt;br/&gt;
        index = 0&lt;br/&gt;
        item, weight = items[0]&lt;br/&gt;
        location = weight&lt;br/&gt;
        while n:&lt;br/&gt;
            target = random.random() * total&lt;br/&gt;
            while location 
                    index += 1&lt;br/&gt;
                    item, weight = items[index]&lt;br/&gt;
                    location += weight&lt;br/&gt;
                penalty = weight/2&lt;br/&gt;
                items[index] = (items[index][0], items[index][1]-penalty)&lt;br/&gt;
                total -= penalty&lt;br/&gt;&lt;br/&gt;
                yield item&lt;br/&gt;
                index = 0&lt;br/&gt;
                item, weight = items[0]&lt;br/&gt;
                location = weight&lt;br/&gt;
                n -= 1&lt;br/&gt;&lt;br/&gt;&lt;/code&gt;</description><link>http://ellimilial.com/post/75078925873</link><guid>http://ellimilial.com/post/75078925873</guid><pubDate>Thu, 30 Jan 2014 21:14:01 +0000</pubDate><category>python</category><category>random</category><category>sampling</category></item><item><title>Bootstrap 2 vs Bootstrap 3 differences</title><description>&lt;p&gt; There has been a recent rumbling coming from the real of Twitter Bootstrap, that is, Bootstrap 3 RC 1 has been released (and made default on &lt;a href="http://getbootstrap.com/" target="_blank"&gt;http://getbootstrap.com/&lt;/a&gt;). You can find some skeletal information about the changes &lt;a href="http://blog.getbootstrap.com/2013/07/27/bootstrap-3-rc1/" target="_blank"&gt;here&lt;/a&gt;, including a link to the actual pull request, which gives you a long (and boring) list of changes.&lt;/p&gt;
&lt;p&gt;There have been multiple improvements to the repository structure, inheritance and general maintainability of the code (glyphicons have been moved to a separate repository). The main changes from my own perspective (i.e. a person using it as a pluggable end product) are the following:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;-No longer need to include bootstrap-responsive and specifying viewport size as responsive design is now included by default (thankfully!).&lt;/li&gt;
&lt;li&gt;-The headers are much sleeker, smaller and not as much emphasised. This makes the page look much lighter but in some cases it might have gone too far (for example in modal header).&lt;/li&gt;
&lt;li&gt;-Buttons are now much more metro-styled, made slightly larger, no more puffiness and default color changed to dark-grey.&lt;/li&gt;
&lt;li&gt;-Buttons in the button group are no longer visibly separated until you stick your mouse pointer on top of them, when the currently selected button borders will show.&lt;/li&gt;
&lt;li&gt;-Navbar was made slightly larger.&lt;/li&gt;
&lt;li&gt;-The close icon inside alert blocks now matches the colour with the rest of the component instead of being light grey.&lt;/li&gt;
&lt;li&gt;-Modals no longer use drop down/go up animation when being made visible/hidden respectively.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt; In short, Bootstrap 3 comparing to make 2 screams &amp;lsquo;sleeker, let&amp;rsquo;s go metro&amp;rsquo;. IMHO it is the right direction, making it easier for the eye although I was fond of the sturdy, large headers and sections titles and very conservative use of space. Guess we&amp;rsquo;ll have to wait for RC 2 to see what else awaits us.&lt;/p&gt;</description><link>http://ellimilial.com/post/56778302978</link><guid>http://ellimilial.com/post/56778302978</guid><pubDate>Mon, 29 Jul 2013 13:32:17 +0100</pubDate><category>bootstrap</category><category>design</category></item><item><title>Visual Studio environment theme and settings</title><description>&lt;p&gt;&lt;br/&gt;&lt;br/&gt;Just a handy tip (and a recollection point for my glorious self ) how to make the Moloch of Visual Studio a bit lighter on the head.&lt;br/&gt;&lt;br/&gt;First you should install the right theme (&lt;a href="http://studiostyl.es/"&gt;http://studiostyl.es/&lt;/a&gt;) for your lovely VS.&lt;br/&gt;&lt;br/&gt;Configure your VAssistX (which you should really be using) Advanced-&amp;gt;Fonts and Colours to work well with the style and not make you lose your sight too much.&lt;br/&gt;&lt;br/&gt;Clean the unnecessary mess on the - screen fillers that you do not need from the bars - for me that means getting rid of anything apart from Standard bar unless when debugging but that&amp;rsquo;s a different story.&lt;br/&gt;&lt;br/&gt;Polish your right mouse button so it is always ready to click on a file tab and open it in the vertical splitter which can easily improve your efficiency by 10%.&lt;br/&gt;&lt;br/&gt;Hiding all screens - now this is something I need most of the time when trying to crack the mysteries of the lost memory allocation. A shortcut to close all the windows (and re-open them). As most of the time I work with VS 2008, this is the one that gave me the most pain. There are several ways I&amp;rsquo;ve read about, most of them centred around creating a macro and binding a key to it. I prefer something much much simpler. Associate the keys with Window.AutoHideAll and Window.ResetWindowLayout calls. It&amp;rsquo;s nothing close to any sophistication but, at least for me, it has always done the trick. To do that, go to Options-&amp;gt;Environment-&amp;gt;Keyboard, search for the options and fill &amp;lsquo;Press Shortcut Keys:&amp;rsquo; line edit. I usually assign Ctrl+d for closing and Ctrl+Shift+d to restore the layout.&lt;br/&gt;&lt;br/&gt;Simple, but I can&amp;rsquo;t work without those.&lt;/p&gt;</description><link>http://ellimilial.com/post/55010470469</link><guid>http://ellimilial.com/post/55010470469</guid><pubDate>Tue, 09 Jul 2013 18:10:04 +0100</pubDate><category>Visual Studio</category><category>C++</category><category>IDE</category></item><item><title>Scapegoat Picker</title><description>&lt;p&gt;At my glorious company we have recently encountered an issue with code reviewing. Sounds like an easy thing to do, right? Grab a coffee, sit down with someone else&amp;rsquo;s horrors and attempt to decipher what they meant. As we are so amazing and the errors like removing an item from current position in the iterator via an obfuscated call and then calling next on it are a rarity, it turned mostly into a competition to find a good place to put an assert or possibly point out an incoherent maximum line size. &lt;/p&gt; 

In any case, it turned out people are not as eager to take a bite at the responsibility of viewing code of their teammates as one could expect. At one point we were discussed using a web-based randomiser to choose the reviewer. As we looked at the front page of the results, I realised that none of them were quite what we needed.

&lt;ul&gt;&lt;li&gt;We required the randomiser to preserve list of names between daily scrums.&lt;/li&gt;
&lt;li&gt;Our randomiser should be a fast, one-click thing.&lt;/li&gt;
&lt;li&gt;We required some minor twists to the  randomisation like weighting senior people slightly more than complete juniors and  making sure that the last person chosen is safe for the next round. &lt;/li&gt;
&lt;li&gt;Most of the randomisers we found were either chesesy (in our view). We required something with, specific kind of humour applicable at our company.  Slightly darker yet kind in the end. Plus we really wanted the picture of our manager with flaming eyes!&lt;/li&gt;
&lt;/ul&gt;

Finally, I thought, a good reason to play with Flask instead of losing hours for Django configuration. My first real time with Javascript apart from Codacademy as well. Flask-bootstrap still gives me a headache when attempting to use reflective version, though it&amp;rsquo;s pretty neat apart from that. To be honest, Flask is the way to do simple sites. It&amp;rsquo;s dead-simple, minimalistic to the bone yet session and the rest pf API is simply functional. I mean, this could really end up in a single file if I was not so much into separating views, namespaces and common functionality.

Once the site was done, I thought about deploying it on Heroku, after some time struggling with bare AWS. Again, a charm, a couple of hours to fix my sillyness and it was there. All in all, &lt;a href="http://scapegoatpicker.com"&gt;ScapegoatPicker&lt;/a&gt; was a nice exercise for a weekend and some.</description><link>http://ellimilial.com/post/50261370365</link><guid>http://ellimilial.com/post/50261370365</guid><pubDate>Sun, 12 May 2013 16:07:44 +0100</pubDate><category>flask</category><category>bootstrap</category><category>javascript</category><category>sessions</category><category>heroku</category></item><item><title>SQL Server Management Studio - Value cannot be null bug</title><description>&lt;p&gt;I&amp;rsquo;m afraid this is not going to be a particularly interesting one - just an environmental glitch I spent a day trying to work out.   &lt;/p&gt;
&lt;p class="MsoNormal"&gt;I recently experienced an issue with SQL Server management studio (2008 R2) in which I was presented with the following error:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;Value cannot be null.&lt;/strong&gt;&lt;strong&gt;&lt;br/&gt;&lt;strong&gt;Parameter name: viewInfo (Microsoft.SqlServer.Management.SqlStudio.Explorer)&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This happened after a reinstallation of SQL Server and resulted in Object Explorer tree not being populated at all and rendered the Management Studio useless. Multiple threads relating to the issue mention that this might be due to TEMP &amp;amp; TMP folders being improperly configured or missing recently created folders. This was not the issue in my case and the next suggestion was to repair .Net 4.0 Framework. Again, no luck there, neither did help uninstalling / reinstalling of Management Studio.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Eventually, using Process Monitor, I realised that there were errors in machine.config xml configuration file (located under “%WinDir%\Microsoft.NET\Framework\&amp;lt;versionNo&amp;gt;\Config”) – half of the file was simply missing, making the DOM invalid. There is a skeleton machine.config.default file within the same directory with which I replaced the broken file to make the application work. There was another problem with Visual Studio not starting, which boiled down to, again, broken config XML (“\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.config), which I simply terminated correctly to get it going.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In case you are forced to reinstall SQL Server and stop being able to use SSMS, this is the bit that happened to me and I could not find it on any of the web forums.&lt;/p&gt;</description><link>http://ellimilial.com/post/46937077347</link><guid>http://ellimilial.com/post/46937077347</guid><pubDate>Tue, 02 Apr 2013 15:27:53 +0100</pubDate><category>SQLServer</category><category>SQL Server Management Studio</category></item><item><title>Auxilary XML - the simplest data persistence flexibility pattern</title><description>&lt;p&gt;There are various ways to spec out your requirements, model your domain and translate it to database design, encompassed in the lovely &lt;a href="http://en.wikipedia.org/wiki/Entity-relationship_diagram" target="_blank"&gt;ERD&lt;/a&gt; diagrams you can show off to everyone interested. Once it&amp;rsquo;s done, you&amp;rsquo;re ready to implement, test and deploy it. Once on site, it just works and you never have to think about it again, unless, you know, you live in a real world.&lt;/p&gt;

&lt;p&gt;When changing the code, adding new functionality, it might be the case that you need to update the data model. Making values obsolete is easy. Extending your schema by adding a single attribute - not so much. Sure, you can use &lt;a href="http://en.wikipedia.org/wiki/Extract,_transform,_load" target="_blank"&gt;ETL&lt;/a&gt; software and make update to your customers&amp;rsquo; persistence layer whenever you create a patch. It&amp;rsquo;s not always possible and it&amp;rsquo;s wasting time doing it over and over again at the smallest change. Django builders know the inconvenience of having to fiddle with their store when trying to add new attributes to their models once the application is deployed.&lt;/p&gt;
&lt;p&gt; This frustration can be avoided with an extremely simple trick. When designing your data store, make sure you you pay attention to the most likely culprits for future extension/change. Then, simply add an auxiliary text/XML attribute. When implementing small changes, you will have an extensible  store for whatever additional data you need, which you can then swiftly map to the new fields when required (if ever).&lt;/p&gt;</description><link>http://ellimilial.com/post/43719811369</link><guid>http://ellimilial.com/post/43719811369</guid><pubDate>Fri, 22 Feb 2013 13:02:49 +0000</pubDate><category>database design</category><category>data</category><category>flexibility</category><category>design pattern</category><category>software</category><category>django</category><category>data store</category><category>best practices</category></item><item><title>Hosting blog photos on Amazon S3</title><description>&lt;p&gt; I&amp;rsquo;m afraid I&amp;rsquo;m going to spoil it straight away: &lt;strong&gt;DON&amp;rsquo;T, JUST DON&amp;rsquo;T&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt; Only recently I advised my lass to try that. She wanted to have a good control over the collection and did not enjoy the size limitations that Blogger, Picassa and Flickr happen to have. Since it costs close to nothing to store the files, it made a total sense to go this route.&lt;/p&gt;
&lt;p&gt;It was all too easy to use one of the many software pieces that let you upload files straight to S3 and then modify the permissions to let everyone access the photos.&lt;/p&gt;
&lt;p&gt; The catch is, as those of you who, unlike myself, happen to have any idea about how the net works, the transfer. And it can scale up massively in the longer run. In this particular case, said blog had experienced traffic increase of about 44% in about 5 weeks. At the end of the month, the total transfer out of S3 amounted to 149 GB.&lt;/p&gt;
&lt;p&gt;So make sure you always do proper estimation beforehand.&lt;/p&gt;</description><link>http://ellimilial.com/post/42932346787</link><guid>http://ellimilial.com/post/42932346787</guid><pubDate>Tue, 12 Feb 2013 17:15:00 +0000</pubDate><category>S3</category><category>AWS</category><category>blog</category><category>image hosting</category><category>riennahera</category></item><item><title>Creating own personal tech blog</title><description>&lt;p&gt;Since the times of ancient Greece, &lt;em&gt;meta- &lt;/em&gt;prefix seems to be quite valuable. Therefore, in the spirit of making the Internet a much better (value added) place, I present my step-by-step guide to creating a personal tech oriented blog by someone who is supposed to be a software guy. Here goes:&lt;/p&gt;
&lt;p&gt;Lock down the important bits first and fast: what to write about (i.e. not abut stuff you like, but stuff that you might know a thing or two about), intended audience, taboos and how to &lt;a href="http://www.mattcutts.com/blog/disclaimer/" target="_blank"&gt;put a proper disclaimer&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Decide that since you&amp;rsquo;ve spent most of your time hacking in Java and C++, it is simply impossible that any scripting and/or declarative language can cause you any trouble at all. If you do multi threading, distributed, real-time systems, you will not be beaten by some silly silliness made of JavaScript mumbo-jambo and whatnot. You know that you can do this, and you simply won&amp;rsquo;t go for Blogger or Wordpress because you are TOO GOOD FOR THIS.&lt;/p&gt;
&lt;p&gt;Realise that you might have been just a tiny bit too cocky and those PHP tutorials from uni times are not really that useful anymore (even if you did remember quarter of them).&lt;/p&gt;
&lt;p&gt; Lucky enough, you&amp;rsquo;ve taken time to play with Python and &lt;a href="https://www.djangoproject.com/" target="_blank"&gt;Django&lt;/a&gt; and you know how to use &lt;a href="http://aws.amazon.com/" target="_blank"&gt;AWS&lt;/a&gt; to fire your own instance somewhere in the stratosphere. You even learned that there are &lt;a href="http://bitnami.org/stack/django" target="_blank"&gt;easier ways than manually prepare your distro from scratch&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt; You spend a couple of days trying out &lt;a href="http://stackoverflow.com/questions/82653/is-there-any-list-of-blog-engines-written-in-django" target="_blank"&gt;different Django blog engines&lt;/a&gt;, being slightly &lt;a href="https://www.djangopackages.com/grids/g/blogs/" target="_blank"&gt;spoilt for choice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You then realise that it is not at all cost-effective to host it on an Amazon instance. Digging deeper you find out that there are ways to &lt;a href="http://www.webmonkey.com/2013/01/host-your-static-website-on-amazon-s3-no-www-necessary/" target="_blank"&gt;host static files on S3&lt;/a&gt;. Thankfully, there is &lt;a href="https://github.com/koenbok/Cactus" target="_blank"&gt;Cactus&lt;/a&gt; that is the key to using Django like that.&lt;/p&gt;
&lt;p&gt;Come into conclusion (brain size!) that some content simply cannot be static, in which case you will need to pick up a third-party plugin. Be it &lt;a href="http://developers.facebook.com/docs/reference/plugins/comments/" target="_blank"&gt;Facebook comments&lt;/a&gt;, &lt;a href="http://www.intensedebate.com/" target="_blank"&gt;Disqus&lt;/a&gt;, &lt;a href="http://www.intensedebate.com/" target="_blank"&gt;IntenseDebate&lt;/a&gt; or &lt;a href="http://www.livefyre.com/"&gt;something along those lines&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Get back to the basics and realise that it makes little sense to dig that deep producing nothing up to that point. Since you are supposed to be a software developer there should be no shortcuts.&lt;/p&gt;
&lt;p&gt;After a day or two of deliberation, come to the conclusion that life is too short for that and there must be a way to do it faster and better.&lt;/p&gt;
&lt;p&gt;Ok, so you decide to go &lt;a href="http://www.tumblr.com" target="_blank"&gt;Tumblr&lt;/a&gt;, you might not feel hipster enough to use it but after a day you are ready to roll. If only you read about it somewhere beforehand&amp;hellip;&lt;/p&gt;</description><link>http://ellimilial.com/post/42878384564</link><guid>http://ellimilial.com/post/42878384564</guid><pubDate>Mon, 11 Feb 2013 23:48:00 +0000</pubDate><category>meta</category><category>tech blog</category><category>personal blog</category><category>django</category></item></channel></rss>
