Skip to content

Instantly share code, notes, and snippets.

#import <Foundation/Foundation.h>
@interface NSMutableURLRequest (KDJBasicAuthentication)
// Sets the "Authorization" HTTP header to a basic authentication value
// with Base64-encoded username and password. This overwrites any existing
// value for this header.
- (void)setAuthorizationHeaderWithUsername:(NSString *)username
password:(NSString *)password;
#import <UIKit/UIKit.h>
@interface ViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *data;
@property (nonatomic, strong) NSMutableArray *sectionTitles;
@end
alias longestFiles='find . -name \*.m -not -path "./Pods/*" -exec wc -l {} \; | sort | tail'
alias avgFilesLong="find . -name \*.m -not -path './Pods/*' -exec wc -l {} \; | awk '{ total += \$1; count++} END { print total/count }'"
alias toLongFiles="find . -name \*.m -not -path './Pods/*' -exec wc -l {} \; | sort | awk 'BEGIN{ count = 0; } { if (\$1 > 300){ print \$0; count++}} END { print \" \" count \" files long over 300 lines\" }'"
#contentArea {
width:850px!important;
}
._4-u2,._5x16 ._5inf::after,._6l-:after, ._4_w3::after, ._5va1, .timelineUnitContainer, .timelineReportContainer, ._4lh .fbTimelineCapsule .timelineUnitContainer, ._4lh ._1xz, ._1xw:hover ._1xz, ._4lh ._1xw, .UFIReplyList .UFIRow, ._5vsj .UFIReplyList .UFIComponent.UFILastComponent:after, ._5vsj .UFIReplyList .UFIComponent.UFIFirstComponent:after {
border:0!important;
border-left: none!important;
border-right:none!important;
-webkit-box-shadow: none!important;
}
// returns a MKCoordinateRegion that encompasses an array of MKAnnotations
- (MKCoordinateRegion)regionForAnnotations:(NSArray *)annotations {
CLLocationDegrees minLat = 90.0;
CLLocationDegrees maxLat = -90.0;
CLLocationDegrees minLon = 180.0;
CLLocationDegrees maxLon = -180.0;
for (id <MKAnnotation> annotation in annotations) {
@MaciejGad
MaciejGad / updateXcodePlugins.sh
Created July 1, 2015 09:30
update Xcode plugins
#!/bin/bash
xcodeUUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
echo $xcodeUUID
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add $xcodeUUID
if [ "$CONFIGURATION" = "Ad hoc" ] || [ "$CONFIGURATION" = "Release" ]; then
echo "Bumping build number..."
plist=${PROJECT_DIR}/${INFOPLIST_FILE}
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "No build number in $plist"
exit 2
fi
@MaciejGad
MaciejGad / hanoi.swift
Last active October 6, 2018 23:49
Simple implementation of hanoi algorithm. If you want more information about this algorithm watch this video https://www.youtube.com/watch?v=3YH0SZYAzOQ
enum Tower:String {
case A
case B
case C
}
func hanoi(_ disk: Int, from: Tower, using: Tower,
to: Tower, output: inout [String]) {
if disk == 1 {
output.append("\(from.rawValue)->\(to.rawValue)")
@MaciejGad
MaciejGad / file.m
Last active April 14, 2016 19:38
Set image with URL
//remember to intall AFNetworking https://github.com/AFNetworking/AFNetworking#installation-with-cocoapods
//and add import :
//#import "UIImageView+AFNetworking.h"
- (void)setImageFromDictionary:(NSDictionary *)dic2 {
NSString *path = dic2[@"safe_value"];
if (![path isKindOfClass:[NSString class]]) {
return;
}
NSURL *imageUrl = [NSURL URLWithString:path];
@MaciejGad
MaciejGad / NSImageExtensions.swift
Created March 24, 2017 11:49
NSImage extensions for easy resizing, cropping and saving png images. Version updated for Swift 3. Originally by Raphael Hanneken https://gist.github.com/raphaelhanneken/cb924aa280f4b9dbb480
extension NSImage {
/// Returns the height of the current image.
var height: CGFloat {
return self.size.height
}
/// Returns the width of the current image.
var width: CGFloat {
return self.size.width