Skip to content

Instantly share code, notes, and snippets.

:octocat:
Building Stuff

Daniele Margutti malcommac

:octocat:
Building Stuff
Block or report user

Report or block malcommac

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 regex_c.c
sqlite3_create_function(dbSqlitez, "regexp", 2, SQLITE_ANY, NULL, &sqlite_regexp, NULL, NULL);
...
...
static void sqlite_regexp(sqlite3_context* context, int argc, sqlite3_value** values) {
if ( argc < 2 ) {
sqlite3_result_error(context, "SQL function regexp() called with missing arguments.", -1);
return;
}
View ImageSizeFetcherExample.swift
let imageURL: URL = ...
fetcher.sizeFor(atURL: $0.url) { (err, result) in
// error check...
print("Image size is \(NSStringFromCGSize(result.size))")
}
View ImageFetcherParser.swift
import UIKit
/// Errors generated by the parser.
///
/// - unsupportedFormat: unsupported image format.
/// - network: network error
public enum ImageParserErrors: Error {
case unsupportedFormat
case network(_: Error?)
}
@malcommac
malcommac / ImageFetcherOperation.swift
Last active Sep 9, 2018
ImageFetcherOperation.swift
View ImageFetcherOperation.swift
import UIKit
internal class ImageSizeFetcherOp: Operation {
/// Callback to call at the end of the operation
let callback: ImageSizeFetcher.Callback?
/// Request data task
let request: URLSessionDataTask
View ImageFetcher.swift
import UIKit
public class ImageSizeFetcher: NSObject, URLSessionDataDelegate {
/// Callback type alias
public typealias Callback = ((Error?, ImageSizeFetcherParser?) -> (Void))
/// URL Session used to download data
private var session: URLSession!
View ExtendedUIButton.swift
import UIKit
@IBDesignable
class ExtendedUIButton: UIButton {
@IBInspectable var extendedMargin:CGFloat = 30.0
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let area = self.bounds.insetBy(dx: -extendedMargin, dy: -extendedMargin)
return area.contains(point)
View prova.swift
extension UIFont {
func withTraits(traits:UIFontDescriptorSymbolicTraits...) -> UIFont {
let descriptor = self.fontDescriptor()
.fontDescriptorWithSymbolicTraits(UIFontDescriptorSymbolicTraits(traits))
return UIFont(descriptor: descriptor, size: 0)
}
func boldItalic() -> UIFont {
return withTraits(.TraitBold, .TraitItalic)
View richstring_5.swift
let body: Style = Style { ... }
let big: Style = Style { ... }
let attributed: AttributedString = "hello ".set(style: body)
// the following code produce an attributed string by
// concatenating an attributed string and two plain string
// (one styled and another plain).
let attStr = attributed + "\(username)!".set(style:big) + ". You are welcome!"
View richstring_4.swift
let emailPattern = "([A-Za-z0-9_\\-\\.\\+])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]+)"
let style = StyleRegEx(pattern: emailPattern) {
$0.color = UIColor.red
$0.backColor = UIColor.yellow
}
let str = "My email is hello@danielemargutti.com and my website is http://www.danielemargutti.com".(style: style!)
self.label?.attributedText = str
View richstring_3.swift
let str = "Hello <h1>\(username)</h1>\nWelcome <h2>here!<h2>"
self.label?.styledText = str.set(style: StyleNames.myStyòe)
You can’t perform that action at this time.