done is better than perfect

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.Map;
import java.util.TreeSet;

public class GetEnv {
  /**
   * let's test generics
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    // get a map of environment variables
    Map<String, String> env = System.getenv();
    // build a sorted set out of the keys and iterate
    for(String k: new TreeSet<String>(env.keySet())) {
      System.out.printf("%s = %s\n", k, env.get(k));
    }
  }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#define UNICODE
#include <windows.h>

int main(int argc, char **argv) {
  int speed = 0, speed1 = 0, speed2 = 0; // 1-20
  printf("Set Mouse Speed by Maverick\n");

  SystemParametersInfo(SPI_GETMOUSESPEED, 0, &speed, 0);
  printf("Current speed: %2d\n", speed);

  if (argc == 1) return 0;
  if (argc >= 2) sscanf(argv[1], "%d", &speed1);
  if (argc >= 3) sscanf(argv[2], "%d", &speed2);

  if (argc == 2) // set speed to first value
    speed = speed1;
  else if (speed == speed1 || speed == speed2) // alternate
    speed = speed1 + speed2 - speed;
  else
    speed = speed1;  // start with first value

  SystemParametersInfo(SPI_SETMOUSESPEED, 0,  speed, 0);
  SystemParametersInfo(SPI_GETMOUSESPEED, 0, &speed, 0);
  printf("New speed:     %2d\n", speed);
  return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

cd $ROOT_DIR
DOT_FILES="lastpass weechat ssh Xauthority"
for dotfile in $DOT_FILES; do conform_link "$DATA_DIR/$dotfile" ".$dotfile"; done

# TODO: refactor with suffix variables (or common cron values)

case "$PLATFORM" in
    linux)
        #conform_link "$CONF_DIR/shell/zshenv" ".zshenv"
        crontab -l > $ROOT_DIR/tmp/crontab-conflict-arch
        cd $ROOT_DIR/$CONF_DIR/cron
        if [[ "$(diff ~/tmp/crontab-conflict-arch crontab-current-arch)" == ""
            ]];
            then # no difference with current backup
                logger "$LOG_PREFIX: crontab live settings match stored "\
                    "settings; no restore required"
                rm ~/tmp/crontab-conflict-arch
            else # current crontab settings in file do not match live settings
                crontab $ROOT_DIR/$CONF_DIR/cron/crontab-current-arch
                logger "$LOG_PREFIX: crontab stored settings conflict with "\
                    "live settings; stored settings restored. "\
                    "Previous settings recorded in ~/tmp/crontab-conflict-arch."
        fi
    ;;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  {-# LANGUAGE OverloadedStrings #-}
  module Main where

  --import Prelude hiding (id)
  --import Control.Category (id)
  import Control.Arrow ((>>>), (***), arr)
  import Control.Monad (forM_)
  -- import Data.Monoid (mempty, mconcat)

  -- import System.FilePath

  import Hakyll


  main :: IO ()
  main = hakyll $ do

      route   "css/*" $ setExtension "css"
      compile "css/*" $ byExtension (error "Not a (S)CSS file")
          [ (".css",  compressCssCompiler)
          , (".scss", sass)
          ]

      route   "js/**" idRoute
      compile "js/**" copyFileCompiler

      route   "img/*" idRoute
      compile "img/*" copyFileCompiler

      compile "templates/*" templateCompiler

      forM_ ["test.md", "index.md"] $ \page -> do
          route   page $ setExtension "html"
          compile page $ pageCompiler
              >>> applyTemplateCompiler "templates/default.html"
              >>> relativizeUrlsCompiler

  sass :: Compiler Resource String
  sass = getResourceString >>> unixFilter "sass" ["-s", "--scss"]
                           >>> arr compressCss

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class MyFormatter < Rouge::Formatters::HTML
# this is the main entry method. override this to customize the behavior of
# the HTML blob as a whole. it should receive an Enumerable of (token, value)
# pairs and yield out fragments of the resulting html string. see the docs
# for the methods available on Token.
def stream(tokens, &block)
  yield "<div class='my-outer-div'>"

  tokens.each do |token, value|
    # for every token in the output, we render a span
    yield span(token, value)
  end

  yield "</div>"
end

# or, if you need linewise processing, try:
def stream(tokens, &block)
  token_lines(tokens).each do |line_tokens|
    yield "<div class='my-cool-line'>"
    line_tokens.each do |token, value|
      yield span(token, value)
    end
    yield "</div>"
  end
end

# Override this method to control how individual spans are rendered.
# The value `safe_value` will already be HTML-escaped.
def safe_span(token, safe_value)
  # in this case, "text" tokens don't get surrounded by a span
  if token == Token::Tokens::Text
    safe_value
  else
    "<span class=\"#{token.shortname}\">#{safe_value}</span>"
  end
end
end

python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  # test python (sample from offlineimap)
  class ExitNotifyThread(Thread):
      """This class is designed to alert a "monitor" to the fact that a thread has
      exited and to provide for the ability for it to find out why."""
      def run(self):
          global exitthreads, profiledir
          self.threadid = thread.get_ident()
          try:
              if not profiledir:          # normal case
                  Thread.run(self)
              else:
                  try:
                      import cProfile as profile
                  except ImportError:
                      import profile
                  prof = profile.Profile()
                  try:
                      prof = prof.runctx("Thread.run(self)", globals(), locals())
                  except SystemExit:
                      pass
                  prof.dump_stats( \
                              profiledir + "/" + str(self.threadid) + "_" + \
                              self.getName() + ".prof")
          except:
              self.setExitCause('EXCEPTION')
              if sys:
                  self.setExitException(sys.exc_info()[1])
                  tb = traceback.format_exc()
                  self.setExitStackTrace(tb)
          else:
              self.setExitCause('NORMAL')
          if not hasattr(self, 'exitmessage'):
              self.setExitMessage(None)

          if exitthreads:
              exitthreads.put(self, True)

      def setExitCause(self, cause):
          self.exitcause = cause
      def getExitCause(self):
          """Returns the cause of the exit, one of:
          'EXCEPTION' -- the thread aborted because of an exception
          'NORMAL' -- normal termination."""
          return self.exitcause
      def setExitException(self, exc):
          self.exitexception = exc
      def getExitException(self):
          """If getExitCause() is 'EXCEPTION', holds the value from
          sys.exc_info()[1] for this exception."""
          return self.exitexception
      def setExitStackTrace(self, st):
          self.exitstacktrace = st
      def getExitStackTrace(self):
          """If getExitCause() is 'EXCEPTION', returns a string representing
          the stack trace for this exception."""
          return self.exitstacktrace
      def setExitMessage(self, msg):
          """Sets the exit message to be fetched by a subsequent call to
          getExitMessage.  This message may be any object or type except
          None."""
          self.exitmessage = msg
      def getExitMessage(self):
          """For any exit cause, returns the message previously set by
          a call to setExitMessage(), or None if there was no such message
          set."""
          return self.exitmessage
1

Markdown

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  # H1
  ## H2
  ### H3
  #### H4
  ##### H5
  ###### H6

  Alternatively, for H1 and H2, an underline-ish style:

  Alt-H1
  ======

  Alt-H2
  ------
  > quote

  Emphasis, aka italics, with *asterisks* or _underscores_.

  Strong emphasis, aka bold, with **asterisks** or __underscores__.

  Combined emphasis with **asterisks and _underscores_**.

  Strikethrough uses two tildes. ~~Scratch this.~~

  1. First ordered list item
  2. Another item
  Unordered sub-list.
  1. Actual numbers don't matter, just that it's a number
  1. Ordered sub-list
  4. And another item.

  You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

  To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
  Note that this line is separate, but within the same paragraph.⋅⋅
  (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

  * Unordered list can use asterisks
  - Or minuses
  + Or pluses

  [I'm an inline-style link](https://www.google.com)

  [I'm an inline-style link with title](https://www.google.com "Google's Homepage")

  [I'm a reference-style link][Arbitrary case-insensitive reference text]

  [I'm a relative reference to a repository file](../blob/master/LICENSE)

  [You can use numbers for reference-style link definitions][1]

  Or leave it empty and use the [link text itself].

  URLs and URLs in angle brackets will automatically get turned into links.
  http://www.example.com or <http://www.example.com> and sometimes
  example.com (but not on Github, for example).

  Some text to show that the reference links can follow later.

  [arbitrary case-insensitive reference text]: https://www.mozilla.org
  [1]: http://slashdot.org
  [link text itself]: http://www.reddit.com

  Inline `code` has `back-ticks around` it.
  Colons can be used to align columns.

  | Tables        | Are           | Cool  |
  | ------------- |:-------------:| -----:|
  | col 3 is      | right-aligned | $1600 |
  | col 2 is      | centered      |   $12 |
  | zebra stripes | are neat      |    $1 |

  There must be at least 3 dashes separating each header cell.
  The outer pipes (|) are optional, and you don't need to make the
  raw Markdown line up prettily. You can also use inline Markdown.

  Markdown | Less | Pretty
  --- | --- | ---
  *Still* | `renders` | **nicely**
  1 | 2 | 3

  Three or more...

  ---

  Hyphens

  ***

  Asterisks

  ___

  Underscores

  youube
  <a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE" target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg" alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>

javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
sample javascript from xui
*/

var undefined,
    xui,
    window     = this,
    string     = new String('string'),
    document   = window.document,
    simpleExpr = /^#?([\w-]+)$/,
    idExpr     = /^#/,
    tagExpr    = /<([\w:]+)/,
    slice      = function (e) { return [].slice.call(e, 0); };
    try { var a = slice(document.documentElement.childNodes)[0].nodeType; }
    catch(e){ slice = function (e) { var ret=[]; for (var i=0; e[i]; i++)
        ret.push(e[i]); return ret; }; }

window.x$ = window.xui = xui = function(q, context) {
    return new xui.fn.find(q, context);
};

HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html><head>
  <title>A Tiny Page</title>
  <style type="text/css">
  <!-- p { font-size:15pt; color:#000 } -->
  </style></head><!-- real comment -->
  <body bgcolor="#FFFFFF" text="#000000" link="#0000CC">
  <script language="javascript" type="text/javascript">
        function changeHeight(h) {
          var tds = document.getElementsByTagName("td");
          for(var i = 0; i < tds.length; i++) {
            tds[i].setAttribute("height", h + "px");
        }}
  </script>
  <h1>abc</h1>
  <h2>def</h2>
  <p>Testing page</p>
  </body></html>

Aiming for perfection is a frustrating process. Sometimes it feels like aiming at a moving target. Why so? I guess it’s a combination of things, high personal standards, attachment to a vision, to an idea but it can also be a poor definition of scope.

Knowing the scope is key to getting something done because you limit the number of choices and move towards an objective. If the objective implies some hypotheses then, fine you get to test them in the real world because the thing is done.

It’s something catharhic about getting stuff done, it’s like the mind has less things to think about. New ideas can emerge because old ones have been archived into something done. Then, why the chase for perfection? Some just can’t help it. It is an elusive process of emergence that happens without too much conscious notice.

And so, I get to the object of this first post. Why it exists? I guess it’s a simple log. A way to get some things off my mind and, to keep trach of other things. Just an exercise.