Skip to content

Instantly share code, notes, and snippets.

View w-i-n-s's full-sized avatar
🏠
Working from home

Sergey Vinogradov w-i-n-s

🏠
Working from home
  • Varna, Bulgaria
View GitHub Profile
@maltekrupa
maltekrupa / basic-auth.swift
Last active September 10, 2021 05:18
HTTP Basic Authentication using URLSession and URLCredentialStorage in swift 4 with xcode 9
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let credential = URLCredential(user: “username@gmail.com”, password: “password”, persistence: URLCredential.Persistence.forSession)
let protectionSpace = URLProtectionSpace(host: "example.com", port: 443, protocol: "https", realm: "Restricted", authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
URLCredentialStorage.shared.setDefaultCredential(credential, for: protectionSpace)
let config = URLSessionConfiguration.default
@adrienjoly
adrienjoly / restartCoreAudio.sh
Created December 25, 2013 01:07
Mac Os X command to restart the core audio. I needed to use this in order to fix my AirPlay issue.
# You have to restart the core audio be pasting the following line into termnal
sudo kill `ps -ax | grep 'coreaudiod' | grep 'sbin' |awk '{print $1}'`
@swhitty
swhitty / CGPathApply.swift
Created February 27, 2017 11:15
Bridges CoreGraphics.CGPathApplierFunction with a standard Swift closure
extension CGPath {
func apply(action: @escaping (CGPathElement)->()) {
var action = action
apply(info: &action) {
let action = $0!.bindMemory(to: ((CGPathElement)->()).self, capacity: 1).pointee
action($1.pointee)
}
}
}
@khorbushko
khorbushko / PHPhotoLibrary+SaveImage
Created December 29, 2016 09:27
PHPhotoLibrary+SaveImage - save image with Photos Framework swift 3
import UIKit
import Photos
extension PHPhotoLibrary {
// MARK: - PHPhotoLibrary+SaveImage
// MARK: - Public
func savePhoto(image:UIImage, albumName:String, completion:((PHAsset?)->())? = nil) {
func save() {
@pietbrauer
pietbrauer / Makefile
Created April 26, 2015 10:03
Shutdown and reset all iOS Simulators
erase_sim:
./reset_sim.sh 2>/dev/null; true
@ljbatwh
ljbatwh / PagerManager.swift
Created August 9, 2020 22:47
swiftui page controller
import SwiftUI
struct PagerManager<Content: View>: View {
let pageCount: Int
@Binding var currentIndex: Int
let content: Content
//Set the initial values for the variables
init(pageCount: Int, currentIndex: Binding<Int>, @ViewBuilder content: () -> Content) {
self.pageCount = pageCount
struct ContentView: View {
@State private var currentPage = 0
var body: some View {
//Pager Manager
VStack{
PagerManager(pageCount: 2, currentIndex: $currentPage) {
Text("First page")
Text("Second page")
@shu223
shu223 / CustomActivity.swift
Last active November 4, 2020 17:59
Custom UIActivity in Swift 3
import UIKit
class CustomActivity: UIActivity {
override class var activityCategory: UIActivityCategory {
return .action
}
override var activityType: UIActivityType? {
guard let bundleId = Bundle.main.bundleIdentifier else {return nil}
@itsjustcon
itsjustcon / UIColor+Hex.mm
Created June 10, 2013 19:31
Get UIColor from HEX in Objective-C. Great for programmatically creating color swatches on iOS + OS X!
+ (UIColor *) colorFromHexCode:(NSString *)hexString {
NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
if([cleanString length] == 3) {
cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
[cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
[cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
[cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
}
if([cleanString length] == 6) {
cleanString = [cleanString stringByAppendingString:@"ff"];
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *info = @"http://codeafterhours.wordpress.com";
// Generation of QR code image
NSData *qrCodeData = [info dataUsingEncoding:NSISOLatin1StringEncoding]; // recommended encoding
CIFilter *qrCodeFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrCodeFilter setValue:qrCodeData forKey:@"inputMessage"];