Skip to content

Instantly share code, notes, and snippets.

Oleksandr Bezpalchuk TramPamPam

Block or report user

Report or block TramPamPam

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
View URLSession.swift
import Cocoa
let session = URLSession(configuration: URLSessionConfiguration.default)
var getTask = URLSessionTask()
var request = URLRequest(url: URL(string: "https://itunes.apple.com/search?term=jack+johnson&limit=25")!)
request.httpMethod = "GET"
getTask = session.dataTask(with: request, completionHandler: { (data, response, error) in
debugPrint("(data \(data != nil), response \(response), error \(response)")
View HighlightString.swift
private func highlight(_ substring: String, in string: String, color: UIColor = UIColor(named: "Blue")!) -> NSAttributedString {
let defaultAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14.0),
NSAttributedString.Key.foregroundColor: UIColor.white]
let text = NSMutableAttributedString(string: string, attributes: defaultAttributes)
if let fillableRange = string.nsRange(of: substring) {
text.addAttribute(NSAttributedString.Key.font, value: UIFont.boldSystemFont(ofSize: 14.0), range: fillableRange)
text.addAttribute(NSAttributedString.Key.underlineColor, value: color, range: fillableRange)
text.addAttribute(NSAttributedString.Key.underlineStyle, value: 1, range: fillableRange)
View Decodable+Dictionary.swift
extension KeyedDecodingContainer {
func decode(_ type: [String: Any].Type, forKey key: K) throws -> [String: Any] {
let container = try self.nestedContainer(keyedBy: JSONCodingKeys.self, forKey: key)
return try container.decode(type)
}
func decodeIfPresent(_ type: [String: Any].Type, forKey key: K) throws -> [String: Any]? {
guard contains(key) else {
return nil
View CoreData-Homework.md

CoreData

Створити простий додаток який використовує Core Data для зберігання данних.

  • В приорітеті реалізувати додавання і видалення записів, редагування як бонус.
  • На вибір дається три завдання, тобто в кожного буде ідивідуальне завдання, обирати однакові теми не допустимо.
  • Завдання даються з прицілом на самостійний R&D, тому не даються ні повні описи структур ні типів і т.д.
  • Приклади допустимих запитів описують потенційно допустимі зв'язки між сущностями, а не являються такими які обов'язково треба реалізувати в такому вигляді в якому вони описані.

Теми

@TramPamPam
TramPamPam / Push info
Last active May 29, 2018
AppDelegate.swift
View Push info
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if let userInfo = launchOptions?[.remoteNotification] as? [AnyHashable: Any] {
// Parsed notification here
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "openPush"), object: nil, userInfo: userInfo)
} else {
// Ordinary opened app
}
return true
}
View Chainable.swift
protocol Chainable {
var id: String? { get set }
var afterId: String? { get set }
}
extension Array where Element: Chainable {
func chained() -> [Element] {
let ids: [String] = self.flatMap{ return $0.id ?? "-1" }
let afterIds: [String] = self.flatMap{ return $0.afterId ?? "-1" }
View GradientView.swift
import UIKit
@IBDesignable
class GradientView: RoundedView {
@IBInspectable var from: UIColor! = UIColor.init(colorLiteralRed: 255.0/64.0, green: 255.0/164.0, blue: 255.0/196.0, alpha: 1)
@IBInspectable var to: UIColor! = UIColor.init(colorLiteralRed: 255.0/59.0, green: 255.0/88.0, blue: 255.0/152.0, alpha: 1)
@IBInspectable var vertical: Bool = false
@IBInspectable var rounded: Bool = false {
didSet {
View CorneredButton.swift
@IBDesignable
class CorneredButton: UIButton {
@IBInspectable var radius: CGFloat = 2.0
@IBInspectable var border: CGFloat = 0.0
var corners: UIRectCorner? = .allCorners
override func layoutSubviews() {
super.layoutSubviews()
@TramPamPam
TramPamPam / RepeatingAlphabeth.py
Last active Nov 24, 2016
Getting acquaintance with 'def' in Python
View RepeatingAlphabeth.py
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
alphabetLength = len(alphabet)
def get_alphabet_till(length):
# Validate input
# 1) Check for type:
if not (type(length) is int): #type of length must be int
return "Sorry, I expect int"
# 2) Check range:
if length > alphabetLength: #length should be equal or less of letters count
View TypeConvertions.py
# type checks
# Hello World program in Python
from datetime import datetime, date, time
print("Hello World!\n")
today = datetime.now()
#this is func that prints "Awesome"
def print_me():
print("Awesome")
f = print_me
You can’t perform that action at this time.