I’m doing a small revolution in my environment from time to time. I think “hey, a cool stuff”, take a deep breath and doing something new. And this is story about my migration from the bash to the fish shell.
Let’s see, what says the official tutorial:
fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.
If you want to make your command line more productive, more useful, and more fun, without learning a bunch of arcane syntax and configuration options, then fish might be just what you’re looking for!
And this is almost true =) But there is another concrete reason, why I like fish shell:
I’m at the beginning of my journey into the world of gnuchess. Its interface is a slightly tricky, than I’ve expected, but I was interested. So I’ve decided to make some notes about this.
GNU Chess performs at the senior master/weak international master strength of 2500+ on the Elo rating system
I don’t know, what does this mean really, but sounds cool =)
It is often used in conjunction with a GUI program such as XBoard or glChess
No, it’s not our way. Let’s try to use original teminal-based client (more terminal for the terminal god, mwuahahahaha =).
A little bit about my new program-frankenstein. Now it is an endless Paginator for Django. It sounds crazy, isn’t?
Standart Django Paginator uses the count() function for the verification of page number. It is converted to the SELECT COUNT(*) ... query, of course. But as I was explained (I really don’t know, maybe it’s just an exaggeration - you can post your opinion in the commentaries), this is not a such lightweight query, as we want for the paginated rest api, because of the MVCC in PostgreSQL.
How we can avoid the extra COUNT(*) query? Don’t panic, we can trick the Django.
First of all we need to disable count parameter from the api response. We can introduce a custom pagination serializer:
The next our move - disable the page number verification. This can be done by the custom paginator class:
classCustomPaginator(Paginator):""" HACK: To avoid unneseccary `SELECT COUNT(*) ...`
paginator has an infinity page number and a count of elements.
"""def_get_num_pages(self):"""
Returns the total number of pages.
"""returnfloat('inf')num_pages=property(_get_num_pages)def_get_count(self):"""
Returns the total number of objects, across all pages.
"""returnfloat('inf')count=property(_get_count)def_get_page(self,*args,**kwargs):returnCustomPage(*args,**kwargs)classSomeListView(generics.ListAPIView):model=SomeModelserializer_class=SomeSerializerClasspagination_serializer_class=CustomPaginationSerializerpaginator_class=CustomPaginator
Oh, goodness - we introduced the infinity number of the pages and the infinity number of elements… But we want also the correct next/prev links, so one more detail:
classCustomPage(Page):defhas_next(self):""" HACK: Select object_list + 1 element
to verify next page existense.
"""low=self.object_list.query.__dict__['low_mark']high=self.object_list.query.__dict__['high_mark']self.object_list.query.clear_limits()self.object_list.query.set_limits(low=low,high=high+1)try:# len is used only for small portions of data (one page)
iflen(self.object_list)<=self.paginator.per_page:returnFalsereturnTruefinally:# restore initial object_list count
self.object_list=self.object_list[:(high-low)]
This solution looks very questionable, but exciting for me. If you have something to say about this - welcome! =)
Don’t be confused by the title of this post - I will tell you about my experience in the development of xmpp client xi. The first version of this client was written in Haskell in the shortest time (for me, of cource), and this fact provides the second emotional part of title =)
First of all - xi was inspired by ii irc client. It explains the all of its features, design and main idea. In short - after this post I’m a huge fan of this tool and philosophy.
Second - xi was written in Haskell. I will not explain why =)
Now let’s take a look inside. We can see a lot of dependencies of course - xi uses pontarius xmpp for the XMPP interaction. But there is an interesting hidden trick - we must use this library from the github directly yet, because of an unpleasant bug. This can be done by the cabal sandbox add-source command:
Other important feature is the listening of the file, which will contain a user input. We will use a fsnotify library for these purposes. Michael Snoyman shared the implementation of this feature (he always flying to help, when SO question contains the haskell and conduit keywords =). The main idea is the monitoring file changes by fsnotify, and save the current position in file. There are several disadvanteges with this approach - e.g. we can’t handle a file truncation. But for our purposes we can use files, that will never be truncated.
get a user roster and convert it to the internal representation (the ContactList type)
create an appropriate directory structure (a separate directory for each contact with in/out)
for the each input file start a separate thread to monitoring the user input
start a thread for monitoring the incoming messages
Little bit about client details. A Session and ContactList objects have been shared through the Reader monad. For the parsing of configuration file yaml-config library has been used. Also, there is an ability to see an entire xmpp data flow - this requires only the debug mode in configuration.
Client source code hosted on the github, but you should keep in mind, that it’s more prototype, than a completed project. So if you want to improve something - welcome =)