Skip to content

Instantly share code, notes, and snippets.

View shmidt's full-sized avatar

Dima Shmidt shmidt

View GitHub Profile
@shmidt
shmidt / DetailViewController.m
Last active August 29, 2015 14:00 — forked from GiK/DetailViewController.m
Dismiss search bar (ARC)
/*
This sample uses your application's keyWindow - the window that all other views hang from. Since UIWindow is simply a subclass of UIView, we can add gesture recognizers to it.
No matter where you tap or scroll - the master view's table view, or a map in the detail view - the keyboard will be dismissed and your pan/tap gesture continues unhindered.
*/
// Adopt UIGestureRecognizerDelegate and UISearchBarDelegate protocols in .h
@shmidt
shmidt / shutdown_osx.applescript
Last active August 29, 2015 14:07
Shutdown OS X
tell application "System Events"
set ProcNm_ to name of every application process whose visible is true
repeat with i_ from 1 to count items of ProcNm_
set TarProc_ to item i_ of ProcNm_
try
tell application TarProc_ to quit
end try
end repeat
shut down
end tell
@shmidt
shmidt / RowTemplateRelationship
Last active December 8, 2016 18:17
NSPredicateEditorRowTemplate subclass to support relationships in Interface Builder
class RowTemplateRelationshipAny: NSPredicateEditorRowTemplate {
override func predicate(withSubpredicates subpredicates: [NSPredicate]?) -> NSPredicate{
let predicate: NSComparisonPredicate = super.predicate(withSubpredicates: subpredicates) as! NSComparisonPredicate
let newPredicate = NSComparisonPredicate(leftExpression: predicate.leftExpression, rightExpression: predicate.rightExpression, modifier: .any, type: predicate.predicateOperatorType, options: predicate.options)
return newPredicate
}
@shmidt
shmidt / Swift3Base64.swift
Last active September 19, 2022 08:18 — forked from stinger/Swift3Base64.swift
Swift 3: Base64 encoding and decoding strings
//: # Swift 3: Base64 encoding and decoding
import Foundation
extension String {
//: ### Base64 encoding a string
func base64Encoded() -> String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString()
}
return nil
@shmidt
shmidt / URL+Readlines.swift
Created May 16, 2018 16:30
URL+Readlines
//
// String+ReadLines.swift
//
// Created by Dmitry Shmidt on 5/16/18.
//
import Foundation
extension URL{
func readLines() throws -> [String] {
@shmidt
shmidt / IPAPI+ReactiveKit.swift
Created May 25, 2018 17:31
IPAPI+ReactiveKit
//
// IPAPI+ReactiveKit.swift
// Created by Dmitry Shmidt on 5/25/18.
//
import IPAPI
import ReactiveKit
extension Service{
@discardableResult open func fetch(query: String? = nil, fields: [Result.Field]? = nil, language: String? = nil) -> Signal<Service.Result, Service.Error>
@shmidt
shmidt / String+Digits.swift
Created June 11, 2018 23:41
Extract array of unsigned ints from string
extension String{
func extractDigits() -> [UInt]{
return components(separatedBy: CharacterSet.decimalDigits.inverted).compactMap(UInt.init)
}
}
@shmidt
shmidt / ReactiveKit+NSButton.swift
Created September 14, 2018 19:13
ReactiveKit+NSButton
#if os(macOS)
import AppKit
import ReactiveKit
import Bond
public extension ReactiveExtensions where Base: NSButton {
public var click: SafeSignal<Void> {
return controlEvent.eraseType()
@shmidt
shmidt / forEachBatch.swift
Last active March 21, 2019 21:43
For loop using batches
import Foundation
public extension Array {
/**
Loops through array by batches
- Parameter batchSize: Size of the batch
- batch: Current batch elements
- currentNo: Current batch number
@shmidt
shmidt / secure_pi.sh
Last active September 30, 2020 07:41
Securing Pi
# https://www.raspberrypi.org/documentation/configuration/security.md
sudo apt install ufw
sudo ufw allow ssh
sudo ufw limit ssh/tcp
sudo ufw enable
sudo apt install fail2ban
sudo service fail2ban restart