Google Reader alternative for Emacs Ninjas

With Google Reader being discontinued and everyone looking for alternatives I’ve decided to look for a little less “standard” solution, and hey, it turns out Emacs can be a pretty powerful RSS reader.

Newsticker.el

News Ticker is a built-in Emacs feed reader that doesn’t get much attention for some reason. It is feature-rich, handles both RSS 2.0 and Atom feeds and has quite a bunch of tweakable options.
Here’s a simple setup to start with:

(require 'newsticker)

; W3M HTML renderer isn't essential, but it's pretty useful.
(require 'w3m)
(setq newsticker-html-renderer 'w3m-region)

; We want our feeds pulled every 10 minutes.
(setq newsticker-retrieval-interval 600)

; Setup the feeds. We'll have a look at these in just a second.
(setq newsticker-url-list-defaults nil)
(setq newsticker-url-list '("..."))

; Optionally bind a shortcut for your new RSS reader.
(global-set-key (kbd "C-c r") 'newsticker-treeview)

; Don't forget to start it!
(newsticker-start)

Continue reading

System monitor in Emacs mode-line

Resistance is futile…

As we all know Emacs is a great operating system and a decent editor, and as such it has been serving me really well – I find myself assimilating more and more of my tools and daily activities into the Emacs collective. Recently I realised that Conky just wouldn’t cut it anymore…

First of all, I barely look at my desktop. There’s just no reason to do that other than checking some of the system stats such as memory usage or CPU load when I’m hacking arround and testing stuff.

For this particular use-case I figured the Emacs mode-line would be perfect to display all the relevant statistics directly in Emacs in such a way that I could glance through them without interrupting my workflow – giving me real-time feedback with minimal distraction.
Continue reading

There is nothing cooler than a macr- Err… Mixin?

One of the most distinctive features of Common Lisp and Lisp in general, are its code-generation and code-manipulation capabilities.

Probably the best example is the LOOP macro – a Swiss Army knife of iteration that can do pretty much anything. The following snippet iterates a list of random numbers collecting some statistics of its contents and does that while being very concise and readable:

(let ((random (loop with max = 500
                    for i from 0 to max
                    collect (random max))))
  (loop for i in random
          counting (evenp i) into evens
          counting (oddp i) into odds
          summing i into total
          maximizing i into max
          minimizing i into min
        finally (format t "Stats: ~A"
                          (list min max total evens odds))))
Stats: (0 499 120808 261 240)

Continue reading

I do robots Beamer theme

Recently I’ve been looking for a simple and readable Beamer theme but all of the ones I found lacked something in one way or another. Finally, I settled for a theme of my own – based on Amsterdam theme by Rogier Koppejan adding frame numbering to the footer. It’s simple, it’s sleek. It’s all I want.

Here you can find a few sample slides using the theme and here you’ll find the theme itself.

It consists of a header containing outline of the presentation and a footer containing navigation box and all the necessary info such as authors name and institute, presentation title and a frame counter.

Templated Monads? Monadic Templates?

So, I finally found some time for a Template Metaranting follow-up post. This time let’s get down to business as this one contains a fair amount of code.

Sadly, I won’t rant as much but instead I’ll try to show how awesome D‘s templates really are. We’ll write a piece of code, based on this Scheme implementation, that is, a simple monad that we’ll use to build a binary tree, with uniquely numbered nodes containing their height, without any global state (therefore purely) entirely at compile time.

Quick Reader, grab my code!
ADVENTURE!

Continue reading

Instant docs in StumpWM

Here’s a cool hack I use to optimize my docs searching.

Let’s start off with DuckDuckGo search engine.
By itself it’s a pretty powerful tool thanks to its numerous features like the !bang syntax. For example searching for:

!cpp std::string::clear

…takes me exactly where I want.

Let’s use it to our advantage, shall we?

StumpWM is a tailing window manager that allows you to define system-wide key bindings that work and feel pretty much like Emacs ones. Combining that with DuckDuckGo’es !bang syntax makes you just a few clicks away from anything out there:

(defcommand duckduckgo (phrase) ((:string "Search: "))
  "Searches for something on DuckDuckGo."
  (run-shell-command
    (concatenate 'string
                 *your-fav-webbrowser*
                 " http://duckduckgo.com/?q="
                 (substitute #\+ #\Space phrase))))
(define-key *root-map* (kbd "d") "duckduckgo")

Now, if you want to find out if I used substitute correctly all you have to do is:

C-t d !lisp substitute

…what will take you directly there. Turns out I did.

But wait, there’s more!
Continue reading

Properties in the D programming language

Just to evangelize D a little and increase my code/crap ratio, let’s pretend we develop a library in C++ that contains this class:

class SomeMetaVariables {
    public:
    std::string foo;
    bool bar;
};

// ... Somewhere in the client code:
SomeMetaVariables baz;
baz.foo = "foo";
baz.bar = true;

Our library is quite successful and many people are using SomeMetaVariables despite its obvious flaws.
Now, say we get many requests for additional functionality, for example:
“Make bar true only when foo is set to “foo” and other way arround.”
“Well, ok.” – we say and commit this new version of SomeMetaVariables:

class SomeMetaVariables {
    std::string foo;
    bool bar;

    public:
    std::string getFoo() {
        return foo;
    }

    std::string setFoo(std::string newFoo) {
        foo = newFoo;
        bar = (foo == "foo");
        return foo;
    }

    bool getBar() {
        return bar;
    }

    bool setBar(bool newBar) {
        bar = newBar;
        foo = bar ? "foo" : "";
        return bar;
    }
};

We implemented the requested feature, but SomeMetaVariables‘ interface has changed…
“But why are you mad clients? You asked for it!” – cries the C++ developer.
Continue reading

Accessing private class members in C++

I’ve been called Kajtek “MOTHERFU*KINGWALLOFTEXT” Rzepecki lately, so let’s make this post short.

We’ve got this code:

#include <iostream>

class A {
    private:
    int bar;
    void foo() {
        std::cout << "In A::foo() " << bar << "\n";
    }

    public:
    //...
};

int main() {
    A* a = new A();

    //...

    delete a;
    return 0;
}

And we feel a sudden urge to call foo() or access bar. How do we do that?
Continue reading