Author Archives: Alvar

TypeScript 4.0 is here!

TypeScript 4 features

Microsoft continues to make developers feel great using new technologies. Now they announced the availability of TypeScript 4.0! It’s better in all areas – productivity, stability, and scalability.

Developers love to work with clean, well structured, readable, and functional code. This is exactly what TypeScript is for. Together with their IDE Visual Code it’s a strong and convenient combination for almost any web developer.

No more ‘undefined’ errors, better structure, and easier refactoring, mixed types of black magic. If needed create your own composite types for complex situations.

There’s a great article on TypeScript blog on what’s added and how to get started right away.

Start hacking and learn something new!

npm install -D typescript

TypeScript 4 features

Running Obyte wallet on headless RaspberryPi 3+

RaspberryPi 3+

Let’s build and run headless Obyte wallet on RaspberryPi 3+. We’re going to run Obyte light node. Running full node is too slow to sync and the first database buildup can take weeks-months to complete Raspberry Pi 3+.

I also tried to do the full node syncing on another computer and then copied that DB into the Raspberry. Still, keeping it in sync was too much for Raspberry so it didn’t work out even then.

Prepare image on to the SD card

Go with the Raspbian Stretch Lite image from here Raspian is based on Debian Linux.

Raspbian Stretch Lite

Next, download balenaEtcher ( for burning that image onto the SD card. If you haven’t used it yet then the balenaEtcher is a very easy, convenient way to burn OS images into the SD & USB drives.

Note that I have 16GB SD card in my example, 8GB is more than enough.


Configure SSH & Wifi (if needed)

Now, enable SSH so you could connect into your Raspberry Pi without a need for a screen and keyboard. I’m going to use cable LAN and therefore don’t need to setup Wifi connection at the beginning.

To setup SSH you need to create the file ssh into the boot folder. Basically, there are two volumes – boot and rootfs. Create empty file names ssh and validate that it’s there.

For Wifi setup create a file named wpa_supplicant.conf again into the boot folder with the following content:


This file will be copied on the first boot into the /etc/wpa_supplicant/wpa_supplicant.conf folder.

Find your Pi and log in

Now it’s time to put SD card into the Raspberry, connect LAN and power up.

You need to find your device IP address. One option is to assume that it has default hostname. In that case, you could ping raspberrypi.local to get it. The easiest way!

Other ways are to use arp -a, nmap (more info here or get IP addresses list from your router and find it from there.

Log in using SSH using IP or ssh raspberrypi.local. The default username is “pi” and password “raspberry”. Change your password after login.

Update and configure

When logged in, first update its system.

sudo apt update
sudo apt upgrade

Then check Raspberry configuration tool to setup Wifi (if needed and you didn’t do this before) and extend file system. Run raspi-config.

For the menu “Advanced Options” choose “Expand Filesystem”. This will make Raspberry use the whole SD card.

To be sure that system is updated you could also run “Update” from there.


Install NodeJS, Git, Tor and Screen

curl -sL | sudo -E bash -
sudo apt install nodejs git screen tor

I also like to use vim and sysv-rc-conf, but there’s no need to install these for this setup.

“Screen” will be used to run wallet on the background while remaining overview of the situation. This is totally optional.

Clone and configure wallet

Now clone “headless-obyte” from Github.

git clone obyte
cd obyte
npm install

Create the user configuration file into ~/.config/headless-obyte/conf.jsonand enter the following.

"socksHost": "",
"socksPort": 9050,
"socksLocalDNS": true, "control_addresses": [""], "bLight": true,
"bFaster": true

Don’t set socksHostsocksPort, and socksLocalDNS if you don’t wish to use TOR.

Also, you can also define control_addresses (array) with your Obyte wallet device address, so you can control your wallet remotely or payout_address, to restrict, which addresses the wallet can withdraw funds.

Run & enjoy

node start.js --max-old-space-size=2048

It will ask to set the passphrase. Later on every run it also asks that. This is used to protect your wallet private keys.

When you run the node, “my pairing code” is the code that you can use to connect headless wallet with your Obyte wallet.

====== my pairing code: *****************

When everything work you can “Ctrl + a + d” to detach that screen. And with command screen -r go back into it. “Ctrl + d” or `exit` to terminate.

An issue to be dealt with will be handling growing log file size. One option is to disable the log, but it won’t suggest doing that.

For now, if everything runs without errors turn logs off by adding the following line into the conf.json file.

“LOG_FILENAME”: “/dev/null”


Android apk keystore signing for store


First think you need to do is to generate keystore file for project. Store apps needs to be signed with that and its always good to have separated keystore for each app. Keep that securely cause you need this everytime youre updating your app on store.

You can generate also using various IDEs like NetBeans, Eclipse, Android Studio and so on, but in this time we’re using command line.

user@host:~/home $ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000


After you have built your apk (unsigned) you need to use following command to sign this with previously generated keystore.

user@host:~/home $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name

Validate signed apk:

user@host:~/home $ jarsigner -verify -verbose -certs my_application.apk


Finally align you apk to optimize it and after that it’s ready to be submitted into store.

user@host:~/home $ zipalign -v 4 my_application.apk my_application_aligned.apk


Add custom fields under wp general settings

To add custom fields under wordpress general settings without hacking core code use this as example. Of course you can make it better and write some fancy class for doing this.

add_filter('admin_init', 'my_general_settings_register_fields');

function my_general_settings_register_fields()
	register_setting('general', 'my_field', 'esc_attr');
	add_settings_field('my_field', '<label for="my_field">'.__('My Field' , 'my_field' ).'</label>' , 'my_general_settings_fields_html', 'general');

function my_general_settings_fields_html()
	$value = get_option( 'my_field', '' );
	echo '<input type="text" id="my_field" name="my_field" value="' . $value . '" />';

WordPress custom menu display

Just a small example of how to build custom menu output in WordPress.

$menu_args		= array('menu' => 'Main menu', 'echo' => 0) ;
$menu_string	= wp_nav_menu($menu_args);
$xml	= new SimpleXMLElement($menu_string);
$out	= false;

foreach ($xml->ul[0] as $li) 
	$classes = array('current-page-ancestor', 'current-menu-item', 'current-menu-parent');
	if (strstr($li['class'], 'current-page-ancestor') || 
		strstr($li['class'], 'current-menu-item') || 
		strstr($li['class'], 'current-menu-parent')) 
		$out = $li->ul;      
		$i = 0;
		if (isset($out->li) && !empty($out->li))
			$out['id']		= 'sub_menu';
			$out['class']	= 'clear';
			foreach ($out->li as $li_sub) 
				if (!strstr($li_sub['class'], 'current-page-ancestor') && 
					!strstr($li_sub['class'], 'current-menu-item') && 
					!strstr($li_sub['class'], 'current-menu-parent')) 
if (!empty($out)) {
	 echo $out->asXML(); 

Replace menu links in Drupal 7 using menu_link & menu_tree hooks

Want to add span elements to menu, change ul id or add classes? Need images in menu or some custom style? You can do that by using menu_link for menu items and menu_tree hook for menus itself. To replace all menus remove __MENUNAME.

// Customize menu li & links
function MYTHEME_menu_link__MENUNAME($variables) 
	$element	= $variables['element'];
	$sub_menu	= '';

	if ($element['#below']) {
		$sub_menu = drupal_render($element['#below']);

	// Enable this to use html in title, eg img, span or something else...
	$element['#localized_options']['html'] = true;

	$link = l('<span>' . $element['#title'] . '</span>', $element['#href'], $element['#localized_options']);

	return '<li' . drupal_attributes($element['#attributes']) . '>' . $link . $sub_menu . "</li>\n";

// Customize menu ul
function MYTHEME_menu_tree__MENUNAME($variables) 
	// Change id of menu ul
	return '<ul id="my-custom-menu-id">' . $variables['tree'] . '</ul>';

You can probably use preprocess_menu_link or preprocess_links as well, but this seems to be easiest way. Read more about it here.

Requiring files in Drupal 6 & 7

I have seen a lot of Drupal modules where requiring php files is done like this

$module = 'my_module';
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . '/test.php');

While this is totally right i still encourage you to use special function for this called “module_load_include“.

module_load_include('php', 'my_module', 'test');