Channels
Displaying page 2
Posted 5 days ago at MongoTips by John Nunemaker

A “massively multiplayer”, online crossword puzzle. Uses MongoDB’s geospatial indexing. The creators posted Building a Scrabble MMO in 48 hours if you are curious about how they did it. Crazy!

back to top
Posted 5 days ago at MongoTips by John Nunemaker

Kristina Chodorow is on a roll posting about Mongo’s assumptions, history, sharding, and now an introduction to mongosniff.

back to top
Posted 6 days ago at Ruby Inside

It's been a great year for Ruby on Android, but no one knows it. You can start writing Ruby apps for Android devices TODAY. You don't need to install any SDK, you don't need to install some giant Eclipse IDE, and you certainly don't need to write any Java.

Mike Leone

In Turn your Android Phone Into a Remote Spy Camera with Ruby in 15 Minutes, Mike Leone demonstrates how to use Ruby, Sinatra and Scripting Layer for Android (SL4A) to build and deploy a phone-hosted "spy camera" Web service.

SL4A is a system that allows you to run "scripting language" scripts and interactive interpreters on the Android platform. It currently supports JRuby, Python, Perl, Lua, JavaScript, BeanShell, and Tcl. Mike demonstrates how to set up a Sinatra project to use SL4A to run on an Android phone using JRuby. Upon receiving a request, Mike's app takes a picture using the phone's camera and serves it back over HTTP. He has also released the source code to a larger Ruby app called Broadcast that implements general Android device management functionality over HTTP.

Even if you don't want to build a "spy camera", Mike's walkthrough is a must-read if building Web services in Ruby that can run directly on the Android platform is of interest to you.

back to top
Posted 6 days ago at RubyLearning Blog

Programming Challenge for Newbies in Clojure and Python too?

RubyLearning has been conducting the monthly Ruby Programming Challenge for Newbies for over a year now and so far 12 challenges have been completed. The 13th challenge is in progress. All this was possible due to the extensive support we got from Rubyists across the world. Also, you all indicated that we continue with these challenges in the months to come.

Recently, my colleague Dhananjay Nene posted a Python based solution to the 13th Ruby challenge. While discussing the solution it struck me that it would help Clojure and Python Newbies, if we opened up these challenges in these languages too. Dhananjay and some of my Clojure colleagues are interested in evaluating the submitted solutions in Clojure and Python and maybe we could start the challenges from Oct. 2010.

Clojure, Python enthusiasts interested? What Do you Think? What is Your Opinion? Please share in the comments below.

Technorati Tags: Clojure, Python, RPCFN, Ruby Challenge, Ruby, Programming

back to top
Posted 6 days ago at Jay Fields' Thoughts

An introduction to clojure.test is easy, but it doesn't take long before you feel like you need a mocking framework. As far as I know, you have 3 options.

  1. Take a look at Midje. I haven't gone down this path, but it looks like the most mature option if you're looking for a sophisticated solution.

  2. Go simple. Let's take an example where you want to call a function that computes a value and sends a response to a gateway. Your first implementation looks like the code below. (destructuring explained)
    (defn withdraw [& {:keys [balance withdrawal account-number]}]
    (gateway/process {:balance (- balance withdrawal)
    :withdrawal withdrawal
    :account-number account-number}))
    No, it's not pure. That's not the point. Let's pretend that this impure function is the right design and focus on how we would test it.

    You can change the code a bit and pass in the gateway/process function as an argument. Once you've changed how the code works you can test it by passing identity as the function argument in your tests. The full example is below.
    (ns gateway)

    (defn process [m] (println m))

    (ns controller
    (:use clojure.test))

    (defn withdraw [f & {:keys [balance withdrawal account-number]}]
    (f {:balance (- balance withdrawal)
    :withdrawal withdrawal
    :account-number account-number}))

    (withdraw gateway/process :balance 100 :withdrawal 22 :account-number 4)
    ;; => {:balance 78, :withdrawal 22, :account-number 4}

    (deftest withdraw-test
    (is (= {:balance 78, :withdrawal 22, :account-number 4}
    (withdraw identity :balance 100 :withdrawal 22 :account-number 4))))

    (run-all-tests #"controller")
    If you run the previous example you will see the println output and the clojure.test output, verifying that our code is working as we expected. This simple solution of passing in your side effect function and using identity in your tests can often obviate any need for a mock.

  3. Solution 2 works well, but has the limitations that only one side-effecty function can be passed in and it's result must be used as the return value.

    Let's extend our example and say that we want to log a message if the withdrawal would cause insufficient funds. (Our gateway/process and log/write functions will simply println since this is only an example, but in production code their behavior would differ and both would be required)
    (ns gateway)

    (defn process [m] (println "gateway: " m))

    (ns log)

    (defn write [m] (println "log: " m))

    (ns controller
    (:use clojure.test))

    (defn withdraw [& {:keys [balance withdrawal account-number]}]
    (let [new-balance (- balance withdrawal)]
    (if (> 0 new-balance)
    (log/write "insufficient funds")
    (gateway/process {:balance new-balance
    :withdrawal withdrawal
    :account-number account-number}))))

    (withdraw :balance 100 :withdrawal 22 :account-number 4)
    ;; => gateway: {:balance 78, :withdrawal 22, :account-number 4}

    (withdraw :balance 100 :withdrawal 220 :account-number 4)
    ;; => log: insufficient funds
    Our new withdraw implementation calls two functions that have side effects. We could pass in both functions, but that solution doesn't seem to scale very well as the number of passed functions grows. Also, passing in multiple functions tends to clutter the signature and make it hard to remember what is the valid order for the arguments. Finally, if we need withdraw to always return a map showing the balance and withdrawal amount, there would be no easy solution for verifying the string sent to log/write.

    Given our implementation of withdraw, writing a test that verifies that gateway/process and log/write are called correctly looks like a job for a mock. However, thanks to Clojure's binding function, it's very easy to redefine both of those functions to capture values that can later be tested.

    The following code rebinds both gateway/process and log/write to partial functions that capture whatever is passed to them in an atom that can easily be verified directly in the test.
    (ns gateway)

    (defn process [m] (println "gateway: " m))

    (ns log)

    (defn write [m] (println "log: " m))

    (ns controller
    (:use clojure.test))

    (defn withdraw [& {:keys [balance withdrawal account-number]}]
    (let [new-balance (- balance withdrawal)]
    (if (> 0 new-balance)
    (log/write "insufficient funds")
    (gateway/process {:balance new-balance
    :withdrawal withdrawal
    :account-number account-number}))))

    (deftest withdraw-test
    (let [result (atom nil)]
    (binding [gateway/process (partial reset! result)]
    (withdraw :balance 100 :withdrawal 22 :account-number 4)
    (is (= {:balance 78, :withdrawal 22, :account-number 4} @result)))))

    (deftest withdraw-test
    (let [result (atom nil)]
    (binding [log/write (partial reset! result)]
    (withdraw :balance 100 :withdrawal 220 :account-number 4)
    (is (= "insufficient funds" @result)))))

    (run-all-tests #"controller")
In general I use option 2 when I can get away with it, and option 3 where necessary. Option 3 adds enough additional code that I'd probably look into Midje quickly if I found myself writing a more than a few tests that way. However, I generally go out of my way to design pure functions, and I don't find myself needing either of these techniques very often.

back to top
Posted 6 days ago at The GitHub Blog

While Twitter may see traffic spikes during Apple events, we see quite the opposite:

back to top

cached-commons: API for Common Javascripts and Stylesheets Cached and Optimized:

You probably already use Google’s AJAX Libraries as a CDN for your JavaScripts. But what do you do when Google is slow to add your favorite JavaScript library? Lance Pollard has created Cached Commons, an API for common Javascripts and stylesheets, cached and optimized on GitHub’s CDN.

Screenshot

Cached Commons lists dozens of scripts under categories like visualization, Ajax, syntax highlighting, HTML5, Flash, and testing, complete with links to project sources, demos, even documenation. Don’t see a script you want? Just fork the project and your script for everyone to share.

It looks like CSS libraries are on the TODO list, just like I had asked of Google in Episode 0.3.2!

[Source on GitHub] [Homepage]

back to top
Posted 7 days ago at Obie Fernandez

back to top

Mastering Node: Open source eBook for Node.js:

GitHub is for more than just code you know. It’s a great collaboration tool for hackers. Nathan, Chris, and I use GitHub as a big part of our workflow for our upcoming book.

TJ (do we really have to say his last name by now?), of Express and now Sencha wants you to Master Node.js by reading and hacking on his own community-driven ebook.

The book will walk you through Node step-by-step from installation to topics like EventEmitter:

Typically an object inherits from EventEmitter, however our small example below illustrates the api. First we create an emitter, after which we can define any number of callbacks using the emitter.on() method which accepts the name of the event, and arbitrary objects passed as data. When emitter.emit() is called we are only required to pass the event name, followed by any number of arguments, in this case the first and last name strings.

var EventEmitter = require('events').EventEmitter;

var emitter = new EventEmitter;

emitter.on('name', function(first, last){
    console.log(first + ', ' + last);
});

emitter.emit('name', 'tj', 'holowaychuk');
emitter.emit('name', 'simon', 'holowaychuk');

Go ahead, fork it, contribute, and add ePub support.

[Source on GitHub]

back to top

Episode 0.3.3 - Node Knockout:

Micheil and Wynn caught up with Gerad and Visnu from the Node Knockout to talk about the 48 hour Node.js development competition and its entries.

Download MP3

Items mentioned in the show:

  • Lone Star Ruby Conference - Texas’ regional Ruby conference in Austin
  • Mike Perham - The awesome Rubyist whose name gives Wynn fits
  • Node Knockout - The 48 hour Node.js coding competition
  • Rails Rumble - Ruby’s own 48 hour coding bash
  • Gerad - of Gerad & Visnu, the “data-y” and “product-y” guy
  • Visnu - the “developer-y” and “designer-y” guy
  • Fortnight Labs - the proper name for Gerad & Visnu, Inc.
  • List of great Node Knockout Judges
  • Joyent & Heroku are great places to host your Node.js apps.
  • Express High performance, high class web development for Node.js
  • Connect - high performance middleware framework for node featuring robust middleware for serving static files, advanced routing, cookie and session implementations, error handling and much more.
  • npm is a package manager for node. You can use it to install and publish your node programs. It manages dependencies and does other cool stuff.
  • Node Inspector is a web inspector based Node.js debugger
  • Go vote for your favorite entries!

back to top

dalli: High performance memcached client for Ruby:

After maintaining memcached-client for a couple of years, Mike Perham decided it was time to build a new Ruby client for Memcached from the ground up. Dalli aims to be a simpler, high performance client for Memcached the simple, ultra-fast in-memory key value store.

Among the improvements in Dalli:

  • Use of the faster binary Memcached protocol vs. the slower text protocol
  • Almost 500 fewer lines of Ruby
  • Monitoring hooks for tools like New Relic and Rack::Bug
  • SASL support for managed environments

To get started, just install the gem

sudo gem install dalli

You can then write to and read from your cache:

require 'dalli'
dc = Dalli::Client.new('localhost:11211')
dc.set('abc', 123)
value = dc.get('abc')

[Source on GitHub]

back to top
Favorite
Posted 8 days ago at Ruby5

Rails 3 has been released, memcached received a new Ruby library, and RubyDoc.info is in your RubyGems generating your YARD docs. Also, API versioning, extended transaction support, tutorials and more are on this episode of Ruby5.

Listen to this episode on Ruby5

This episode is sponsored by Screencasts.org

Screencasts.org is a new website that provides thoughtful, high-quality, in-depth video tutorials for popular programming languages and frameworks. They craft, edit, and cut the filler, so the time you dedicate to watching each screencast is time well spent.

For a limited time, Ruby5 listeners will receive a 20% discount on all screencasts. Check out the episode previews at http://screencasts.org/ruby5.


Rails 3.0 has been officially released
This Sunday, Rails 3.0 was officially released. If you've been listening to this podcast and somehow still don't know anything about it, then there's not much we can do for you, now. Read up on the release on the Rails weblog or .. just go back to doing whatever it was you were doing before you got here. Thanks. (And congratulations and thank you to the core team and all of the contributors!)

Dalli - memcached for Ruby
Mike Perham recently released Dalli, a new memcached library for Ruby, written in Ruby. This new code was sponsored by NorthScale to utilize the new binary protocols in newer versions of memcached. It's smaller, faster, and well tested than it's predecessors. It's also a drop-in replacement, in most cases.

Rails 3 Tutorial
Michael Hartl recently published a free online book which covers Rails 3 from the ground, up. In addition, it goes into detail about using git and GitHub, RSpec, and deployment with Heroku.

RubyDoc.info – A YARD Documentation Server
In the past few days, RDoc.info has been replaced with a new service by Loren Segal and Nick Plante called RubyDoc.info. This new service utilizes YARD to generate more aesthetically pleasing and useable documentation for all gems on RubyGems.org and any GitHub projects that you request.

af_after_transaction
If you're performing complex database logic in your application, then you (hopefully) know about transactions. And, if so, you know that there are occasions where you want to execute certain code if and when a transaction is successful. And, Michael Grosser decided to codify that sentiment with ar_after_transaction. It gives you an after_commit hook where you can write methods that should run only on complete, success.

Restful Route Versions
Rails does an exceptional job at generating APIs for your application. But, if you've ever built an API in the past, you know that the best practice is to version your API, to prevent future updates from breaking everyone's integrations. To that end, Hemant Kumar just released resftul route versions, a plugin which allows you to version features of your API from within your routes file.

Appreciate Rails 3 with Charity:Water
The Rails 3 team has put together a small charity drive to go along with the Rails 3 release. If you've got a few spare bucks and want to show your appreciation for their hard work, consider donating to the Rails 3 Charity:Water fund drive (or, maybe some other charity of your choice).

back to top
Posted 8 days ago at The GitHub Blog

GitHub launched with a simple pull request system on day one. You've used it to send 200 thousand pull requests in just over two years. Now we're taking it to the next level with a re-imagined design and a slew of new tools that streamline the process of discussing, reviewing, and managing changes.

As of today, pull requests are living discussions about the code you want merged. They're our take on code review and represent a big part of our vision for collaborative development.

Know What You're Sending

Sending a pull request is simple. Browse to the branch or commit with your recent work and hit the Pull Request button. You'll be greeted by a brand new screen:

Pull requests are now fully revision aware and take into account not only what you would like pulled but also where you intend those changes to be applied. They even work when sending from and to the same repository, making pull requests just as useful in scenarios where a team is working out of a single shared repository as they are in the fork + pull model.

When you send a pull request, you're starting a discussion.

Some back and forth is typically required before a pull request is accepted. The maintainer needs clarification, or the change doesn't conform to the project's coding conventions, or maybe someone was able to take a concept 80% to completion and needs help working through the last bits.

The discussion view makes pull requests the best place to have these types of conversations. Anywhere. Here's why:

The discussion view presents all pull request related activity as it unfolds: comment on the pull request itself, push follow up commits, or leave commit notes - it's all interleaved into the discussion view as it happens.

Revision Aware

The discussion view is perfect for watching changes evolve over time, but it's equally important to know exactly what modifications would be made if the changes were accepted right now. The Commits and Files Changed tabs are quickly accessible and show the cumulative progress of the pull request:

Look familiar? It's a miniature compare view.

Visible, Linkable, Archived

Anyone with access can browse a repository's pull requests by visiting the repository's Network ⇢ Pull Requests page.

Every pull request has a URL so you can link to them. They're archived forever and indexed by search engines.

An Issue at heart

Pull requests are tightly integrated into GitHub Issues. When you see an [^] icon in the issues list, it means there's a pull request attached.

Don't use Issues? No problem. You still get awesome pull requests.

Pull Request Dashboard

The pull request dashboard gives a high level view of all pull requests across every repository you or your organization is involved with.

What are you waiting for?

Pull requests sent prior to today are not automatically imported into the new system. If you have outstanding requests, use them as an opportunity to try out revision aware pull requests today!

back to top
Posted 8 days ago at RubyLearning Blog

Ruby Programming Challenge For Newbies

RPCFN: Economics 101 (#13)

By Dr. Bruce Scharlau

About Dr. Bruce Scharlau

Dr. Bruce Scharlau In Dr. Bruce’s own words: “I’ve been using and teaching Ruby since trying out the cookbook example in the summer of 2006. As soon as I saw how much easier it all was with Ruby and Rails, I was hooked. I now try to do as much with Ruby as I can with my teaching and own work. It’s a joy to code with Ruby compared to using other languages, which don’t seem as intuitive by comparison. When I’m not busy working, then I try to spend time with the family, or get out sailing.”

Dr. Bruce has this to say about the challenge:

The challenge is useful for newbies as a way to extend their skills in a useful manner. They will learn how they solved the problem, and also gain from seeing how others solved the problem too. We all start from different places when we solve problems, so the ‘obvious’ solution to you, might not occur to someone else who has a different experience of Ruby. This is why it’s good to share examples and code together when possible too.

Prizes

  • The participant with the best Ruby solution (if there is a tie between answers, then the one who posted first will be the winner) will be awarded any one of PeepCode’s Ruby on Rails screencasts.
  • From the remaining working Ruby solutions, three participants would be selected randomly and each one would be awarded any one of Pragmatic’s The Ruby Object Model and Metaprogramming screencasts.

The four persons who win, can’t win again in the next immediate challenge but can still participate.

The Ruby Challenge

RPCFN

The Challenge

As a developer it helps to be able to understand a client’s perspective and to build suitable applications to help them in their field. This means knowing a bit about the world. We’ll help this background knowledge by doing looking at some economic data, and also testing our XML parsing skills.

The file cia-1996.xml is the data from the CIA World Factbook of 1996 in XML format. It has details about 260 countries across five continents. Your challenge, should you choose to accept it, is to uncover the following details buried within this file:

  1. What is the population of the country with the most people? Yes, we know it’s China, but just how many people lived there in 1996?
  2. What are the five countries with the highest inflation rates, and what were those rates in 1996?
  3. What are the six continents in the file and which countries belong to which continent? Can you also produce them in alphabetical order?

Once you’ve worked out how to do part (2), then you can do anything with this file; all you need is a bit of time. Knowing how to do (2) you could then do (3) without too much effort.

You can use any XML library. I used REXML as it’s already there if you have Ruby installed; so don’t need to worry about any gem installs. You may also want to look at how REXML uses XPath.

Submit your solution of your code, which includes a test file that answers the three questions.

How to Enter the Challenge

Read the Challenge Rules. By participating in this challenge, you agree to be bound by these Challenge Rules. It’s free and registration is optional. You can enter the challenge just by posting the following as a comment to this blog post:

  1. Your name:
  2. Country of Residence:
  3. GIST URL of your Solution (i.e. Ruby code) with explanation and / or test cases:
  4. Code works with Ruby 1.8 / 1.9 / Both:
  5. Email address (will not be published):
  6. Brief description of what you do (will not be published):

Note:

  • As soon as we receive your GIST URL, we will fork your submission. This means that your solution is frozen and accepted. Please be sure that is the solution you want, as it is now recorded in time and is the version that will be evaluated.
  • All solutions posted would be hidden to allow participants to come up with their own solutions.
  • You should post your entries before midnight of 27th Sept. 2010 (Indian Standard Time). No new solutions will be accepted from 28th Sept. onwards.
  • On 28th Sept. 2010 all the solutions will be thrown open for everyone to see and comment upon.
  • The winning entries will be announced on this blog before 30th Sept. 2010. The winners will be sent their prizes by email.

More details on the RPCFN?

Please refer to the RPCFN FAQ for answers to the following questions:

Donations

RPCFN is entirely financed by RubyLearning and sometimes sponsors, so if you enjoy solving Ruby problems and would like to give something back by helping with the running costs then any donations are gratefully received.

Click here to lend your support to: Support RubyLearning With Some Love and make a donation at www.pledgie.com !

Acknowledgements

Special thanks to:

  • Dr. Bruce Scharlau.
  • GitHub, for giving us access to a private repository on GitHub to store all the submitted solutions.
  • The RubyLearning team.

Questions?

Contact Satish Talim at satish [dot] talim [at] gmail.com OR if you have any doubts / questions about the challenge (the current problem statement), please post them as comments to this post and the author will reply asap.

The Participants

There are two categories of participants. Some are vying for the prizes and some are participating for the fun of it.

In the competition

Just for Fun

Previous Challenge

RPCFN: Cycle Tracks (#12) by David Griffiths.

Note: All the previous challenges, sponsors and winners can be seen on the Ruby Programming Challenge for Newbies page.

Update

  • The (#14) challenge by Joseph Wilk, U.K. is scheduled for Oct. 2010.

Technorati Tags: Ruby, The Ruby Programming Language, Ruby Programming Challenge For Newbies, Programming, RPCFN, Dr. Bruce Scharlau

back to top
Posted 8 days ago at Jay Fields' Thoughts

Clojure sets and maps are functions.

Since they are functions, you don't need functions to get values out of them. You can use the map or set as the example below shows.

(#{1 2} 1)
> 1

({:a 2 :b 3} :a)
> 2
That's nice, but it's not exactly game changing. However, when you use sets or maps with high order functions you can get a lot of power with a little code.

For example, the following code removes all of the elements of a vector if the element is also in the set.
(def banned #{"Steve" "Michael"})
(def guest-list ["Brian" "Josh" "Steve"])

(remove banned guest-list)
> ("Brian" "Josh")
I'm a big fan of using sets in the way described above, but I don't often find myself using maps in the same way. The following code works, but I rarely use maps as predicates.
(def banned {"Steve" [] "Michael" []})
(def guest-list ["Brian" "Josh" "Steve"])
> ("Brian" "Josh")
However, yesterday I needed to compare two maps and get the list of ids in the second map where the quantities didn't match the quantities in the first map. I started by using filter and defining a function that checks if the quantities are not equal. The following code shows solving the problem with that approach.
; key/value pairs representing order-id and order-quantity
(def map1 {1 44 2 33})
(def map2 {1 55 2 33})

(defn not=quantities [[id qty]] (not= (map1 id) qty))
(keys (filter not=quantities map2))
> (1)
However, since you can use maps as filter functions you can also solve the problem by merging the maps with not= and filtering by the result. The following code shows an example of merging and using the result as the predicate.
; key/value pairs representing order-id and order-quantity
(def map1 {1 44 2 33})
(def map2 {1 55 2 33})

(filter (merge-with not= map1 map2) (keys map2))
> (1)
I don't often find myself using maps as predicates, but in certain cases it's exactly what I need.

back to top