Skip to content

Commit

Permalink
signature tag used
Browse files Browse the repository at this point in the history
  • Loading branch information
paulosuzart committed Apr 13, 2012
1 parent d28f7f6 commit d300817
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 8 deletions.
22 changes: 22 additions & 0 deletions plugins/signature.rb
@@ -0,0 +1,22 @@
# A Liquid tag for signatures
# by: Paulo Suzart
# Source https://gist.github.com/2372727
#
# Example usage: {% signature paulosuzart %}
module Jekyll

class SignatureTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text.strip!
end

def render(context)
<<-HTML
<p>Don't forget to visit the <a href="/about">about</a> page. And follow me on Twitter: <a href="http://twitter.com/#{@text}">@#{@text}</a>.</p>
HTML
end
end
end

Liquid::Template.register_tag('signature', Jekyll::SignatureTag)
Expand Up @@ -52,4 +52,6 @@ Note that if the param named `requestTimeParam` is not present or carries a inva

Although easy to build and extract params from query string and requested path, it is not a Finagle strength. It is kinda limited. A better abstraction is offered by [Unfiltered](https://github.com/unfiltered/unfiltered)(another [@n8han's](http://twitter.com/n8han) great job).

Hope you enjoy it.
Hope you enjoy it.

{% signature paulosuzart %}
Expand Up @@ -10,4 +10,4 @@ Hi, this is another blog of mine. Yap, I have a - mostly in portuguese - wordpre

The main reason to starting blogging directly on my Github is to keep the subjects even more focused on projects committed here, and share some experiences with some libs also committed here.

Hope you enjoy the content. Please don't forget to visit the [about](/about) page. And follow me at Twitter: [@paulosuzart](http://twitter.com/paulosuzart)
{% signature paulosuzart %}
Expand Up @@ -70,4 +70,4 @@ Now your code is a bit more resilient to database changes with this thing layer

Korma can do a lot of things to make your life easier, as the abililty to compose queries, and performs really nice. Think I finally found THE framework for relational data access in clojure.

Don't forget to visit the [about](/about) page. And follow me on Twitter: [@paulosuzart](http://twitter.com/paulosuzart)
{% signature paulosuzart %}
Expand Up @@ -44,4 +44,4 @@ It is simple and is helping a lot. Another good thing I started to do is to writ

I'm using [clj-redis](https://github.com/mmcgrana/clj-redis/) interact with redis.

Hope it may be useful for you. Don't forget to visit the [about](/about) page. And follow me on Twitter: [@paulosuzart](http://twitter.com/paulosuzart)
{% signature paulosuzart %}
Expand Up @@ -35,4 +35,4 @@ An instance of this process would be:

It is the form I'm using as doc strings in a namespace. It looks great with [Marginalia](http://www.fogus.me/fun/marginalia/).

Hope it may be useful for you. Don't forget to visit the [about](/about) page. And follow me on Twitter: [@paulosuzart](http://twitter.com/paulosuzart)
{% signature paulosuzart %}
Expand Up @@ -76,4 +76,6 @@ If take a closer look you may notice a function call to `(env "AWS_KEYID")`. It

You can extend the macro to have any admin task you may need. Note that the `*sdbconf*` will become available, so you can call rummage directly without having to configure all again.

That is it. Clojure is smart!
That is it. Clojure is smart!

{% signature paulosuzart %}
Expand Up @@ -101,4 +101,4 @@ lein run

And start having fun with enlive and noir. This project template may be evolved to have [korma](http://sqlkorma.com/) or any persistence framework.

Hope it may be useful for you. Don't forget to visit the [about](/about) page. And follow me on Twitter: [@paulosuzart](http://twitter.com/paulosuzart)
{% signature paulosuzart %}
Expand Up @@ -43,7 +43,9 @@ Just to play around, try:

It returns from 0 to 10, being a finite lazy sequence just like the source data set. One can use `take-while` to limit the results of a lazy-seq. You can compute really big sets using the laziness approach.

Hope it may be useful. Don't forget to visit the [about](/about) page. And follow me on Twitter: [@paulosuzart](http://twitter.com/paulosuzart).
Hope it may be useful.

{% signature paulosuzart %}

**Update - Apr 7 2012**: *Although an interesting and working solution, this code is not that functional. First of all, because it does I/O, but there is something that could be fixed to have a better "purity". `map` or `pmap` produce new sequences. Sequences full of `nils` in this case, because `persist` returns `nil`. The only advantage is the use of `pmap`, to run it in parallel, but it is still weird to have resulting seqs of `nils`.*

Expand Down
35 changes: 35 additions & 0 deletions source/_posts/2012-04-11-sorting-with-clojure-comparator.markdown
@@ -0,0 +1,35 @@
---
layout: post
title: "sorting with clojure comparator"
date: 2012-04-11 22:51
comments: true
categories: clojure elementary
---

This is a quick post to show an example of [clojure](http://clojure.org) `comparator` for sorting a list with `sort`.

At work a friend wrote dozen lines of java to sort a list of characters that represents t-shirt sizes. The sizes are: pp, p, m, mm, g, gg, a, aa. Whre pp is super small, p small, m medium, etc.

Some shees have all the sizes available, some not. So imagine a shirt with just g, a, gg, p sizes availabe. The screen should show: p, g, gg, a.

He requested me to do a clojure version of it. Here it goes.

{% gist 2351780 %}

The first useful function is [`map-indexed`](http://clojuredocs.org/clojure_core/clojure.core/map-indexed). Since the order of sizes is not natural, we associate numbers to them given we know the size order. So `sizes` becomes `{:a 6, :gg 5, :g 4, :pp 0, :m 2, :mm 3, :aa 7, :p 1}`.

Then I used a [`comparator`](http://clojuredocs.org/clojure_core/clojure.core/comparator). It produces a `java.util.Comparator` for the given function. In this case the comparison of the map values for each key.

To finish that, the [`sort`](http://clojuredocs.org/clojure_core/clojure.core/sort) function. It takes a given product sizes list and sorts then. So `'(p, g, gg, aa)` becomes `(p g gg a)`.

It is even silly for a blog post but what if I can convince him to replace the java methods/utils/whatever methods for a [`gen-class`](http://clojuredocs.org/clojure_core/clojure.core/gen-class) of it? Packing compiled clojure code and using them for utility functions and small piece of your application can be a good way to get used to the language and confidence to start a full application in it.

Actually to let this code resuable, one can take the list of sizes instead of hard coding it. But this is an exercise for you.

{% signature paulosuzart %}

*Thanks to USA guys, you are the top visitors here. Thank you very much.*




0 comments on commit d300817

Please sign in to comment.