Skip to content

Instantly share code, notes, and snippets.

func stringByStrippingHTMLElementsWithRegex() -> String {
let trimmedString = self.stringByReplacingOccurrencesOfString("<[^>]+>", withString: "", options: .RegularExpressionSearch, range: nil)
let trimmedStringFromNewLine = trimmedString.stringByReplacingOccurrencesOfString("\n", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
let trimmedStringFromWhiteSpaces = trimmedStringFromNewLine.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
return trimmedStringFromWhiteSpaces
}
func stringByStrippingHTMLElementsNativeWay() -> String {
let encodedData = self.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
]
var attributedString: NSAttributedString?
do {
attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
<ul>
<li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.Cras consequat.</li>
<li>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</li><li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li><li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li>
</ul>
struct User {
let first: String? //optional with value
let last: String? //optional with wrong key
let headline: String? //optional with null
let isEmployee: Bool // boolean
let employeeLevel: EmployeeLevel //enum
let socialProfiles: [SocialProfile] //array
let friendId: Int //nested property
}
{
"firstname": "Wayne",
"lastname": "Walsh",
"headline": null,
"isEmployee": true,
"employee_level": "junior",
"resume_url": "https://workable.com",
"friends": {
"id": 10
},
// For models that are ALREADY Swift.Decodable and want to be used inside Argo decodable models
protocol SwiftToArgoDecodable: Argo.Decodable, Swift.Decodable where Self.DecodedType == Self {}
extension SwiftToArgoDecodable {
static func decode(_ json: JSON) -> Decoded<DecodedType> {
do {
let jsonData = try JSONSerialization.data(withJSONObject: json.JSONObject(), options: [])
let decodedValue = try JSONDecoder().decode(Self.self, from: jsonData)
return .success(decodedValue)
} catch let error {
// For models that are ALREADY Argo decodable and want to be used inside Swift decodable models
protocol ArgoToSwiftDecodable: Argo.Decodable where Self.DecodedType == Self, Self: Swift.Decodable{}
extension ArgoToSwiftDecodable {
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let json = try container.decode(JSON.self)
self = try Self.decode(json).dematerialize()
}
}
extension Argo.JSON: Swift.Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let value = try? container.decode(String.self) {
self = .string(value)
} else if let value = try? container.decode(Int.self) {
self = JSON.number(value as NSNumber)
} else if let value = try? container.decode(Double.self) {
self = JSON.number(value as NSNumber)
} else if let value = try? container.decode(Bool.self) {
extension User: Swift.Decodable {}
extension User: ArgoToSwiftDecodable {
static func decode(_ json: JSON) -> Decoded<User> {
return curry(self.init)
<^> json <|? "firstname"
<*> json <|? "lastname"
<*> json <|? "headline"
<*> json <| "isEmployee"
<*> json <| "employee_level"
<*> json <|| "social_profiles"
@elenipapanik
elenipapanik / Deploy.groovy
Last active September 10, 2020 12:07
Deploy.groovy - version1
def deploy() {
stage('Checkout') {
checkout scm
}
stage('Install dependencies') {
sh 'gem install bundler'
sh 'bundle update'
sh 'bundle exec pod repo update'