Skip to content

Instantly share code, notes, and snippets.

💭
better than last action

Dmytro Pylypenko dimpiax

Block or report user

Report or block dimpiax

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dimpiax
dimpiax / UIFont+.swift
Last active Oct 9, 2017
UIFont's extension which serves FontDescriptor attributes
View UIFont+.swift
//
// UIFont+.swift
// Autofriend
//
// Created by Pilipenko Dima on 10/9/17.
// Copyright © 2017 dimpiax. All rights reserved.
//
import Foundation
import UIKit
@dimpiax
dimpiax / iso8601.swift
Last active Sep 22, 2017
Swift custom date decoder. ISO8601 without milliseconds
View iso8601.swift
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .custom { decoder -> Date in
let valueContainer = try decoder.singleValueContainer()
let value = try valueContainer.decode(String.self)
if let regex = try? NSRegularExpression(pattern: "\\.\\d+", options: []) {
let result = regex.stringByReplacingMatches(in: value, options: [], range: NSRange(location: 0, length: value.count), withTemplate: "")
if let date = ISO8601DateFormatter().date(from: result) {
return date
@dimpiax
dimpiax / promiseUtils.js
Last active Sep 19, 2017
Lite Promise.sync using async/await
View promiseUtils.js
const next = async (it, callback) => {
const { value, done } = it.next()
if (done) return []
const result = await callback(value)
const nextResult = await next(it, callback)
return [result, ...nextResult]
}
const sync = async (value, callback) => {
@dimpiax
dimpiax / Optional+.swift
Created Jul 17, 2017
Optional Bool shortcut
View Optional+.swift
extension Optional where Wrapped == Bool {
var bool: Bool {
switch self {
case .some(let value): return value == true
case .none: return false
}
}
}
var foo: Bool? = true
@dimpiax
dimpiax / prequest.js
Created Mar 5, 2017
request library with promise wrapped under ES6 with flowtype
View prequest.js
/* @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)
})
View 24b47a79-c124-40ac-8bd0-25ae5ea24767.json
{
"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": {
View updated_declaration.json
{
"id": "edfd42c4-ba78-47da-8a8c-5924a017e807",
"created_date": "05.12.2016",
"lastmodified_date": "05.12.2016",
"data": {
"step_0": {
"changesYear": "2016"
},
"step_1": {
"lastname": "Посвистак",
View declaration.json
{
"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": {
View HourglassScanner.swift
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 = [
View gist:ae7b2be13ff0a7946ecdab8c5204fe53
{
"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": {
You can’t perform that action at this time.