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 / 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 / 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 / ape2mp3.sh
Created January 6, 2016 09:08 — forked from jingle/ape2mp3.sh
Convert ape to mp3 using avconv, split with mp3splt and cue
#!/bin/bash
find "$1" -type f -name "*.ape" -print0 | while read -d $'\0' song
do
output=${song%.ape}.mp3
cue=${song%.ape}.cue
avconv -i "$song" -b 192k "$output"
if ls "$cue" &> /dev/null; then
mp3splt -a -c "$cue" "$output"
@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 / 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 / UIImageView+CoordinateTransform.h
Last active May 5, 2018 12:36
Convert UIImageView coordintate to UIImage pixel coordinate and back turn around. Borrowed from here: http://b2cloud.com.au/tutorial/uiimageview-transforming-touch-coordinates-to-pixel-coordinates/
//
// Created by Andrey Streltsov on 16/11/15.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UIImageView (CoordinateTransform)
-(CGPoint) pixelPointFromViewPoint:(CGPoint)viewPoint;
-(CGPoint) viewPointFromPixelPoint:(CGPoint)pixelPoint;
@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 / common-utils.cpp
Created October 19, 2015 08:49
Reveal file in Finder or Explorer with Qt
void revealFile(QWidget* parent, const QString &pathToReveal) {
// See http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
// for details
// Mac, Windows support folder or file.
#if defined(Q_OS_WIN)
const QString explorer = Environment::systemEnvironment().searchInPath(QLatin1String("explorer.exe"));
if (explorer.isEmpty()) {
QMessageBox::warning(parent,
@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;