Skip to content

Instantly share code, notes, and snippets.

View andrey-str's full-sized avatar

Andrey Streltsov andrey-str

View GitHub Profile
@andrey-str
andrey-str / xcodeSwitch.sh
Created March 20, 2012 07:47 — forked from doronkatz/xcodeSwitch.sh
XCode switch script
$ sudo /usr/bin/xcode-select -switch /Applications/Xcode.app
@andrey-str
andrey-str / PDFDocument.cpp
Created October 12, 2015 23:15
Load and render a page from PDF with QuartzCore
#import "PDFDocument.h"
bool PDFDocument::loadDocument(const char *filename){
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
size_t count;
@andrey-str
andrey-str / NSDictionary+XXXConvertValues.h
Created November 12, 2015 08:59 — forked from kristopherjohnson/NSDictionary+XXXConvertValues.h
Category on NSDictionary that will convert string values to numbers or vice versa. Useful for JSON deserialization.
#import <Foundation/Foundation.h>
@interface NSDictionary (XXXConvertValues)
// Return value associated wth key, converted to NSString
- (NSString *) stringValueForKey:(id)key;
// Return integer value associated with key, converted to integer
- (NSInteger) integerValueForKey:(id)key;
@andrey-str
andrey-str / bash_shortcut.sh
Last active November 19, 2015 14:03
Useful aliases for bash .profile
# common alaises
# up one level
alias ..="cd .."
# unload cacher applications preferences on Yosemite and up(maybe on Maverick too)
alias fixpref='killall -u andrey cfprefsd'
# refresh locate database
alias updatedb=open_in_appcode
# detailed directory listing
alias ll="ls -l"
@andrey-str
andrey-str / fix_bluetooth.sh
Created December 5, 2015 08:58
Fix bluetooth problem on Yosemite
#!/bin/sh
# Credits to author of this message(timgws): https://discussions.apple.com/thread/6693749?start=15&tstart=0
function msg() {
foo=$2
what="$(tr '[:lower:]' '[:upper:]' <<< ${foo:0:1})${foo:1}"
echo ">> ${what}ing $1...";
}
function __blued() {
@andrey-str
andrey-str / mute.sh
Created March 24, 2016 10:09
OS X Volume Up/Down/Mute from Terminal
mute=`osascript -e 'output muted of (get volume settings)'`
if [ $mute = true ]; then mute=false; else mute=true; fi
osascript -e "set volume output muted \"$mute\""
@andrey-str
andrey-str / ViewsContainerController.h
Last active March 24, 2016 11:24
UIView Container pattern
//
// Created by Andrey Streltsov on 09/03/16.
//
@import UIKit;
enum eViewControllerIndentifiers {
eIdentifier1, // the one with rendered whole course map
eIdentifier2, // the one with MapKit map
eIdentifier3 // the one with rendered hole map
@andrey-str
andrey-str / string-unicode.rb
Created March 31, 2016 11:00
Ruby's String class extension to support Unicode for some operations
require 'unicode'
class String
def downcase
Unicode::downcase(self)
end
def downcase!
self.replace downcase
end
def upcase
@andrey-str
andrey-str / random-color.m
Created April 12, 2016 20:26
Random UI/SK/NSColor snippet(obj-c)
- (UIColor*) randomColor{
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:1];
return color;
}
double delayInSeconds = 0.7;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Your code here..
});