Skip to content

Instantly share code, notes, and snippets.

@danie7k
danie7k / switch-string.m
Last active February 9, 2017 09:16
iOS Objective-C switch with string
NSString *testedString;
__block NSString *selected;
((void (^)())@{
@"A" : ^{
selected = @"A selected";
},
@danie7k
danie7k / snapshot.m
Last active January 15, 2022 02:18
iOS Objective-C screenshot
- (UIImage *)snapshot:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@danie7k
danie7k / user-command.sh
Created November 22, 2016 16:51
Run console command as another user
sudo -H -u www-data git status
func roundImage(image: Image) -> Image? {
let rect = CGRect(origin:CGPoint(x: 0, y: 0), size: image.size)
UIGraphicsBeginImageContextWithOptions(image.size, false, 0.0)
UIBezierPath(roundedRect: rect, cornerRadius: self.cornerRadius).addClip()
image.draw(in: rect)
let roundedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return roundedImage
}
import UIKit
typealias GradientPoints = (startPoint: CGPoint, endPoint: CGPoint)
enum GradientOrientation {
case horizontal
case vertical
var startPoint: CGPoint {
return points.startPoint
import UIKit
extension UIColor {
convenience init(hex: Int, alpha: CGFloat = 1.0) {
self.init(
red: CGFloat((hex >> 16) & 0xFF) / 255.0,
green: CGFloat((hex >> 8) & 0xFF) / 255.0,
blue: CGFloat(hex & 0xFF) / 255.0,
alpha: alpha
func fixPerformance() {
if (self.cornerRadius > 0) {
self.masksToBounds = false
self.shouldRasterize = true
self.rasterizationScale = UIScreen.main.scale
}
if (self.shadowRadius > 0) {
self.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.cornerRadius).cgPath
}
extension CGPath {
func forEach( body: @convention(block) (CGPathElement) -> Void) {
typealias Body = @convention(block) (CGPathElement) -> Void
let callback: @convention(c) (UnsafeMutableRawPointer, UnsafePointer<CGPathElement>) -> Void = { (info, element) in
let body = unsafeBitCast(info, to: Body.self)
body(element.pointee)
}
print(MemoryLayout.size(ofValue: body))
let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
CFNETWORK_DIAGNOSTICS 3
OS_ACTIVITY_MODE disable
@danie7k
danie7k / text-image.m
Created February 14, 2018 14:37
Text around image
UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
self.textView.textContainer.exclusionPaths = @[imgRect];