Skip to content

Instantly share code, notes, and snippets.

View danieltmbr's full-sized avatar

Daniel Tombor danieltmbr

  • London, United Kingdom
View GitHub Profile
@mjm
mjm / ManagedObjectChangesPublisher.swift
Created November 3, 2019 20:41
Observe changes to a Core Data fetch request with Combine
import Combine
import CoreData
extension NSManagedObjectContext {
func changesPublisher<Object: NSManagedObject>(for fetchRequest: NSFetchRequest<Object>)
-> ManagedObjectChangesPublisher<Object>
{
ManagedObjectChangesPublisher(fetchRequest: fetchRequest, context: self)
}
}
@gonzalezreal
gonzalezreal / KeyedDecodingContainer+EmptyRepresentable.swift
Last active January 11, 2023 08:25
A technique to avoid having optional array properties in your models when decoding JSON using Swift 4
/// A type that has an "empty" representation.
public protocol EmptyRepresentable {
static func empty() -> Self
}
extension Array: EmptyRepresentable {
public static func empty() -> Array<Element> {
return Array()
}
}
import Foundation
struct Person: Codable {
let name: String
}
let person = Person(name: "Soroush")
let archiver = NSKeyedArchiver(forWritingWith: NSMutableData())
- (void)hideVolumeBezel {
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
volumeView.clipsToBounds = YES;
[self.view addSubview:volumeView];
}
- (void)beginDetectingVolumeClicks {
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:YES error:nil];
[audioSession setCategory:AVAudioSessionCategoryAmbient error:nil];
@haruair
haruair / pre-commit-swiftlint.sh
Created December 5, 2016 13:25
Git Client-side pre-commit hook for SwiftLint
#!/bin/bash
#
# hook script for swiftlint. It will triggered when you make a commit.
#
# If you want to use, type commands in your console.
# $ ln -s ../../pre-commit-swiftlint.sh .git/hooks/pre-commit
# $ chmod +x .git/hooks/pre-commit
LINT=$(which swiftlint)
@gunjanpatel
gunjanpatel / revert-a-commit.md
Last active May 7, 2024 22:00
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@alskipp
alskipp / ignoreNil.swift
Created May 6, 2016 00:04
How to ignore `nil` values using RxSwift without using❗️
// Create an `Observable` of Optional<Int>
let values: Observable<Int?> = [1, 2, .None, 3, .None, 4, 5].toObservable()
// Method 1: using a free function
// Requires passing the function to `flatMap`
func ignoreNil<A>(x: A?) -> Observable<A> {
return x.map { Observable.just($0) } ?? Observable.empty()
}
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//