Skip to content

Instantly share code, notes, and snippets.

View k06a's full-sized avatar
🚀
DeFi dreamer

Anton Bukov k06a

🚀
DeFi dreamer
View GitHub Profile
@k06a
k06a / UIImage+Grayscale.m
Last active November 25, 2015 14:18
UIImage+Grayscale
@implementation UIImage (Grayscale)
UIImage *grayscaleImageFromCIImage(CIImage *image, CGFloat scale) {
CIImage *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, image, @"inputBrightness", @0.0, @"inputContrast", @1.1, @"inputSaturation", @0.0, nil].outputImage;
CIImage *output = [CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", @0.7, nil].outputImage;
CGImageRef ref = [[CIContext contextWithOptions:nil] createCGImage:output fromRect:output.extent];
UIImage *result = [UIImage imageWithCGImage:ref scale:scale orientation:UIImageOrientationUp];
CGImageRelease(ref);
return result;
}
@k06a
k06a / UIImage+ResizableFallback.m
Last active December 13, 2015 21:18 — forked from arbales/UIImage_ResizableFallback.m
Portable version of resizable UIImage constructor
@interface UIImage (ResizeableFallback)
- (UIImage *)resizableImageWithInsets:(UIEdgeInsets *)insets;
@end
@implementation
- (UIImage *)resizableImageWithInsets:(UIEdgeInsets *)insets
{
if ([UIImage respondsToSelector:@selector(resizableImageWithCapInsets:)])
return [self resizableImageWithCapInsets: insets];
return [self stretchableImageWithLeftCapWidth:insets.left topCapWidth:insets.top];
}
@k06a
k06a / log2
Created August 18, 2013 12:44
Fast log2 by reversing and then counting trailing bits - see run result at http://codepad.org/MQeUVaiK
// Copyright 2013 (c) Anton Bukov - https://github.com/k06a
// Inspired by http://graphics.stanford.edu/~seander/bithacks.html
#define P0(a) (a)
#define P1(a) (((P0(a) & 0x55555555) << 1) | ((P0(a) & 0xAAAAAAAA) >> 1))
#define P2(a) (((P1(a) & 0x33333333) << 2) | ((P1(a) & 0xCCCCCCCC) >> 2))
#define P3(a) (((P2(a) & 0x0F0F0F0F) << 4) | ((P2(a) & 0xF0F0F0F0) >> 4))
#define P4(a) (((P3(a) & 0x00FF00FF) << 8) | ((P3(a) & 0xFF00FF00) >> 8))
#define P5(a) (((P4(a) & 0x0000FFFF) << 16) | ((P4(a) & 0xFFFF0000) >> 16))
@k06a
k06a / BinSearch
Last active December 21, 2015 06:08
Binary search template function with searching nearest greater.
template<typename TI, typename TV>
int BinSearch(TI begin, TI end, TV value)
{
int minIndex = 0;
int maxIndex = end - begin - 1;
while (minIndex <= maxIndex)
{
int midIndex = (minIndex + maxIndex) / 2;
TI comparison = begin + midIndex;
@k06a
k06a / kick.c
Last active January 4, 2016 19:09
Central and non-central kick
//
// Here is some illustration of central kick:
// https://commons.wikimedia.org/wiki/File:Elastischer_stoß3.gif
//
// V -V
// [m = 2]---> <---[m = 1]
// [m = 2] [m = 1]
// [m = 2][m = 1]
// [m = 2] [m = 1]
// <-[m = 2] [m = 1]----->
@k06a
k06a / NSNull+SelfOrNil.h
Last active January 5, 2016 18:55
Returns nil if equal to [NSNull null] else return self
//
// Usage: `[item.self anyMethod]` is valid for `item` equals to `[NSNull null]`
//
@interface NSNull (SelfOrNil)
@end
@k06a
k06a / NSValue+CVMat.h
Last active January 15, 2016 08:30
NSValue C++ object
#import <Foundation/Foundation.h>
namespace cv {
class Mat;
}
@interface NSValue (CVMat)
+ (instancetype)valueWithCVMat:(cv::Mat)mat;
@property (readonly) cv::Mat CVMatValue;
@k06a
k06a / git-rename-bunch-tags.sh
Last active March 14, 2016 19:48
git rename bunch tags
# Create and push new tags
for t in $(git tag | grep _); do git tag ${t//_//} $t; done
git push --tags
# Delete original tags
for t in $(git tag | grep _); do git tag -d $t && git push origin :refs/tags/$t; done
@k06a
k06a / reorder_attrs.sh
Last active April 5, 2016 11:33
Reorder property attributes script
#
# Reorder property attributes in one possible way
#
# @property (nullable, readonly, assign, nonatomic, getter=isReady) BOOL ready;
#
# 1. Move readonly to the BEGIN of attribute list
# 2. Move nullable to the BEGIN of attribute list
# 3. Move null_resettable to the BEGIN of attribute list
# 4. Move nonatomic to the END of attribute list
# 5. Move getter to the END of attribute list
@k06a
k06a / Bike.m
Created April 28, 2016 18:33 — forked from mgamer/Bike.m
contentsRect animation
#import <QuartzCore/QuartzCore.h>
#import "Bike.h"
@implementation Bike {
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];