-rw-r--r-- 1.5K Apr 6, 2016 · EF30922 · ~1 min

A simple console.log with file and line number output in Node.js

node.js javascript полезное шпаргалки

While coding in Node.js, I constantly need to print something to the console. Errors, for example. But for better information it is more convenient to know exactly where the output is coming from. Especially since when I was coding for iOS, I always had such a handy macro at hand, but with Node.js I had to google and dig around, because many examples from Stack Overflow simply crashed on the latest Node.js 5.10.0. They crashed because they used Error.captureStackTrace(err, arguments.callee), and now you need to use NFE.

In the end I made what I wanted. Leaving it here as a cheat sheet.

npm install colors --save

File logger.js:

'use strict';

let colors = require('colors');
colors.enabled = true;

exports.p = function logger(somethingForPrint) {
    somethingForPrint = somethingForPrint || '';
    const originalPrepareStackTrace = Error.prepareStackTrace;

    Error.prepareStackTrace = (error, stack) => { return stack; };

    let e = new Error;
    Error.captureStackTrace(e, logger);

    const stack = e.stack;
    const filename = stack[0].getFileName().split('/').reverse()[0];
    const trace = filename + ':' + stack[0].getLineNumber() + " " + colors.bold.black('%s') + "\n";

    Error.prepareStackTrace = originalPrepareStackTrace;

    console.log(trace, somethingForPrint);
}; 

Use:

const logger = require('../utils/logger');
logger.p('something happened');
// file.js:401 something happened 
[↵] open page prostoj-console-log-s-vyvodom-fajla-i-nomera-stroki-v-node-js.md
-rw-r--r-- 4.9K Apr 2, 2016 · 56615E4 · ~4 min

Impressions of Assassin's Creed IV Black Flag

assassin's creed игры

Assassin's Creed IV Black Flag

I finished part 4 a couple of weeks ago.

[↵] open page vpechatleniya-ot-assassin-s-creed-iv-black-flag.md
-rw-r--r-- 585B Mar 24, 2016 · 75B06AF · ~1 min

Restoring a broken GRUB bootloader on Hetzner

шпаргалки hetzner grub ubuntu linux

This is already the second time in 2-3 years that I have run into GRUB breaking on one Hetzner server. As a result, after a reboot the server becomes unreachable. You have to go to the control panel, enable booting from the rescue image in the Rescue section, connect to it over SSH, and restore the bootloader. Looking up the info every time is annoying, so in short, after connecting to the rescue system over ssh, enter this in the console:

mount /dev/md3 /mnt
chroot-prepare /mnt
chroot /mnt
mount -a
apt-get install grub2
grub-install /dev/sda
update-grub
exit
reboot now
[↵] open page vosstanovlenie-sletevshego-zagruzchika-grub-na-hetzner.md
-rw-r--r-- 1.1K Jan 12, 2016 · 2701E59 · ~1 min

Telegram bot for App Store releases informing

app store release informer javascript node.js telegram

Telegram bot for App Store Release Informer

I had been carrying this idea around for a while and finally implemented it. Apple has a REST API for searching iTunes. I made a bot for Telegram that lets you subscribe to app updates. When a new version comes out, it writes to you in Telegram, whether in a private chat or a group chat. Now at work we will all be able to find out quickly when new versions of our apps go live in the App Store.

I wrote it in Node.js as best I could. The main thing is that it works. I wanted to make something for Android folks too, but it turns out Google Play has no API. None at all O_O.

Try the bot: https://telegram.me/ReleaseInformerBot (just type /help when you start)

If anyone wants to add something, the source code is on Github: https://github.com/makoni/ReleaseInformerBot

True, besides Node.js it uses my favorite CouchDB as the database. But to run it on a Mac, you just download the binary and you are done (well, and create the DB + views).

[↵] open page bot-dlya-telegram-app-store-release-informer.md
-rw-r--r-- 6.5K Jan 6, 2016 · F6B6F74 · ~5 min

Impressions of Assassin's Creed III

assassin's creed игры

Assassin's Creed III

I'm continuing to play through the Assassin's Creed series and write down my impressions.

[↵] open page vpechatleniya-ot-assassin-s-creed-3.md
-rw-r--r-- 3.1K Dec 31, 2015 · 0B74569 · ~3 min

2015 Year in Review

новый год итоги жизнь концерты итоги года

Modest Instagram-style year-in-review.

[↵] open page itogi-goda-2015.md
-rw-r--r-- 6.0K Dec 6, 2015 · 3F5DA3C · ~5 min

Impressions of Assassin's Creed Revelations

assassin's creed игры

Assassin's Creed Revelations

Fresh impressions of the next Assassin's Creed game.

[↵] open page vpechatleniya-ot-assassin-s-creed-revelations.md
makoni@arm1:~/blog$ cd ../page-13/ // ← previous cd ./page-15/ // more posts →