Monday, October 21, 2013

Function for quick adding tasks or events to google calendar.

I have written a function so that you can quick add tasks as well as events to google calendar, using Google script.

"use strict";
/*
01234567890123456789012345678901234567890123456789012345678901234567890123456789
*/
/*
 * @author Matthias Pall Gissurarson
 * @usage quickAddTaskOrEventFromString(quickadd);
 * @param quickadd A String describing the event to quickadd
 */
function quickAddTaskOrEventFromString(quickadd) {
  //Add a task if the string includes " due ", otherwise add an event.
  if(quickadd.indexOf(" due ") !== -1){
    //Use the already implemented quickAdd to create an event.
    var event = CalendarApp.createEventFromDescription(quickadd);
    //This event gets automatically added to the users calendar, remove it.
    event.deleteEvent();

    /*
    Create a new task, and have it have the same properties as the event.
    Tasks don't have dueTime as of now, so we add that to the note of the task.
    Also add the events location and description, these are often empty.
    */
    var task = Tasks.newTask();
    task.setDue(event.getStartTime().toISOString());
    task.setTitle(event.getTitle());

    task.setNotes([event.getStartTime().toString(),
                   event.getLocation(),
                   event.getDescription()].join("\n"));

    //Add to the users default tasklist.
    Tasks.Tasks.insert(task,'@default');
  } else {

    //Add the event as normal
    CalendarApp.createEventFromDescription(quickadd);
  } 
}

function main() {
  var s = "Homework due tomorrow";
  var e = quickAddTaskOrEventFromString(s);
}
This function takes in a string, and if it contains " due ", it creates a task instead of an event on the default task list. Might this get implemented in the actual calendar?
I have posted a topic for this on the Google product forums. Let's see what happens.

Monday, June 10, 2013

Markdown blog posts via emacs/vim and pandoc

Using Markdown on google blogs from the Commandline


As per the comment on my last post from Matthías Ragnarsson, I'm using pandoc to generate html from a md file, albeit I'm not using vim, but rather emacs (as setting up markdown-mode is simpler, and with evil, it's pretty much the same thing, only more easily extensible. It also fits better with the Unix philosophy of using external tools to do tasks, rather than hardcoding them into the program itself.


Saturday, June 08, 2013

Google calendar from the desktop, and posting through vim

Posting trough vim

Here I am, writing a blog post in vim. If this actually gets posted, I'll be pretty impressed, as this makes posting to the google blogs extremely simple to implelement via a server. The api program itself is just a python program, so porting the functionality over to haskell shouldn't be hard at all. I might even make it and put it on hackage. It'd be neat to have a package there!

Anyway, I hope this test works, as it'll make code examples way simpler.

Google calendar on the desktop

I recently made some commits so that it can display arbitrary colors in conky, and used it to create a neat display of my google calendar on the desktop, and you can see a picture of it included in the pull.

My .gcalclirc is as follows:

--calendar
icetritlo@gmail.com
--military
--monday
#Tomorrow-Night Palette
--conky_color0
    #282A2E
--conky_color8
    #373B41 
--conky_color1
    #A54242 
--conky_color9
    #CC6666 
--conky_color2
    #8C9440 
--conky_color10
    #B5BD68 
--conky_color3
    #F0C674 
--conky_color11
    #DE935F 
--conky_color4
    #5F819D 
--conky_color12
    #81A2BE 
--conky_color5
    #85678F 
--conky_color13
    #B294BB 
--conky_color6
    #5E8D87 
--conky_color14
    #8ABEB7 
--conky_color7
    #707880 
--conky_color15
    #F0C673 

#Viljum auka vidd ef a ad vera a isl
#--locale
#is_IS.UTF-8
#-w
#12

I have that last part if I should want to have the dates and day names in Icelandic, but as neither are capitalized (correct in the middle of a sentence, but not standalone), and the english version suits me fine, I don't think I'll bother fixing it.

[Edit: Rewrote this post in markdown, and used pandoc to translate it into html, as per the comment below. N.B. you need my fork of gcalcli for this to work, as the --conky_color options were added by me.]

Wednesday, June 05, 2013

Using GoogleCL to post from the terminal

I'm really just testing out using googleCl to post from my terminal to the blog. As simple as pacman -S googlecl, then authenticate via oauth (almost totally automatic, just enter your username and password in the browser window, grant access and done), and then $ google blogger post etc. Very basic. I wonder if I can post a text file....

Saturday, April 20, 2013

Using xmobar to display rcirc status from emacs

I use the emacs rcirc as my main irc client, and via BitlBee, facebook and skype chat. I use XMonad as my window manager, and xmobar as my display bar. Today I added the rcirc status line to my xmobar, so that I can see if I have new messages on any channels/facebook chat/skype. I wrote a short bash scriptlet that I execute in xmobar with

Run Com "~/.scritpstouse/rcircActivity" [] "rcirc" 100

the script is as follows:

#!/usr/bin/env bash
if  emacsclient -e rcirc-activity-string > rcirc-string;then
    if ircstr=$(cat rcirc-string | tr '"' '\n' | grep '\[');then
        echo "<fc=#00ff00>"$ircstr"</fc>"
    else
        echo "<fc=#0000ff>[]</fc>"
    fi
else
    echo "<fc=#ff0000>[]</fc>"
fi

This contacts my running emacs server and asks for the status string, and then displays it. I'd have it in the .xmobarrc, but it doesn't handle escaped " so well. If my server isn't running or rcirc isn't, there is no field that contains [, so the output will be empty and my xmobar will just have a few spaces. The echos give me different colors on the xmobar based on what happened, green and the status if rcirc on, blue if emacs on but rcirc not, and red if emacs turned off. Try it!

[Edit: I've decided to try and use erc instead. The command is almost the same (the ircActivity), but the if clause is replaced with:
i
f  ercBuffers=$(emacsclient -e "(if (functionp erc-track-shorten-function) (funcall erc-track-shorten-function (mapcar 'buffer-name (mapcar 'car erc-modified-channels-alist))) (nil))");then
    if ircstr=$(echo ${ercBuffers:1:${#ercBuffers}-2} | tr ' ' ',' | tr -d '"');then
        echo "<fc=#00ff00>["$ircstr"]</fc>"


A little more complicated, but it works, and I believe erc is more feature rich.]

I'll later try to explain my xmonad config, and include the (current) file. It handles everything for me, from handling my workpaces, windows etc.. to changing my keyboardlayout and handling my media keys. It rocks!


Sunday, February 03, 2013

The MIT License

When I make code publicly available, I usually do it under the MIT License. Why? Because it is a so called copyfree license, which, in contrast to copyright, merely states that anyone is free to use the provided code, if they include the license (and thus preserving my name in the codebase). It is as follows:

Copyright (C) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

This, in contrast to copyright, does not restrict use of my code in other work, and in contrast to copyleft, does not force them to apply a specific license to their own code. It is thus a true free software license, allowing anyone to use my ideas for free - as long as they acknowledge my participation by including the license. Thus I enrich society by showing more examples of code, maybe help someone out on the project, and gain better reputation - instead of burdening it with pointless legal battles about something no one can really own. If you ever give out any code, use the MIT License, or at least a copyfree license.

[Edit 2013-04-24:  After reading tldr;legal, I've decided that the GPL is actually a better license, by making more software free as in freedom. I have thus changed most of my projects to the GPL, and I recommend that you read up on tldr;legal and decide for yourself what license fits your project best. I hope that you'll choose the GPL, though anyone should of course be free to do with their work as they please.]

Thursday, November 01, 2012

Errata for "A note on the Icelandic crash from an amateur Austrian perspective".

After receiving some comments on my previous post, I've decided to update it with some errata, and just leave the post as it currently is. The following is verbatim from a comment by user herbert_spencer on reddit.com:

>busts are mainly caused by low interest rates.

It may be more accurate to say that they are caused by unsustainable investments because of *artificially* low interest rates.

> Due to the large size of the Icelandic banks (among other things), the belief in Icelandic Krona was high, causing it to be seemingly overvalued.

The fact that that the CBI said it would act as a lender of last resort and that the IMF was believed to have the capability to provide stability seems more important than the size of the banking system (which was albeit probably oversized) to the proliferation of currency mismatching.

>Central Bank of Iceland, through the Floating exchange rate policy raised the exchange rate.

The CBI does not determine the exchange rate directly. The fact that the krona had a floating rate means that it can fluctuate on the market. There is the issue of foreign currencies having lower interest rates than the krona and the consequent currency mismatching because of the implicit guarantee of bailout from the IMF.

> They might have tried to offer the krona undervalued, and then foreign currency would have flowed into the Central Banks stash, as always happens between good money and bad money, for all would have wanted to get their hands on the krona instead of the foreign currency, seeing as it was seen as being better.

Again, a floating exchange rate does not allow the legal undervaluing or overvaluing of currencies. The state may however, as Iceland did following the crash of the krona, limit the use of foreign exchange.

> This enabled Icelanders to get pretty cheap loans

Its not so much the value of the currency that allowed this as the easy monetary policy pursued by the ICB along with the low worldwide interest rates. Short term borrowing expanded as those rates remained low, which, in conjunction with increased long term investment created maturity mismatching (classic Austrian malinvestment) during the boom period.

> for various items, and was used to buy cars etc.

It is also important to remember, and perhaps mention that the credit expansion was not limited to loans for purchases of consumer goods but also in industry and capital goods (and international business). This is where the malinvestment comes into play.

>The price of housing was also artificially high

It may be good to explain the causal relation between the monetary policy and housing prices.

>Then, when the Icelandic banks fell, due to being in a "liquidity trap"

The Keynesian notion of a liquidity trap is questionable and not exactly the cause of the bank crash. It is important to note the difference between the liquidity crisis we saw, where the ICB had lent to insolvent banks (and to the government, which was insolvent). This is where the currency mismatching came back to haunt the ICB. Since debt was owed in foreign currency, there could be no bailout.


>this of course raised the cost of capital to even higher levels than it should have been.

The bust merely reveals the malinvestment.

>The belief in the Icelandic Krona fell, and thus the exchange rate set by the Central Bank was too high, causing an outflow of foreign currency, as it was now determined as being overvalued, and now no one wanted the Icelandic Krona. They then lowered the exchange rate, and thus the foreign currency loans which so many thought were so cheap turned out to be not so cheap at all, merely a fluke.

Again, the exchange rate is not set but is determined by the foreign exchange market. When the bust reared its ugly head in Iceland, and bankruptcy ensued, faith in the krona collapsed, people tried to sell kronur for foreign currency, and its exchange rate naturally collapsed in consequence.

>How could the banks grow so large?
Also, it is important to ask how the banks could make such bad loans.

>We could start by going onto a gold standard, or some other standard in which the value of the currency is based on some commodity.

While it would definitely be an improvement, a denationalized currency may be even better from an Austrian perspective.

>It is a hassle to dig up more gold (certainly more than just to print more money/issue government bonds)

If gold money is mined (on the market. If done by governments, then yes, there is still a problem but the state would probably rather resort to debasing the currency than to mine) to make money, then it is not even inherently a problem. The mining entrepreneur is acting as an arbitrageur since he realized people value gold more than anything else those miners (and the mining equipment) could be doing.

End verbatim.

As I've previously stated, I'm still studying Austrian economics, and many of these points highlight some of my misunderstandings. I believe that reading the book Deep Freeze by Phillip Bagus will further clarify this, and I hope to make another post after having read said book.