Skip to content

Instantly share code, notes, and snippets.

@yauhenidrobau
yauhenidrobau / git-reset-author.sh
Created February 2, 2021 08:53 — forked from bgromov/git-reset-author.sh
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
extension UIImage {
private static let defaultThumbSize = CGSize(width: 640, height: 480)
func generatePreview() -> Data? {
guard let imageData = UIImageJPEGRepresentation(self, 0.5) else { return nil }
guard let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil) else { return nil }
guard let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? Dictionary<String, Any> else { return nil }
guard let width = properties[kCGImagePropertyPixelWidth as String] as? Float else { return nil }
guard let height = properties[kCGImagePropertyPixelHeight as String] as? Float else { return nil }
/*Im Macros*/
#define LocalizedString(key, comment) [LanguageUtils getLocalizedStringForKey:(key)]
/*In Language Utils class*/
+ (NSString *)getLocalizedStringForKey:(NSString *)key {
NSString *oldLocalization = [NSBundle.mainBundle localizedStringForKey:(key) value:@"" table:nil];
if (oldLocalization.length > 0) {
return oldLocalization;
}
/// Returns an appropriate size for page thumbnails.
///
/// - Parameters:
/// - pageSize: The page size. Only the aspect ratio is considered, so the units are irrelevant.
/// - containerSize: The size of the container that will display the thumbnails in points.
/// - interitemSpacing: The padding between thumbnails in points.
/// - Returns: An appropriate size for thumbnails in points.
func automaticThumbnailSize(for pageSize: CGSize, containerSize: CGSize, interitemSpacing: CGFloat) -> CGSize {
// What is the total available area?
let containerArea = containerSize.width * containerSize.height
func didTapAttributedText(inLabel label: UILabel?, andInRange range: NSRange?) -> Bool {
guard let range = range, let label = label else {
return false
}
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: label.bounds.size)
let textStorage = NSTextStorage(attributedString: label.attributedText!)
// Configure layoutManager and textStorage
@yauhenidrobau
yauhenidrobau / AZTextFrame.swift
Created June 12, 2018 12:25 — forked from azimin/AZTextFrame.swift
Helper for calculating String and NSAttributedString frame
import UIKit
class AZTextFrameAttributes: NSObject {
// MARK: - Properties
fileprivate(set) var width: CGFloat = 0
fileprivate(set) var string: String?
fileprivate(set) var attributedString: NSAttributedString?
@yauhenidrobau
yauhenidrobau / iOS Community
Created June 12, 2018 12:23 — forked from azimin/iOS Community
iOS Community
ios-channels.ru
digest.mbltdev.ru
bit.ly/podlodka_podcast
vk.com/iosdevcourse
iosgoodreads.ru
vk.com/iosninja
peerlab.community
cocoadevelopers.club
NSString *strCurrentDate;
NSString *strNewDate;
NSDate *date = [NSDate date];
NSDateFormatter *df =[[NSDateFormatter alloc]init];
[df setDateStyle:NSDateFormatterMediumStyle];
[df setTimeStyle:NSDateFormatterMediumStyle];
strCurrentDate = [df stringFromDate:date];
NSLog(@"Current Date and Time: %@",strCurrentDate);
int hoursToAdd = 3;
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
#pragma mark - UIViewControllerAnimatedTransitioning
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext {
return 0.4;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
UIView *container = [transitionContext containerView];
CGAffineTransform transform = CGAffineTransformMakeScale(0.01, 0.01);
func cropedImage(image:UIImage, withFrame frame: CGRect) -> UIImage {
//create drawing context
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0.0)
let context: CGContext? = UIGraphicsGetCurrentContext()
// context?.translateBy(x: frame.size.width, y: frame.size.height)
// // Rotate the image context
//draw
// context?.translateBy(x: -0.5 * frame.size.width, y: -0.5 * frame.size.height)
image.draw(in: CGRect(x: -frame.origin.x, y: -frame.origin.y, width: image.size.width, height: image.size.height))
//capture resultant image