<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Languages on Klaus Hebsgaard</title><link>https://khebbie.dk/tags/languages/</link><description>Recent content in Languages on Klaus Hebsgaard</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 27 Apr 2015 00:00:00 +0000</lastBuildDate><atom:link href="https://khebbie.dk/tags/languages/index.xml" rel="self" type="application/rss+xml"/><item><title>Optimistic locking in mongomapper and eventbus</title><link>https://khebbie.dk/posts/optimistic-locking-in-mongomapper-and-eventbus/</link><pubDate>Mon, 27 Apr 2015 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/optimistic-locking-in-mongomapper-and-eventbus/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1554224155-1696413565d3?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Database lock and key symbols representing concurrency control" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Apr 27, 2015&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;In Be My Eyes we use &lt;a href="https://github.com/mongomapper/mongomapper/"&gt;mongomapper&lt;/a&gt; and &lt;a href="https://github.com/kevinrutherford/event_bus"&gt;eventbus&lt;/a&gt;, both are very good tools that make my everyday life as a developer easier - except when it doesn&amp;rsquo;t.&lt;br&gt;
We had a problem where more than one helper is added to a call. This should not happen. We have a &lt;a href="https://github.com/bemyeyes/bemyeyes-server/blob/master/routes/requests.rb#L56"&gt;pretty simple if statement&lt;/a&gt; in our code. The thing is that many helpers were allowed through the if statement down to the &amp;ldquo;default&amp;rdquo; case, where only one should be allowed.&lt;br&gt;
I really lost a lot of hair trying to figure out why more than one helper could fall through. It really made no sense, since we assigned a helper and assigned &lt;em&gt;answered&lt;/em&gt; to be true. This should mean that the next time a helper tries to answer, she would be told that the call was already answered. But in many cases this did not happen.&lt;br&gt;
I searched the codebase through and through for many hours with two things in mind that could be wrong:&lt;/p&gt;</description></item><item><title>Optimistic locking in mongomapper and eventbus</title><link>https://khebbie.dk/posts-pages/optimistic-locking-in-mongomapper-and-eventbus/</link><pubDate>Mon, 27 Apr 2015 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/optimistic-locking-in-mongomapper-and-eventbus/</guid><description>&lt;h1 id="optimistic-locking-in-mongomapper-and-eventbus"&gt;Optimistic locking in mongomapper and eventbus&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Apr 27, 2015&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/optimistic-locking-in-mongomapper-and-eventbus/"&gt;https://khebbie.dk/optimistic-locking-in-mongomapper-and-eventbus/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;In Be My Eyes we use &lt;a href="https://github.com/mongomapper/mongomapper/"&gt;mongomapper&lt;/a&gt; and &lt;a href="https://github.com/kevinrutherford/event_bus"&gt;eventbus&lt;/a&gt;, both are very good tools that make my everyday life as a developer easier - except when it doesn&amp;rsquo;t.&lt;br&gt;
We had a problem where more than one helper is added to a call. This should not happen. We have a &lt;a href="https://github.com/bemyeyes/bemyeyes-server/blob/master/routes/requests.rb#L56"&gt;pretty simple if statement&lt;/a&gt; in our code. The thing is that many helpers were allowed through the if statement down to the &amp;ldquo;default&amp;rdquo; case, where only one should be allowed.&lt;br&gt;
I really lost a lot of hair trying to figure out why more than one helper could fall through. It really made no sense, since we assigned a helper and assigned &lt;em&gt;answered&lt;/em&gt; to be true. This should mean that the next time a helper tries to answer, she would be told that the call was already answered. But in many cases this did not happen.&lt;br&gt;
I searched the codebase through and through for many hours with two things in mind that could be wrong:&lt;/p&gt;</description></item><item><title>Map Reduce in MongoDb</title><link>https://khebbie.dk/posts/map-reduce-in-mongodb/</link><pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/map-reduce-in-mongodb/</guid><description>&lt;p&gt;&lt;em&gt;Published: Oct 31, 2014&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1551288049-bebda4e38f71?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Data visualization dashboard with analytics and distributed processing metrics" width="1600" height="1067" loading="lazy"&gt;
I had a problem where I needed to aggregate some documents in MongoDb. In Be My Eyes, we keep records of which version of ios the app is installed on. We do this to know which versions to support.
The natural solution would be to use the aggregation framework, however I had to do some string manipulation, since we only care about major versions at the moment.
So I went ahead and learned me som map - reduce. Map - reduce is a pretty simple concept, where you in the map step extract some data, and in the reduce step do some kind of manipulation of that data, to get some kind of values out of it.
The code I endend up with was:
&lt;pre&gt;&lt;code&gt;db.iphone_distributions.remove({})
db.devices.mapReduce(
function() {
var iosVersion = this.system_version.substring(10, 11);
emit(this.model + iosVersion, {
count: 1
});
},
function(key, values) {
var count = 0;
values.forEach(function(v) {
count += v['count'];;
});
return {
count: count
};
}, {
query: {},
out: &amp;quot;iphone_distributions&amp;quot;
}
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first function is the map function, where I extract the model (iPad, iPhone or iPod) and concat the major version number.&lt;br&gt;
The emit function is a MongoDb function, where the first argument is an id, which groups the values, and the second argument is the stuff you want to work on in the reduce function.&lt;/p&gt;</description></item><item><title>Map Reduce in MongoDb</title><link>https://khebbie.dk/posts/map-reduce-in-mongodb/</link><pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/map-reduce-in-mongodb/</guid><description>&lt;p&gt;&lt;em&gt;Published: Oct 31, 2014&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;img alt="Data visualization dashboard with analytics and distributed processing metrics" loading="lazy" src="https://images.unsplash.com/photo-1551288049-bebda4e38f71?auto=format&amp;fit=crop&amp;w=1600&amp;q=80"&gt;&lt;br&gt;
I had a problem where I needed to aggregate some documents in MongoDb. In Be My Eyes, we keep records of which version of ios the app is installed on. We do this to know which versions to support.&lt;br&gt;
The natural solution would be to use the aggregation framework, however I had to do some string manipulation, since we only care about major versions at the moment.&lt;br&gt;
So I went ahead and learned me som map - reduce. Map - reduce is a pretty simple concept, where you in the map step extract some data, and in the reduce step do some kind of manipulation of that data, to get some kind of values out of it.&lt;br&gt;
The code I endend up with was:&lt;/p&gt;</description></item><item><title>Update all records in mongodb</title><link>https://khebbie.dk/posts/update-all-records-in-mongodb/</link><pubDate>Thu, 15 May 2014 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/update-all-records-in-mongodb/</guid><description>&lt;p&gt;&lt;em&gt;Published: May 15, 2014&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;img alt="Database schema visualization representing MongoDB document collection and update operations" loading="lazy" src="https://images.unsplash.com/photo-1563013544-824ae1b704d3?auto=format&amp;fit=crop&amp;w=1600&amp;q=80"&gt;&lt;br&gt;
Recently we discovered a problem in &lt;a href="http://bemyeyes.org"&gt;Be My Eyes&lt;/a&gt; where an id was not unique.&lt;br&gt;
So we needed a quick fix to make all ids a forthrunning unique number before solving the problem in the code.&lt;/p&gt;
&lt;p&gt;On stackoverflow i found this question:&lt;br&gt;
&lt;a href="http://stackoverflow.com/questions/4146452/mongodb-what-is-the-fastest-way-to-update-all-records-in-a-collection"&gt;http://stackoverflow.com/questions/4146452/mongodb-what-is-the-fastest-way-to-update-all-records-in-a-collection&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And I modified the code to work for our schema.&lt;br&gt;
Please note: the code in the question was working, but slow for many millions records (a problem we don&amp;rsquo;t have yet ;-).&lt;/p&gt;</description></item><item><title>Update all records in mongodb</title><link>https://khebbie.dk/posts/update-all-records-in-mongodb/</link><pubDate>Thu, 15 May 2014 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/update-all-records-in-mongodb/</guid><description>&lt;p&gt;&lt;em&gt;Published: May 15, 2014&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1563013544-824ae1b704d3?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Database schema visualization representing MongoDB document collection and update operations" width="1600" height="1067" loading="lazy"&gt;
Recently we discovered a problem in [Be My Eyes](http://bemyeyes.org) where an id was not unique.
So we needed a quick fix to make all ids a forthrunning unique number before solving the problem in the code.
&lt;p&gt;On stackoverflow i found this question:&lt;br&gt;
&lt;a href="http://stackoverflow.com/questions/4146452/mongodb-what-is-the-fastest-way-to-update-all-records-in-a-collection"&gt;http://stackoverflow.com/questions/4146452/mongodb-what-is-the-fastest-way-to-update-all-records-in-a-collection&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And I modified the code to work for our schema.&lt;br&gt;
Please note: the code in the question was working, but slow for many millions records (a problem we don&amp;rsquo;t have yet ;-).&lt;/p&gt;</description></item><item><title>Trying Out Ruby on Rails on Windows Vista</title><link>https://khebbie.dk/posts-pages/trying-out-ruby-on-rails-on-windows-vista/</link><pubDate>Fri, 14 Nov 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/trying-out-ruby-on-rails-on-windows-vista/</guid><description>&lt;h1 id="trying-out-ruby-on-rails-on-windows-vista"&gt;Trying Out Ruby on Rails on Windows Vista&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Nov 14, 2008&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/trying-out-ruby-on-rails-on-windows-vista/"&gt;https://khebbie.dk/trying-out-ruby-on-rails-on-windows-vista/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;OK, so I am not excactly an early adopter, but I had some time and had to try it out.&lt;/p&gt;
&lt;p&gt;First I followed this guide:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://wiki.rubyonrails.org/rails/pages/RailsOnWindows"&gt;http://wiki.rubyonrails.org/rails/pages/RailsOnWindows&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then I tryed out the first chapter of &lt;a href="http://pragprog.com/titles/cerailn/rails-for-net-developers"&gt;“Rails for .Net developers”&lt;/a&gt; from pragmaticprogrammers.&lt;/p&gt;
&lt;p&gt;I must say that it really just works!&lt;/p&gt;
&lt;p&gt;Of course this is a really simple app, but scaffolding is a great thing for CRUD.&lt;/p&gt;</description></item><item><title>Trying Out Ruby on Rails on Windows Vista</title><link>https://khebbie.dk/posts/trying-out-ruby-on-rails-on-windows-vista/</link><pubDate>Fri, 14 Nov 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/trying-out-ruby-on-rails-on-windows-vista/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1461749280684-dccba630e2f6?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Ruby on Rails logo with vintage Windows interface" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Nov 14, 2008&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;OK, so I am not excactly an early adopter, but I had some time and had to try it out.&lt;/p&gt;
&lt;p&gt;First I followed this guide:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://wiki.rubyonrails.org/rails/pages/RailsOnWindows"&gt;http://wiki.rubyonrails.org/rails/pages/RailsOnWindows&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then I tryed out the first chapter of &lt;a href="http://pragprog.com/titles/cerailn/rails-for-net-developers"&gt;“Rails for .Net developers”&lt;/a&gt; from pragmaticprogrammers.&lt;/p&gt;
&lt;p&gt;I must say that it really just works!&lt;/p&gt;
&lt;p&gt;Of course this is a really simple app, but scaffolding is a great thing for CRUD.&lt;/p&gt;</description></item><item><title>About Ruby</title><link>https://khebbie.dk/posts/about-ruby/</link><pubDate>Tue, 23 Sep 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/about-ruby/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1560472354-b33ff0c44a43?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Red ruby gemstone representing the Ruby programming language" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Sep 23, 2008&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Since there has been so much hype about ruby, I thought I&amp;rsquo;d better take a look at it.&lt;/p&gt;
&lt;p&gt;I must say it looks really good. There&amp;rsquo;s two things i like about Ruby:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Duck-typing&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So many times I have been trying to make generic functionality for classes I didn&amp;rsquo;t own. So in C# I have no chance of implementing a common interface.&lt;/p&gt;</description></item><item><title>About Ruby</title><link>https://khebbie.dk/posts-pages/about-ruby/</link><pubDate>Tue, 23 Sep 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/about-ruby/</guid><description>&lt;h1 id="about-ruby"&gt;About Ruby&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Sep 23, 2008&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/about-ruby/"&gt;https://khebbie.dk/about-ruby/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Since there has been so much hype about ruby, I thought I&amp;rsquo;d better take a look at it.&lt;/p&gt;
&lt;p&gt;I must say it looks really good. There&amp;rsquo;s two things i like about Ruby:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Duck-typing&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So many times I have been trying to make generic functionality for classes I didn&amp;rsquo;t own. So in C# I have no chance of implementing a common interface.&lt;/p&gt;
&lt;p&gt;With Duck-typing that is now possible, since I find that common functionality and do Duck-typing.&lt;/p&gt;</description></item><item><title>Good cop - Bad cop</title><link>https://khebbie.dk/posts/good-cop-bad-cop/</link><pubDate>Thu, 31 Jan 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/good-cop-bad-cop/</guid><description>&lt;p&gt;&lt;em&gt;Published: Jan 31, 2008&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800" alt="Two diverging paths representing different approaches" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;There is a danish movie called &amp;ldquo;hannibal &amp;amp; Jerry&amp;rdquo;. It&amp;rsquo;s a story about a little boy who buys a dog - the dog later is discovered to be able to speak (it&amp;rsquo;s a kids movie).&lt;/p&gt;
&lt;p&gt;So the boy takes the dog for a walk and is having a conversation with his dog. During this conversation he walks out in front of a police car and is nearly run over.&lt;/p&gt;</description></item><item><title>Good cop - Bad cop</title><link>https://khebbie.dk/posts/good-cop-bad-cop/</link><pubDate>Thu, 31 Jan 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/good-cop-bad-cop/</guid><description>&lt;p&gt;&lt;em&gt;Published: Jan 31, 2008&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;img alt="Two diverging paths representing different approaches" loading="lazy" src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800"&gt;&lt;/p&gt;
&lt;p&gt;There is a danish movie called &amp;ldquo;hannibal &amp;amp; Jerry&amp;rdquo;. It&amp;rsquo;s a story about a little boy who buys a dog - the dog later is discovered to be able to speak (it&amp;rsquo;s a kids movie).&lt;/p&gt;
&lt;p&gt;So the boy takes the dog for a walk and is having a conversation with his dog. During this conversation he walks out in front of a police car and is nearly run over.&lt;/p&gt;</description></item></channel></rss>