Skip to content. | Skip to navigation

Personal tools
Log in
You are here: Home - Blog

Run bitcoin-abe with parameters, from a script

Posted by admin |

Bitcoin-abe takes its config values either from the command line or from a config file. What if you want to run it from inside of another script, how do you configure it? Please check the comments in the source code below:


from Abe import abe
# Your config settings
from myconfig import config

# A complex setting, a dictionary in a list, that
# we want bitcoin-abe to be configured with
datadir = [{
       "dirname": config.bitcoin_regtest_data_dir,
       "chain": "Regtest"

# It turns out that bitcoin-abe accepts JSON as values
# for its command-line arguments. It means we can pass
# in as complex data as we want

datadir_arg = '--datadir=' + json.dumps(datadir)
port_arg = '--port='+ str(config.abe_port)
config_arg = '--config='+ config.abe_config_location

# argv contains the command line arguments, so we just fake one
argv = [datadir_arg, port_arg, config_arg]

# Call the main function in abe with the command line arguments
def main():
Sep 01, 2015 10:55

A logger for multi threaded python that does not make python segfault

Posted by admin |

I introduced logging to a a python application that is multi threaded, and it started to segfault. I switched to ConcurrentLogHandler but it still segfaulted. I then switched to log over http with restapi-logging-handler, and in that way introduced a bit of complexity, but eventually decided to take another sweep at pypi to see if there wasn't a simpler solution and found this:

multiprocessing-logging 0.2.1 : Python Package Index

It seems to work like a charm in initial tests. I use it like this (abbreviated code):

import multiprocessing_logging

log_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logs', 'app.log')
mhandler = multiprocessing_logging.MultiProcessingHandler('worker-logger', sub_handler= logging.handlers.RotatingFileHandler(
              log_file, maxBytes=20000000, backupCount=0))



Aug 26, 2015 11:19

Prevent Spotify stealing your icons on Ubuntu 14.04

Posted by admin |

Well, it isn't actually stealing your icons but when interacting with Spotify on Ubuntu 14.04 Linux, it has a tendency to make your icons for applications and other stuff disappear. It seems to do this by switching themes somehow or some sorts. However there is a way of preventing that.

AppArmor is a program that can control what other programs can and cannot do, with regards to file access. It is mainly used for security reasons to make sure that programs, especially binary-only ones whose code you cannot scrutinize (such as Spotify), are not secretly veering off stealing data from your hard disk or mucking about in other ways.

AppArmor can be configured to prevent Spotify from doing this icon-disappearing thingy. In your AppArmor profile for Spotify, add these two lines (tested by me):

# block sni-qt
deny /usr/lib/i386-linux-gnu/qt4/plugins/systemtrayicon/ r,
deny /usr/lib/x86_64-linux-gnu/qt4/plugins/systemtrayicon/ r,

Or use the entire profile here (not tested by me)

"First you need to disable Spotify's indicator. Spotify is using sni-qt package to show indicator. Removing that package will disable indicator but this solution will affect other Qt based applications like Skype. But we got another option to do that. after some research i discovered that this task can be done using AppArmor. I wrote an experimental AppArmor profile, copy this profile and reload AppArmor."




Aug 26, 2015 11:10

How to update one file from the same file in another branch (git)

Posted by admin |

Untested by me. My need is to carry over just the changes in one file to the same file in another branch in the same git repository.


A simple command already solved the problem for me if I assume that all changes are committed in both branches A and B:
git checkout A
git checkout --patch B f

Read more: Link - git - How do I merge changes to a single file, rather than merging commits? - Stack Overflow

Aug 24, 2015 04:10

How to kill Linux process by pattern of process name

Posted by admin |

Don't point pkill at anything you do not have the intention to kill.

pgrep -f pattern

first, so you know what you are killing.

Use pkill -f, which matches the pattern for any part of the command line
pkill -f my_pattern

Read more: Link - linux - How to kill all processes with a given partial name? - Stack Overflow

Aug 15, 2015 02:00

How to create a desktop item on Ubuntu 14.04

Posted by admin |
In GNOME desktop, you can use gnome-desktop-item-edit to configure a desktop shortcut easily.
$ gnome-desktop-item-edit ~/.local/share/applications --create-new
In this example, gnome-desktop-item-edit will automatically create a desktop launcher file in ~/.local/share/applications.
If gnome-desktop-item-edit is not available (e.g., on Ubuntu), you can install it as follows.
$ sudo apt-get install --no-install-recommends gnome-panel

Read more: Link - How to create desktop shortcut or launcher on Linux - Xmodulo

Aug 15, 2015 12:47

How to run individual tests in python

Posted by admin |

Tested by me.

You specify the path to the file where the tests are residing. After the path you add a string that specifies the place of the test inside that file, in dotted format:

python <path_to_file> <class_name>.<test_method_name>
python MyCase.testItIsHot

Read more: Link - python - Running single test from unittest.TestCase via command line - Stack Overflow

Aug 15, 2015 02:40

What's the best way of writing readable javascript applications?

Posted by admin |

Update 2014-08-02, see also these links:

Which take a Haskell/FP perspective on improvements


Understanding the code in a javascript application can be hard work. There are at least two reasons for that:

1. TIMTOWDI (There is more than one way to do it)

There's more than one way to do it, a term I believe originally coined by Perl creator Larry Wall. C++ and  Scala are also often said to suffer from different coding styles, while python does not. Javascript is by many felt as lacking a lot of features, but can be cajoled to emulate these features.

Different people have different preferences and decide to go about "fixing" these things in different ways. The result of this is that there are different ways of importing functionality, tracking dependencies, emulating a class base OO language and so on and so forth. All these extensions still rely on javascript syntax which makes them contrived in source code.

Even such a common solution as the object literal demands a lot of knowledge of the coder about anonymous functions, closures and so on to figure out what's going on. Also other ways of going about things become syntax-heavy:

(function() {
  this.Example || (this.Example = {});
  this.Example.Models = { Product: employee };
  this.Example.Collections = { Products: employees }


On top of that there is a plethora of frameworks each one if their own idiosyncratic view of the world.

2. Javascript is asynchronous

"Callback hell" is a term often used for the default way of handling asynchronicity in javascript. It makes it hard to follow the program execution by reading the source code. There are other ways of handling asynchronicity in javascript, but then we are back to reason number 1 above: a plethora of solutions. Another aspect, put forth by my friend Mikael, is that javascript has exceptions, which doesn't sit very well with the structure of the language. I guess because it becomes quite unclear through what an exception is supposed to bubble up.


What can one do in order to write javascript that is readable and understandable by another coder?

  • One way is to present upfront the unchangeable parts of the application, whatever they might be. Basically present the conceptual model for the implementation of the application.
  • Frameworks, as much as I am not fond of frameworks in general, do make this possible.  Frameworks suffer from that you need to lean them and then use their tools which often aren't as useful and universally applicable as the language underneath: You end up trying to screw in screws with a hammer.
  • One idea is to divide program flow into two categories: hierarchical and sequential, where the file indicates level of hierarchy. So there is a top file that deals with overall logic of the program, and then there are files that each contain code that carry out lower-level tasks. Ideally there should be no leakage of these abstractions: You should be able to rely on a file being its own universe, and ideally testable on its own. This is called a Multilayered architecture.
  • Another idea is to use some kind of actor model and disentagle callback hell into objects and messages.
  • Or write in another language altogether and transcompile it to javascript, hopefully with a source map.
  • Or use Dart or Typescript.
  • Typescript contains a lot of extensions to javascript on the language level (instead of on a framework level), which may make the syntax cleaner.

There is no publicly available code for tracing a node.js program line by line

Or at least I cannot find any. Jetbrains has acquired spy.js but that one is not open source. The node-inspector people seem less enthusiastic  Enhancement: Full trace of program execution · Issue #366 · node-inspector/node-inspector

There is something close to tracing though for node.js (and I have tested it):

(alpha) njstrace lets you easily instrument and trace you code, see all function calls, arguments, return values, as well as the time spent in each function.

Jul 29, 2015 03:11

Software architecture: Invariant things should be apparent

Posted by admin |

I'm trying to figure out how to make the source code of a system readable, readable meaning that you can understand the system on a high level, and also its constituent parts, from the source code.

It seems to me, and I am just starting thinking about this, that there things (patterns, frameworks, data schemas) that are invariant, that is they don't change over time as the system runs.  I'm sure the word invariant has other definitions, but for this text that was invariant means. These invariant things are the things you can communicate to the developer/maintainer.

So it would seem that you should be upfront with your invariant stuff. Like in a central file or as imports to it. And if you have stuff that is changing and amorphous, can it be abstracted into, or at least abstractly described, as something invariant? Then do that.

It seems to me that the more of these invariant stuff you can get into your system and systems description, the easier it the system will be to understand.

However the invariants, such as e.g. a framework's modus operandi, should not lead to convoluted solutions.

So the rule might be:

Use as many invariants as you can in your system, but not to the point of convoluted constructs.

Could be a two step process: Find and describe the invariants you already have, and see if you can refactor code into invariants.

The invariants can work on many levels: Using a language that discourages TIMTOWDI, using frameworks (iff they fit the problem) and taking time to create well defined abstractions for as many parts of the code as possible. Abstractions here means in the direction of readability and understandability.

Another question then arises, what abstractions are easy to undertstand? In user interface design one measure of the complexity of a GUI is the number of objects on the screen and how many alignment lines there are. Fewer objects and aligned objects lead to lower complexity. I wonder how could one measure the complexity of abstractions in source code? Metrics could include

  • how many inputs
  • if there is mutable state in there somewhere
  • if there are side effects
  • how many other files the code interacts with
  • the cyclomatic complexity

Abstractions already familiar to the developer are easier for him to use, and re-using known abstractions with some magical twist may work too. it also means it may be a good idea to have a toolbox of powerful abstractios that covers most of the things needed to be done.

Sometimes there is a like precipice when interactions between even simple components get too complex to understand. In which case the sub system needs to be "black-boxed" and not leak into the environment.

Jul 29, 2015 02:55

The regtest generate command gone if --disable-wallet is set

Posted by admin |

If you compile bitcoind version 0.11.0 with the --disable-wallet flag set, certain commands go missing. That is only natural since commands that need a wallet won't work without one.

Curiosly enough the "generate" command in regtest mode, a command that lets you build up on the number of blocks you pretend that you've mined, also disappears.

Well now as I am writing this I realised that it may not be so strange at all. It has to do with that the mining fees need to be paid to an address, and without a wallet, no address. However a bitcoind server in regtest mode can still be a part of a bitcoin network, so one wouldn't necessarily have the the wallet on the server doing the mining.

Well, now I have some 15'000 bitcoins. Not real ones unfortunately.

Jul 19, 2015 05:45