Showing posts with label clojure. Show all posts
Showing posts with label clojure. Show all posts

Eon: A Clojure Basics Quiz

As part of an effort to avoid creating yet another blog engine, I started working on something completely different:  a quiz/game called Eon.


Eon is a simple quiz designed to test basic Clojure evaluation comprehension.  At the moment, it consists of 7 levels of 10 questions.  Each question presents you with a Clojure form.  You are given an answer box to submit your answer.  An answer is initially worth 100 points.  Entering an incorrect answer drops the possible point value by 10, so a perfect score at this point is 7000 (7 levels x 10 questions per level x 100 points).

I started writing Eon for a few reasons:

  • I wanted to get out of a rut where every personal project started to look like a blog engine.
  • I wanted to learn ClojureScript.  There are lots of interesting things happening in ClojureScript lately, and I wanted to get my feet wet.  Eon is written in ClojureScript with Reagent handling the UI.
  • Working on this helped solidify my understanding of simple Clojure evaluation.
Eon is very basic, but I hope that other Clojure beginners out there find it useful.  There are levels/questions that I'd like to add, but due to some limitations in the way I'm handling answers, I'm not sure I'll get to them.  Plus, I'm already itching to create something more substantial using ClojureScript--it's a lot of fun to work with.

If you have questions, comments, or find bugs/see something wrong, please let me know via email or on Twitter.

2014 Clojure Cup Ideas

Clojure Cup 2014 is just around the corner.  If you're excited about entering but don't have a clue what to make, maybe this post will help you.  Below is a small collection of web app ideas I've had recently that I probably won't get to.  I jot these things down whenever they pop into my head regardless of how ridiculous or difficult they seem.  Most of them sit in a text file doing nothing.  Maybe some of them can help someone directly or spark other ideas.  I think the core functionality for most of these could be pulled off in a 48-hour period.  Some may already exist, but attempting to build them might yield useful knowledge, or even win you the cup!

Storytellers

Connect with up to 3 others and collaboratively build a story by taking turns writing in units of paragraph, sentence, or word.  Once the story is finished, publish it to a reading section of the site for others to read.

Version Check

Upload a project.clj file to this web service and you'll be told which libraries you're using that have newer versions.

Destination Helper

Specify a travel destination + dates of travel and get back details about the destination for that time period:  weather, events, the most recent highly-rated restaurant reviews, etc.

Web-based Podcatcher

Log in, subscribe to feeds and listen without the need for a dedicated app.   Is it possible to supplant native apps with a web offering?

Due Today

Yes, this is another TODO list, but it's the only one I've been able to use consistently.  You're only allowed to add items to today's date.  If you don't complete an item, you have the option to move it to today from an earlier date.  The focus is on entering actionable steps that can be achieved today.

Single Subject Search Engine

Indexing the entire internet is impossible for a sole developer with a VPS.  Would it be possible to index a niche subject?  What advantages would you have over a general search engine?

Source Code Recommender

You've learned the basics of a new language.  You've solved some puzzles.  You're still not comfortable writing in the language.  Where do you go to see how advanced users of the language use it?  With Source Code Recommender, reviewers can submit code repos that they think exemplify the best practice patterns and idioms of a language and rate/discuss/review/educate based on the source.

Goodreads Reviewer Suggester

Given your account, this site uses the Goodreads API to find other users that ranked books similarly to you.   Receive suggestions for users to follow, books to read, or discussions to take part in.

Newsletter Aggregator

Email newsletters have taken off in popularity.  This service aggregates all of your newsletters in one place.  Sign up for an account and the service will supply you with an email address to use when signing up for newsletters.  The aggregator then provides you with an interface for reading/managing/tagging/searching your newsletters.

Monument

Memories for locations.  Search for a location on a map and add a memory (anonymously if you want) about that particular place/establishment/location.  Flaco's Tacos, I still miss you.

IT Interview Quiz

A site that quizzes you on those silly puzzles (and/or useful CS theory) that some companies use to filter the hiring pool.  Submit answers to quizzes (anonymously if you want) and have them reviewed/rated by others and learn from other member's submissions.  This is kind of an Exercism.io for theory.

If one of these appeal to you, take it and run with it.  Good luck and see you at Clojure Cup!

P.S.  If you use one of these and anything good comes out of it, you should buy me a burrito!

P.P.S.  If you're interested in making one of these outside of Clojure Cup and want a collaborator, let me know via email or on Twitter.

Adventures in Luminus

A few weeks ago, I started to take a tour of some of the Clojure web frameworks. To get to know them  better, I'm going to pick a few frameworks and build a simple database-backed "Choose Your Own Adventure"-like story engine .   I like this idea because the project is easy to understand and has a simple architecture but is complex enough that I'll need to understand how each framework works.  I also thought the end product might be fun.

The first web framework on the tour is Luminus, a framework spearheaded by Dmitri Sotnikov (aka Yogthos).   My initial project, called Adventure, can be found here, with the source hosted on GitHub.   I also seeded the site with its first story titled "Cube Dweller".

Luminus refers to itself as a "micro framework".   It is a Leiningen template that ties several open-source Clojure libraries together and provides the  starting scaffolding for a project's initial code base.   Luminus sits on top of lib-noir, but other libraries can be removed or swapped out with whatever you prefer.  Luminus embraces flexibility, suggesting ways of doing things, but allowing you to change just about anything.

I found the scaffolding Luminus creates to be similar to what I had done in previous projects.   The code layout is easy to understand, using common organization idioms.   A starter project contains Bootstrap for the initial look and feel, as well as example routes and templates for a Home and About page so you can see how it all works together.  Luminius also has support for generating scaffolding for specific databases, Clojurescript support and a few other features using profile hints.

Luminus also includes the recently-released Selmer templating library (also by Sotnikov).  If you are familiar with Django, you will be right at home with Selmer since it is modeled after Django's template syntax.   Selmer includes many of Django's tags and filters and makes adding new ones easy.   It also includes some of the more advanced features like template inheritance and dev-time reloading.    Selmer was great for me--someone familiar with Django who wanted to ease into Clojure web development.   It's also fast and decently documented.

Although my project needs were modest, I found Luminus to be a big help.   It let me quickly get in and move forward with my project rather than deal with starting-project ceremony.   I feel like I have control of my project and can change whatever I want.  I'm also interested in the support for introducing Clojurescript to Adventure.   At the level I'm at with Clojure web development,  I think starting with Luminus was a great decision.

So, go forth and Adventure with Luminus!

Adding Markdown support to Clabango templates

If you're coming to Clojure web development from Django, you might be interested in Clabango by Dan Larkin.  Clabango is a Clojure templating library modeled after Django's.  It supports several of the Django filters and tags (including the can't-live-without include, block, if, for and extends), but also allows you to extend them by writing your own.

On my current side project, I wanted to add support for writing text entries in markdown and have the templates output the text in html.  Thanks to markdown-clj by Dmitri Sotnikov, this was very simple.

In a namespace for my project's filters, I required markdown-clj, then passed Clabango's body argument to md-to-html-string:

(ns logbook.filters
  (:require [clabango.filters :as filter]
            [markdown.core :as md]))

(filter/deftemplatefilter "markdown" [node body args]
  (when body (md/md-to-html-string body)))

Note that the return value of the deftemplatefilter is a string, rather than the map that Clabango's current examples demonstrate. There is a difference between the source on Github and the binary on Clojars.

Now wherever I need to convert text from markdown to html in a Clabango template, I pass the text to the new markdown filter:
    {% for entry in entries %}
  • {{ entry.title|markdown }}
  • {% endfor %}
I was really impressed by how simple and easy this was.  Thanks guys!

Update:  Dmitri has released Selmer.

(grok 'clojure)

Learn at least one new language every year.  Different languages solve the same problems in different ways.  By learning several different approaches, you can help broaden your thinking and avoid getting stuck in a rut.
- The Pragmatic Programmer

Was that really written almost 15 years ago?  Time flies.

It's been a while since I learned a new language.  I started messing around with Clojure, and it's been a blast.  It is the most fun I've had programming since the first time I fired up Squeak and started poking around.

I can't seem to break out of the "every project looks like a blog engine" mold, so I started another web app called Logbook (source).  Inspired by this post by Austin Kleon,  it'll be a very simple way of logging what you did for the day.   I started keeping a personal logbook using text files a year ago, and really like it.

Logbook uses Clojure, Compojure, and Clabango (I gotta have my templates).

My Clojure Path

The following has helped me get to where I am so far:

So far I'm finding Clojure challenging but fun.   It's a welcome punch in the brain if you feel you've been spinning your wheels.