Skip to content

Instantly share code, notes, and snippets.

View dimpiax's full-sized avatar
💭
better than last action

Dmytro Pylypenko dimpiax

💭
better than last action
  • Barcelona, Spain
View GitHub Profile
@dimpiax
dimpiax / prequest.js
Created March 5, 2017 22:12
request library with promise wrapped under ES6 with flowtype
/* @flow */
import request from 'request'
const promiseWrapper = (r: request): ((data: any) => Promise<Object>) =>
(data: any): Promise<Object> => new Promise((resolve: any, reject: any) => {
r(data, (error: any, response: any, body: any) => {
if (error) reject(error)
else resolve(body)
})
{
"id": "24b47a79-c124-40ac-8bd0-25ae5ea24767",
"created_date": "28.10.2016",
"lastmodified_date": "28.10.2016",
"data": {
"step_0": {
"declarationType": "1",
"declarationYear1": "2015"
},
"step_1": {
{
"id": "edfd42c4-ba78-47da-8a8c-5924a017e807",
"created_date": "05.12.2016",
"lastmodified_date": "05.12.2016",
"data": {
"step_0": {
"changesYear": "2016"
},
"step_1": {
"lastname": "Посвистак",
{
"id": "3371ace7-177b-44d6-ba2a-53e023f740be",
"created_date": "30.10.2016",
"lastmodified_date": "30.10.2016",
"data": {
"step_0": {
"declarationType": "1",
"declarationYear1": "2015"
},
"step_1": {
let input = [
"1 1 1 0 0 0",
"0 1 0 0 0 0",
"1 1 1 0 0 0",
"0 0 2 4 4 0",
"0 0 0 2 0 0",
"0 0 1 2 4 0"
]
let scanner = [
{
"id": "3371ace7-177b-44d6-ba2a-53e023f740be",
"created_date": "30.10.2016",
"lastmodified_date": "30.10.2016",
"data": {
"step_0": {
"declarationType": "1",
"declarationYear1": "2015"
},
"step_1": {
@dimpiax
dimpiax / declaration_example.js
Last active October 31, 2016 22:33
Ukraine's declaration parser example (part)
// link to declaration.json – https://public-api.nazk.gov.ua/v1/declaration/41462809-89e2-4ad9-a9c9-54bb258541df
// usage: node declaration_example.js
'use strict';
var fs = require('fs');
function init() {
let file = fs.readFileSync('declaration.json');
let json = JSON.parse(file);
@dimpiax
dimpiax / UIImage+.swift
Last active October 31, 2016 08:04
Get remote or default image
// somewhere in your class
// where you have declared instance of UIImageView as _imageView
func test() {
UIImage.getRemote(path: "path_to_image", default: "image_name") {[weak self] value in
DispatchQueue.main.async {[weak self] in
guard let s = self else { return }
s._imageView.image = value
s._imageView.sizeToFit()
}
@dimpiax
dimpiax / NSDate+.swift
Last active April 7, 2016 20:51
Conversion timestamp to simple phrase interval
extension NSDate {
class func relativeTimeInString(value: NSTimeInterval) -> String {
func getTimeData(value: NSTimeInterval) -> (count: Int, suffix: String) {
let count = Int(floor(value))
let suffix = count != 1 ? "s" : ""
return (count: count, suffix: suffix)
}
let value = -value
switch value {
import Foundation
extension NSUserDefaults {
func removeAllKeys(except except: [String]? = nil) {
guard let appDomain = NSBundle.mainBundle().bundleIdentifier else { return }
let defaults = NSUserDefaults.standardUserDefaults()
var dict: [String: AnyObject]?
if let except = except {