Skip to content

Instantly share code, notes, and snippets.

View cemolcay's full-sized avatar
🎼
🎶

Cem Olcay cemolcay

🎼
🎶
View GitHub Profile
@cemolcay
cemolcay / swiftJsonReq
Last active October 5, 2015 01:52
swift json request
func json (url: String, response: (AnyObject, NSError?) -> Void) {
NSURLConnection.sendAsynchronousRequest(NSURLRequest(URL: NSURL(string: url)), queue: NSOperationQueue.currentQueue(), completionHandler:{response, data, error in
var jsonError : NSError?
var json : AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: &jsonError)
response (json, jsonError)
})
}
/* usage
json("http://www.someurl.com/some/json", {jsonObj, error in
//#include "unistd.h"
//#include "netdb.h"
- (BOOL)isNetworkAvailable {
char *hostname;
struct hostent *hostinfo;
hostname = "google.com";
hostinfo = gethostbyname (hostname);
if (hostinfo == NULL){
NSLog(@"-> no connection!\n");
- (CCSprite*)spriteWithSize:(CGSize)size andColor:(ccColor4B)color
{
CCSprite *sprite = [CCSprite node];
GLubyte *buffer = malloc(sizeof(GLubyte)*4);
for (int i=0;i<4;i++) {buffer[i]=255;}
CCTexture *tex = [[CCTexture alloc] initWithData:buffer pixelFormat:CCTexturePixelFormat_RGBA4444 pixelsWide:1 pixelsHigh:1 contentSizeInPixels:size contentScale:1];
[sprite setTexture:tex];
[sprite setTextureRect:CGRectMake(0, 0, size.width, size.height)];
free(buffer);
[sprite setColor:[CCColor colorWithCcColor4b:color]];
@cemolcay
cemolcay / AutoSizedTableViewController
Created December 25, 2014 07:21
iOS 8 AutoSized Table View in Swift
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var dataSource: [String] = []
var table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
for _ in 0...10 {
extension String {
subscript (i: Int) -> String {
return String(Array(self)[i])
}
}
extension UILabel {
func addAttributedString (text: String, color: UIColor, font: UIFont) {
var string = self.text == nil ? "" : self.text!
let newString = string + text
let range = NSRange(location: countElements(string), length: countElements(text))
var att: NSMutableAttributedString?
if let a = self.attributedText {
att = NSMutableAttributedString (attributedString: a)
@cemolcay
cemolcay / swift string array search
Created January 9, 2015 13:37
filters the dataSource with searchText
@cemolcay
cemolcay / readme build box cheat sheet
Last active August 29, 2015 14:14
readme build box cheat sheet
[![Build Status](https://travis-ci.org/facebook/AsyncDisplayKit.svg)](https://travis-ci.org/facebook/AsyncDisplayKit)
[![Version](http://img.shields.io/cocoapods/v/AsyncDisplayKit.svg)](http://cocoapods.org/?q=AsyncDisplayKit)
[![Platform](http://img.shields.io/cocoapods/p/AsyncDisplayKit.svg)]()
@cemolcay
cemolcay / circleBlurMask.swift
Last active April 23, 2018 06:17
blurred screen with circle mask
@IBOutlet var mapView: MKMapView!
func setupMapBlur () {
var blur: UIView!
if ios8() {
blur = UIVisualEffectView (effect: UIBlurEffect (style: UIBlurEffectStyle.Light))
} else {
blur = FXBlurView (frame: view.frame)
}
@cemolcay
cemolcay / ASDisplayNodeDraw
Created February 19, 2015 12:24
ASDisplayNode draw shadow & border
override class func drawRect(
bounds: CGRect,
withParameters parameters: NSObjectProtocol!,
isCancelled isCancelledBlock: asdisplaynode_iscancelled_block_t!,
isRasterizing: Bool) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context)
CGContextSetShadowWithColor(context, CGSize (width: 0, height: 1), 10, UIColor.TitleColor().CGColor)