Skip to content

Instantly share code, notes, and snippets.

View madcato's full-sized avatar

Dani Vela madcato

View GitHub Profile
@madcato
madcato / GentleActivityIndicatorView.swift
Last active August 6, 2019 06:45
Specialized activity indicator. This class waits some time before showing the activity view.
//
// GentleActivityIndicatorView.swift
// veladan
//
// Created by Daniel Vela Angulo on 19/02/2019.
// Copyright © 2019 veladan. All rights reserved.
//
import UIKit
@madcato
madcato / SpinnerView.swift
Created August 6, 2019 06:36
Activity indicator to indicate wait with a style like the Android one.
//
// SpinnerView.swift
// veladan
//
// Created by Daniel Vela Angulo on 02/04/2019.
// Copyright © 2019 veladan. All rights reserved.
//
import UIKit
//
// DownloadImageView.swift
//
// Created by Daniel Vela on 18/06/2019.
// Copyright © 2019 veladan. All rights reserved.
//
import UIKit
/// Use this class to download an image form an url and present it
@madcato
madcato / backgit.rb
Created May 4, 2019 09:46
Backup each project by cloning all their repositories: clone the main repo and also the wiki repo
#!/usr/bin/env ruby
# Backup each project by cloning all their repositories: clone the main repo and also the wiki repo.
#
# git clone [email protected]:ai/AAI.git
#
# The clone must be done only once. After that use ```git fetch --all``` to refresh all data
#
# - [doc](https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git)
#
@madcato
madcato / text_prepare.py
Created April 29, 2019 10:14
Function for preparing any text for ML
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
REPLACE_BY_SPACE_RE = re.compile('[/(){}\[\]\|@,;]')
BAD_SYMBOLS_RE = re.compile('[^0-9a-z #+_]')
STOPWORDS = set(stopwords.words('english'))
def text_prepare(text):
"""
// This is the way to create an almost-singleton class and allow replace for testing.
// The difference from a real singleton is in the type of property to store the instance:
// it's declared 'var' allowing to substitute the instace, instead using a 'let' property
// as it would be a real singleton. It works for testing
class Singleton {
static var shared = { Singleton()}()
}
// If you don't want to inherit from the Singleton class,
// 1
view.backgroundColor = .clear
// 2
let blurEffect = UIBlurEffect(style: .light)
// 3
let blurView = UIVisualEffectView(effect: blurEffect)
// 4
blurView.translatesAutoresizingMaskIntoConstraints = false
view.insertSubview(blurView, at: 0)
@madcato
madcato / Singleton.swift
Created July 19, 2018 08:49
Swift singleton sample
final class Manager {
static let shared = Manager()
private init() { ... }
func foo() { ... }
}
@madcato
madcato / exclude
Created April 18, 2018 06:36
Ignore files for Xcode projects, set in .git/info/exclude
.DS_Store
UserInterfaceState.xcuserstate
@madcato
madcato / String+subscript.swift
Created April 3, 2018 07:36
String extension to manage substrings
extension String {
subscript (i: Int) -> Character {
return self[index(startIndex, offsetBy: i)]
}
subscript (bounds: CountableRange<Int>) -> Substring {
let start = index(startIndex, offsetBy: bounds.lowerBound)
let end = index(startIndex, offsetBy: bounds.upperBound)
return self[start ..< end]
}
subscript (bounds: CountableClosedRange<Int>) -> Substring {