Skip to content

Instantly share code, notes, and snippets.

View unboxme's full-sized avatar
🎮
Remote

Pavel Puzyrev unboxme

🎮
Remote
  • Nicosia, Cyprus
View GitHub Profile
@unboxme
unboxme / CaseNameable.swift
Last active February 21, 2023 13:28
Allows to map enum to another using raw "case name"
import Foundation
/// Allows to map enum to another using raw "case name".
///
/// Let's say there are 2 enums such as `GenericEnum` (each case of that may have arguments)
/// and `PlainEnum` (each case of that are representable by a string):
///
/// enum GenericEnum<T>: CaseNameable {
/// case generic(value: T) // caseName == "generic"
/// case exact(Int) // caseName == "exact"
@unboxme
unboxme / FadingView.m
Created January 11, 2018 20:24
Fading view edges
IB_DESIGNABLE
@interface FadingView ()
@property (assign, nonatomic) IBInspectable BOOL verticalFade;
@property (assign, nonatomic) IBInspectable BOOL horizontalFade;
@end
@implementation FadingView
@unboxme
unboxme / terminal | p12 to PEM
Last active September 26, 2016 14:28
p12 to PEM
openssl pkcs12 -in NAME.p12 -out NAME.pem -nodes -clcerts 
@unboxme
unboxme / EnumValueToString.m
Created August 13, 2016 12:03
Returns string from enum value
enum {
ObjectiveC = 'ObjC',
Java = 'Java',
Ruby = 'Ruby'
} Language;
- (NSString *)stringFromEnumValue:(NSUInteger)enumValue {
char *str = calloc(sizeof(enumValue) + 1, sizeof(char));
int integer = NSSwapInt((unsigned int) enumValue);
memcpy(str, (const void *) &integer, sizeof(integer));
@unboxme
unboxme / TextViewLines.m
Created July 18, 2016 17:20
Get amount of lines in UITextView without considering maximum lines, content size and etc.
- (NSUInteger)linesForTextView:(UITextView *)textView {
NSLayoutManager *layoutManager = [textView layoutManager];
NSUInteger numberOfLines, index, numberOfGlyphs = [layoutManager numberOfGlyphs];
NSRange lineRange;
for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++) {
[layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];
index = NSMaxRange(lineRange);
}
return numberOfLines;