Skip to content

Instantly share code, notes, and snippets.

View krin-san's full-sized avatar

Alexander Chapliuk krin-san

  • Joyn GmbH
  • Munich, Germany
View GitHub Profile
@krin-san
krin-san / CrossStoryboardSegue.h
Created September 2, 2014 06:14
CrossStoryboardSegue
//
// CrossStoryboardSegue.h
//
#import <UIKit/UIKit.h>
@interface CrossStoryboardSegue : UIStoryboardSegue
// Default: YES
@property (nonatomic, assign) BOOL animatedSegue;
var resultText;
function run(){
var layerSets = app.activeDocument.layerSets;
dumpLayerSets(layerSets);
dumpLayers(app.activeDocument.layers);
}
function dumpLayerSets(layerSets){
var len = layerSets.length;
@krin-san
krin-san / AutoHotkey.ahk
Last active February 8, 2018 12:12
AutoHotkey config file
; Store path: %userprofile%/Documents/AutoHotkey.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Keyboard layout swithing
;
; See the language identifiers list here:
; http://msdn.microsoft.com/en-us/library/dd318693%28v=vs.85%29.aspx
;
@krin-san
krin-san / private.xml
Last active August 2, 2016 06:28
Karabiner (KeyRemap4MacBook) config file
<?xml version="1.0"?>
<root>
<item>
<name>Krin-San's remapping</name>
<item>
<name>Use F19 as non-cycle layout switching</name>
<appendix>Install Seil plugin to override CapsLock (https://pqrs.org/osx/karabiner/seil.html.en)</appendix>
<identifier>change_inputsources</identifier>
<autogen>__KeyToKey__ KeyCode::F19, ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_ENGLISH</autogen>
<autogen>__KeyToKey__ KeyCode::F19, ModifierFlag::OPTION_L, KeyCode::VK_CHANGE_INPUTSOURCE_RUSSIAN</autogen>
@krin-san
krin-san / #1. Simple retry
Last active October 22, 2021 00:24
ReactiveCocoa. Optional retry on error
// Taken from http://www.slideshare.net/manuelmaly/reactivecocoa-goodness-part-i-of-ii
// Exact presentation slide: http://image.slidesharecdn.com/presentation-141009165841-conversion-gate01/95/reactivecocoa-goodness-part-i-of-ii-37-638.jpg?cb=1412892113
// Try to repeat signal 3 times
static NSUInteger const retryAttempts = 2;
static NSTimeInterval const retrydelay = 1.;
RACSignal *signal = ...;
RACSignal *result = [[signal catch:^RACSignal *(NSError *error) {
return [[[RACSignal empty] delay:retrydelay]
@krin-san
krin-san / KSTestContacts.m
Last active August 29, 2015 14:18
Gist for creating test contacts in iOS AddressBook
#import <AddressBook/AddressBook.h>
...
void (^addContacts)(NSInteger) = ^(NSInteger count){
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
@krin-san
krin-san / NSDate+Compare.swift
Last active August 23, 2016 08:51 — forked from psobot/NSDate+Extensions.swift
Swift NSDate Comparison Extension
// NSDate doesn't include overrides for standard comparison operators in Swift.
// This extension adds <, >, <=, >=, and ==, using NSDate's built-in `compare` method.
// MIT licensed.
func <=(lhs: NSDate, rhs: NSDate) -> Bool {
return lhs.compare(rhs) != .OrderedDescending
}
func >=(lhs: NSDate, rhs: NSDate) -> Bool {
return lhs.compare(rhs) != .OrderedAscending
}
@krin-san
krin-san / iOSVersionCheck.h
Last active September 8, 2016 19:30
NSProcessInfo-based iOS version check macro (iOS 8+)
#define INC_SYSTEM_VERSION(v) ((NSOperatingSystemVersion){v.majorVersion, v.minorVersion + 1, 0})
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:v]
#define SYSTEM_VERSION_LESS_THAN(v) (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v))
#define SYSTEM_VERSION_EQUAL_TO(v) (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) && (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(INC_SYSTEM_VERSION(v))))
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) (SYSTEM_VERSION_LESS_THAN(v) || SYSTEM_VERSION_EQUAL_TO(v))
#define SYSTEM_VERSION_GREATER_THAN(v) (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) && (!SYSTEM_VERSION_EQUAL_TO(v)))
/*
// Manual logical check
NSOperatingSystemVersion v = (NSOperatingSystemVersion){8, 4, 0};
@krin-san
krin-san / happy_birthday.mikrotik
Created October 30, 2015 22:27
Happy Birthday song played using a speaker
:beep frequency=264 length=250ms;
:delay 500ms;
:beep frequency=264 length=250ms;
:delay 250ms;
:beep frequency=297 length=1000ms;
:delay 250ms;
:beep frequency=264 length=1000ms;
:delay 250ms;
:beep frequency=352 length=1000ms;
:delay 250ms;
@krin-san
krin-san / CoreTelephonyCheck.swift
Created November 9, 2015 12:39
Check if iOS device is capable to call / send SMS message
// Swift version of the code from http://stackoverflow.com/a/30335594/1986600
import CoreTelephony
override func awakeFromNib() {
super.awakeFromNib()
let isCapableToCall: Bool
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "tel://")!) {
// Check if iOS Device supports phone calls