Skip to content

Instantly share code, notes, and snippets.

@rbaulin
rbaulin / gist:5534334
Created May 7, 2013 17:12
Tapjoy possible Publisher SDK API improvements
Now API looks like this:
- (void)getTapPoints;
- (void)spendTapPoints;
Here is how it would be absolutely awesome:
- (void)getTapPointsCompletion:(void (^)(TapjoyConnect *tj, NSUInteger tapPoints, NSError *error))completionBlock;
- (void)spendTapPoints:100 completion:(void (^)(TapjoyConnect *tj, NSError *error))completionBlock;
So, I could use it like this:
.. code ..
@rbaulin
rbaulin / colorizeViewStack.m
Last active December 17, 2015 17:49
Colorize view stack, useful for frame inspection
// example: [self colorizeStack:self.view];
- (void)colorizeStack:(UIView *)view {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:0.8];
view.backgroundColor = color;
for (UIView *subView in view.subviews) {
@rbaulin
rbaulin / multilineLabel.m
Last active December 17, 2015 18:09
Label with multiple lines, constrained to width. Use with -sizeToFit.
@interface MultilineLabel : UILabel
@property (nonatomic) CGFloat maximumWidth;
@end
@implementation MultilineLabel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_maximumWidth = 200;
@rbaulin
rbaulin / ReactiveCocoaPower.m
Last active December 17, 2015 18:29
Find out what is item's URL and load it when ready. Oh yeah, and show me a loading screen if it takes more than 1 second for preparation. And call off the fuss if item has changed. Hell yeah, ReactiveCocoa.
self.currentItem = item;
RACSignal *itemChanged = [[RACObserve(self, currentItem) skip:1] take:1];
// prepare item until switched to other item
RACSignal *itemReady = [[item rac_prepareItem] takeUntil:itemChanged];
// show description if preparation takes more than 1 second
[[[[[RACSignal interval:1.] take:1]
takeUntil:itemReady]
deliverOn:[RACScheduler mainThreadScheduler]]
@rbaulin
rbaulin / macros.h
Last active December 25, 2015 11:09
Urgent macros
#define IS_7_0 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_PHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#ifdef DEBUG
# define LOG_MESSAGE(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@rbaulin
rbaulin / ps_build_icons.js
Last active February 22, 2016 13:56
Create icon pack for iOS or Android devices. Recommended source image size is 1024x1024 px 72 dp, make sure visible layer is selected. Workflow: source image is flattened, bicubic resize applied for each size, results saved in /output folder in source directory. Best practice: create photoshop Action with script, bind it to some hotkey.
// Created by Roman Baulin on 17.05.2012
#target photoshop
// in case we double clicked the file
app.bringToFront();
var doc = app.activeDocument;
var startState = doc.activeHistoryState; // save for undo
var initialPrefs = app.preferences.rulerUnits; // will restore at end
@rbaulin
rbaulin / UIImage+ImageEffects.h
Last active January 9, 2017 09:38
UIImage+ImageEffects.m presented on WWDC 2013
/*
File: UIImage+ImageEffects.h
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
Version: 1.0
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
@import UIKit;

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
#
# (c) Baulin Roman 2015
#
# http://stackoverflow.com/questions/1247125/how-to-get-sinatra-to-auto-reload-the-file-after-each-change
# https://github.com/rtomayko/shotgun
# sse http://www.w3schools.com/html/html5_serversentevents.asp
# sse with sinatra http://stackoverflow.com/questions/5227431/html5-server-sent-events-with-ruby-sinatra
# cool demo https://gist.github.com/rkh/1476463
#
// crash and exceptions in google analytics are stripped and all wrong
// but action and label can be delivered in full length
//
// send formatted string w/o params in action (as unique error name)
// will show up count in realtime dashboard under category err
//
// send formatted string w/ params in label (as error description)
// can be inspected and queryied in behaviour -> events -> overview -> err
//
// sample: TRACK_ERR(@"audiosession error %@", error)