This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun binarySearch(list: List<Int>, key: Int, min: Int, max: Int): Int { | |
if (max < min) { | |
return -1 | |
} | |
val mid = min + (max - min) / 2 | |
return when { | |
list[mid] > key -> binarySearch(list, key, min, mid - 1) | |
list[mid] < key -> binarySearch(list, key, mid + 1, max) | |
else -> mid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#ifndef ActivityViewController_h | |
#define ActivityViewController_h | |
@interface UIActivityViewController (Private) | |
- (BOOL)_shouldExcludeActivityType:(UIActivity*)activity; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:5.6-apache | |
ENV APP_ROOT /var/www | |
WORKDIR $APP_ROOT | |
RUN apt-get update && apt-get install -y \ | |
libmcrypt-dev | |
RUN docker-php-ext-install pdo_mysql mysqli mcrypt | |
RUN a2enmod vhost_alias && a2enmod rewrite && service apache2 restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum X509Error: Error { | |
case certificateError(message: String) | |
case publicKeyError(message: String) | |
} | |
class X509 { | |
// A DER (Distinguished Encoding Rules) representation of an X.509 certificate. | |
let publicKey: SecKey | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RichTextParser { | |
class func parse(text: String) throws -> NSAttributedString { | |
let colorPattern = "<color=#([\\w]{6})>(.+?)</color>" | |
let attributedText = NSMutableAttributedString() | |
do { | |
let nsText = (text as NSString) | |
let regex = try NSRegularExpression(pattern: colorPattern, options: []) | |
let matches = regex.matches(in: text, options: [], range: NSRange(location: 0, length: nsText.length)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RealmSwift | |
extension Realm { | |
static func truncateAll(`in` realm: Realm) { | |
for objectScheme in realm.schema.objectSchema { | |
if let clazz = Realm.clazz(fromClassName: objectScheme.className) { | |
try! clazz.deleteAll(in: realm) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func colorized(rangeOf: String, color: UIColor, font: UIFont) -> NSAttributedString { | |
let string = self as NSString | |
let range = string.range(of: rangeOf) | |
let attributedText = NSMutableAttributedString(string: self) | |
attributedText.addAttributes([NSForegroundColorAttributeName: color], range: range) | |
attributedText.addAttributes([NSFontAttributeName: font], range: range) | |
return attributedText | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
func decimal() -> String { | |
struct Static { // swiftlint:disable:this nesting cache formatter | |
static var formatter: NumberFormatter! = nil | |
} | |
if Static.formatter == nil { | |
let formatter = NumberFormatter() | |
formatter.numberStyle = .decimal | |
formatter.groupingSeparator = "," |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM amazonlinux | |
WORKDIR /work | |
RUN set -x && \ | |
yum -y install yum-plugin-fastestmirror && \ | |
yum install -y gcc gcc-c++ make git openssl-devel bzip2-devel zlib-devel readline-devel sqlite-devel && \ | |
yum install -y libtiff-devel libjpeg-devel libzip-devel freetype-devel \ | |
lcms2-devel libwebp-devel tcl-devel tk-devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Encode alphanumeric in QR code | |
''' | |
def encode_alphanum(c): | |
if c >= '0' and c <= '9': | |
return ord(c) - ord('0') | |
elif c >= 'A' and c <= 'Z': | |
return ord(c) - ord('A') + 10 | |
elif c == ' ': |
NewerOlder