-rw-r--r-- 307B Apr 22, 2016 · 4E22F08 · ~1 min

Converting a UTC date with milliseconds from String to NSDate in Swift

swift шпаргалки

To convert a date from text into NSDate from a slightly non-standard format with milliseconds:

let dateString = "2016-04-22T17:42:46.762+03:00"

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

let myDate = dateFormatter.dateFromString(dateString) 
[↵] open page konvertirovanie-utc-daty-s-millisekundami-iz-string-v-nsdate.md
-rw-r--r-- 731B Apr 19, 2016 · 553E35F · ~1 min

CompareShots v1.1

compareshots ios приложения

CompareShots version 1.1 has been released.

What is new: transparency now changes simply by dragging your finger horizontally. One of the users actually asked for this feature in an email. It also makes the transparency change more smoothly.

Besides that, I completely rewrote the app in Swift. So now I have as many as one released project written in it :) But this is only the beginning.

What is surprising is that I submitted the App Store update yesterday, and in less than a day it had already passed Review and been released. I do not remember Apple ever approving an app that fast.

Download

[↵] open page compareshots-v1-1.md
-rw-r--r-- 810B Apr 18, 2016 · E93D4A7 · ~1 min

A log function for Swift that outputs file, method, and line

шпаргалки swift полезное

A cheat-sheet function for logging in Swift:

import Foundation

/**
 A log function that outputs the file, method, and line it was called from. 
 Example usage: DLog("hello")

 - parameter messages: text/objects to print
 - parameter fullPath: path to the calling file
 - parameter line: line number in the file
 - parameter functionName: name of the calling method/function
*/
func DLog(messages: Any..., fullPath: String = #file, line: Int = #line, functionName: String = #function) {
     let file = NSURL.fileURLWithPath(fullPath)
     for message in messages {
          print("\(file.pathComponents!.last!):\(line) -> \(functionName) \(message)")
     }
}

// Example:
DLog("message 1", "message 2")
// YourClass.swift:42 -> someMethod() message 1
// YourClass.swift:42 -> someMethod() message 2
[↵] open page log-funktsiya-dlya-swift-s-vyvodom-fajla-metoda-i-stroki.md
-rw-r--r-- 4.6K Apr 12, 2016 · 6E14506 · ~4 min

Impressions of Assassin's Creed III Liberation

assassin's creed игры

Assassin's Creed III Liberation

[↵] open page vpechatleniya-ot-assassin-s-creed-liberation.md
-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
makoni@arm1:~/blog$ cd ../page-13/ // ← previous cd ./page-15/ // more posts →