Skip to content

Instantly share code, notes, and snippets.

@bleft
bleft / NSMutableString+Utils.m
Created March 11, 2014 12:16
NSMutableString: appendStringOrEmpty
- (void)appendStringOrEmpty:(NSString*)string{
if (string) {
[self appendString:string];
} else {
[self appendString:@""];
}
}
@bleft
bleft / imageFromView.m
Last active August 29, 2015 13:59
UIImage from View
+ (UIImage *)imageFromView:(UIView *)view
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] == 2.0) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 2.0);
} else {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
}
} else {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
@bleft
bleft / sharedInstance.m
Created July 3, 2014 12:33
create singleton dispatch_once_t
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@bleft
bleft / maxNumbersOfLines.m
Created July 22, 2014 14:40
set maximum number of lines on UITextView
// the following snippet sets the number of lines to 1
myTextView.attributedText = [[NSAttributedStringalloc] initWithString:@"my too long text"];
myTextView.textContainer.maximumNumberOfLines = 1;
myTextView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
@bleft
bleft / gist:c9ae29f3cd51ea439c63
Created September 24, 2014 14:34
colors in terminal: .bash_profile
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
@bleft
bleft / roundView.swift
Created October 17, 2014 10:46
Make round UIView
let layer = view.layer
layer.cornerRadius = CGRectGetWidth(mapView.bounds) / 2
layer.borderWidth = 1
layer.masksToBounds = true
@bleft
bleft / terminal defaults
Last active August 29, 2015 14:15
terminal copy without text attributes
kopieren als reiner Text:
defaults write com.apple.Terminal CopyAttributesProfile com.apple.Terminal.no-attributes
und wieder aktivieren:
defaults write com.apple.Terminal CopyAttributesProfile com.apple.Terminal.attributes
@bleft
bleft / php.ini
Created May 13, 2015 15:14
php ini with XDebug
[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=On
xdebug.remote_port=9000
xdebug.profiler_enable_trigger=1
xdebug.max_nesting_level=250
@bleft
bleft / gist:e88cfe0d7504ab725f76
Created June 23, 2015 13:46
remove special characters from string for save text input
function strippedString(OriginalString){
var newString = OriginalString.replace(/\?/g,'?');
newString = newString.replace(/(<([^>]+)>)/ig,"");
return newString;
}
@bleft
bleft / ViewUp.swift
Created June 26, 2015 10:41
move hidden text fields up if keyboard appears
public override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardWillShow:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardWillHide:", name: UIKeyboardDidHideNotification, object: nil)
}
public override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self)
}