Skip to content

Instantly share code, notes, and snippets.

@bleft
bleft / Data+Extension.swift
Created December 14, 2016 13:19
get md5 hash from Data in swift
extension Data {
var md5 : String {
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
_ = self.withUnsafeBytes { bytes in
CC_MD5(bytes, CC_LONG(self.count), &digest)
}
var digestHex = ""
for index in 0..<Int(CC_MD5_DIGEST_LENGTH) {
digestHex += String(format: "%02x", digest[index])
}
@bleft
bleft / docker-compose.yml
Created February 17, 2022 07:21
Run Wordpress with MySQL in Docker - start with: docker-compose up -d
version: "3.8"
services:
db:
image: mysql:latest
volumes:
- ./db/data:/var/lib/mysql
ports:
- "3306:3306"
restart: always
@bleft
bleft / UIButton+Extension.swift
Last active March 12, 2021 19:04
UIButton with centered Image and Text
// with the help of: https://gist.github.com/phpmaple/9458264
extension UIButton {
func centerImageAndButton(_ gap: CGFloat, imageOnTop: Bool) {
guard let imageView = self.imageView,
let titleLabel = self.titleLabel else { return }
let sign: CGFloat = imageOnTop ? 1 : -1;
let imageSize = imageView.frame.size;
@bleft
bleft / customErrors.swift
Last active April 29, 2020 12:32
custom enum errors with localizedDescription
// sepcifiy your errors
enum MyCustomError : Error {
case customError
case missingProperty
var localizedDescription: String {
switch self {
case .urlCouldNotBeCreated:
return NSLocalizedString("MyCustomErrorCcustomError", value: "a localized error message", comment: "")
case .missingProperty:
@bleft
bleft / MySQL.sql
Last active November 12, 2019 12:07
SELECT DATE_FORMAT(FROM_UNIXTIME(`date`), '%e %b %Y %H:%m:%s') AS created, temp, humid FROM `table_name` ORDER BY id DESC LIMIT 1;
@bleft
bleft / AppList.md
Created May 13, 2019 12:32
Software for new Macs

Software for new Macs

  • 1Password
  • Xcode
  • bear
  • homebrew
  • intelliJ IDEA
  • iXLIFF
  • Tweetbot
  • TextMate
  • Gimp
@bleft
bleft / string+extenstion.swift
Created February 28, 2019 12:20
check for valid email
extension String {
var isValidEmail: Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluate(with: self)
}
}
@bleft
bleft / UIImage+Extension.swift
Last active March 6, 2018 14:18
resize UIImage
extension UIImage {
/**
returns an UIImage with the given height
**/
func resizedImage(newHeight: CGFloat) -> UIImage {
let scale = newHeight / self.size.height
let newWidth = self.size.width * scale
UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
self.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
@bleft
bleft / GradientView.swift
Last active January 19, 2018 13:09
UIView with CAGradient
class MyView: UIView {
private let gradient = CAGradientLayer()
override func draw(_ rect: CGRect) {
super.draw(rect)
gradient.colors = [UIColor.red.cgColor, UIColor.blue.cgColor] // beliebig viele Farben für den Verlauf einstellen
gradient.startPoint = CGPoint(x: 0, y: 0) // über start und endPoint kann die Richtung des Verlaufes verändert werden.
gradient.endPoint = CGPoint(x: 0, y: 1)
@bleft
bleft / checkIP.sh
Created December 12, 2017 10:06
check server IP from outside
wget -qO- http://checkip.dyndns.org | sed -e 's/^.*s: //' -e 's_</b.*$__'