Skip to content

Instantly share code, notes, and snippets.

View r3econ's full-sized avatar

r3econ r3econ

View GitHub Profile
@r3econ
r3econ / gist:e044c00f026c3f47610a
Created July 3, 2015 10:21
NSHTTPCookieStorage (RAFExtensions)
@implementation NSHTTPCookieStorage (RAFExtensions)
- (void)logCookies;
{
NSMutableString *descriptions = [NSMutableString string];
for (NSHTTPCookie *cookie in [self cookies])
{
[descriptions appendString:[self cookieDescription:cookie]];
//
// Created by Rafal Sroka
//
// License CC0.
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any means.
//
@r3econ
r3econ / UIView+AnimationExtensions.h
Created April 22, 2014 20:27
UIView Animation Extensions
//
// Created by Rafal Sroka
//
// License CC0.
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any means.
//
@r3econ
r3econ / gist:9959500
Created April 3, 2014 18:02
Smooth out the CMMotionManager acceleration readings with Low Pass Filter.
- (CMAcceleration)smoothOutAcceleration:(CMAcceleration)acceleration
{
static CGFloat x0 = 0;
static CGFloat y0 = 0;
static CGFloat z0 = 0;
const NSTimeInterval dt = (1.0 / 20);
const double RC = 0.3;
const double alpha = dt / (RC + dt);
@r3econ
r3econ / gist:9953196
Created April 3, 2014 12:09
Posting JSON file using NSURLSession.
// URL of the endpoint we're going to contact.
NSURL *url = [NSURL URLWithString:@"http://localhost:8080/my.json"];
// Create a simple dictionary with numbers.
NSDictionary *dictionary = @{ @"numbers" : @[@1, @2, @3] };
// Convert the dictionary into JSON data.
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dictionary
options:0
error:nil];
@r3econ
r3econ / HTTPServer.py
Created April 2, 2014 20:18
HTTP server deamon in Python. Perfect for testing GET/POST requests.
__author__ = 'Rafał Sroka'
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
# Port on which server will run.
PORT = 8080
class HTTPRequestHandler(BaseHTTPRequestHandler):
@r3econ
r3econ / gist:9923319
Created April 1, 2014 21:12
Downloading JSON file using NSURLSession.
// Create a sample URL.
NSURL *url = [NSURL URLWithString:@"http://www.bbc.co.uk/tv/programmes/genres/drama/scifiandfantasy/schedules/upcoming.json"];
// Create a download task.
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:url
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error)
{
if (!error)
@r3econ
r3econ / UIColor+Random.h
Last active August 29, 2015 13:57
UIColor category for creating a random color.
@interface UIColor (Random)
+ (UIColor *)randomColor;
@end
@r3econ
r3econ / ALAssetsLibrary+VideoOrientation.h
Created March 25, 2014 19:34
ALAssersLibrary category for getting the video's orientation.
@interface ALAssetsLibrary (VideoOrientation)
+ (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset;
@end
@r3econ
r3econ / UIButton+VerticalLayout.h
Last active May 14, 2020 01:30
UIButton category for centering title label and image vertically. The text label is placed below the image.
@interface UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding;
- (void)centerVertically;
@end