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 / imageNamed.sh
Last active June 15, 2016 13:08
Xcode xcasset usage detector
set -eu -o pipefail
function show_code {
while read ERROR_LOCATION; do
echo "$ERROR_LOCATION:: error: Missing imageset with name $1"
done < <(find "$PROJECT_NAME" -name '*.m' -print0 | xargs -0 grep -n -o -e "\[UIImage imageNamed:@\"$1\"\]" | cut -d ':' -f 1,2)
}
function show_img {
echo -n $(find "$PROJECT_NAME" -name "$1.imageset")
@k06a
k06a / fizzbuzz.cpp
Last active May 25, 2016 05:57 — forked from bgaff/fizzbuzz.cpp
FizzBuzz C++: Template Recursion
/*
* fizzbuzz.cpp
*
* Created on: Apr 25, 2012
* Author: Brian Geffon
*
* Modified on: May 25, 2016
* Author: Anton Bukov
*
* fizzbuzz solved without looping or conditionals using only template recursion.
@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];
@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 / 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 / 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 / erase-git.sh
Last active May 14, 2021 03:14
Git remove some dirs
# Fetch
git clone https://github.com/username/reponame reponame
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
# Analyze
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py && sudo python get-pip.py && rm get-pip.py
sudo pip install git-fat
git fat -a find 1000000
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4
@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 / RefString.cpp
Last active October 16, 2015 07:17
std::string substring reference without copying
struct RefString
{
RefString(const string & s, int i, int l) : s(s), i(i), l(l) {}
const char & operator [] (int x) const {
return s[i+x];
}
size_t length() const {
return l;
@k06a
k06a / add.cpp
Created October 14, 2015 16:34
Add two decimal number stored in strings
string add(const string & s1, const string & s2)
{
int flag = 0;
string ret(std::max(s1.size(),s2.size())+1, '0');
for (int i = 0; i < ret.size(); i++) {
int v = (i < s1.size() ? s1[s1.size()-1-i]-'0' : 0)
+ (i < s2.size() ? s2[s2.size()-1-i]-'0' : 0) + flag;
flag = v/10;
v -= flag*10;
ret[ret.size()-1-i] = v+'0';