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 / gramps-web-backup.sh
Last active February 4, 2026 19:16
gramps-web automatic backup script
#!/usr/bin/env bash
# This script backs up the Gramps-Web database in ".gramps" format.
# Back them up together with the "media" volume to have a restorable app backup.
set -euo pipefail
# Access
BASE_URL='https://demo.grampsweb.org' # without trailing slash
USERNAME='owner'
PASSWORD='owner'
@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
@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 / CFNetworkErrors.h
Last active September 28, 2023 10:26
Apple NSURLError and CFNetworkError codes
typedef CF_ENUM(int, CFNetworkErrors) {
kCFHostErrorHostNotFound = 1,
kCFHostErrorUnknown = 2, // Query the kCFGetAddrInfoFailureKey to get the value returned from getaddrinfo; lookup in netdb.h
// SOCKS errors; in all cases you may query kCFSOCKSStatusCodeKey to recover the status code returned by the server
kCFSOCKSErrorUnknownClientVersion = 100,
kCFSOCKSErrorUnsupportedServerVersion = 101, // Query the kCFSOCKSVersionKey to find the version requested by the server
// SOCKS4-specific errors
kCFSOCKS4ErrorRequestFailed = 110, // request rejected or failed by the server
kCFSOCKS4ErrorIdentdFailed = 111, // request rejected because SOCKS server cannot connect to identd on the client
@krin-san
krin-san / gems_top_level.sh
Created November 16, 2021 09:32
List gems without reverse dependencies
#!/bin/bash
# Provides list of gems that have nothing depending on them
for target in $(gem list -l --no-verbose | cut -d ' ' -f 1); do
if [ "$(gem dependency -lr $target | wc -l)" -eq 2 ]; then
echo "$target"
fi
done
@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 / ToggleConstraint.m
Last active October 1, 2020 07:23
NSLayoutConstraint with a two possible states and a flag to toggle between them
#import <UIKit/UIKit.h>
/// This constraint could be toggled between two values (min/max) by `enlarged` flag
@interface ToggleConstraint : NSLayoutConstraint
/**
Max size of the height/width/offset/etc.
Think about it as some UI element can change it's size between min and max values.
*/
@property (nonatomic, assign) IBInspectable BOOL enlarged;
@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
;

Build libimobiledevice and ifuse from HEAD

Install development packages via Brew. If you're using OS X 10.12+, install osxfuse via cask as Brew suggest in error output.

brew tap homebrew/fuse
brew install --HEAD usbmuxd
brew install --HEAD libimobiledevice
brew install --HEAD ifuse
@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};