Skip to content

Instantly share code, notes, and snippets.

@krodak
krodak / Realm+CascadeDeleting.swift
Last active April 27, 2023 19:16
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@Ben-G
Ben-G / L10NTests.swift
Created June 16, 2017 20:35
Very simple automated test to ensure localizations exist and are well-formed on iOS.
import Foundation
import XCTest
/// Basic sanity check that ensures that we are able to retrieve localized strings for all languages
/// we support.
final class L10NTests: XCTestCase {
func testLocalizations() {
let locales = ["en", "es", "zh-Hans", "zh-Hant", "fi"]
for locale in locales {
@balachandarlinks
balachandarlinks / Dockerfile
Last active November 27, 2020 14:20
Dockerfile for https://github.com/gojuno/mainframer remote android build system.
FROM ubuntu:16.04
MAINTAINER Balachandar KM "balachandarlinks@gmail.com"
# Install java7
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:webupd8team/java && \
(echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && \
apt-get update && \
@JosiasSena
JosiasSena / WifiConnectionReceiver.java
Last active June 1, 2023 16:36
WifiConnectionReceiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.support.annotation.NonNull;
import android.util.Log;
import static android.content.ContentValues.TAG;
@brennanMKE
brennanMKE / TaskScheduler.swift
Created January 20, 2017 00:07
Task Scheduler with Swift 2.3
public class TaskScheduler: NSObject {
weak var timer: NSTimer? = nil
var task: ((NSTimer) -> Void)?
public func schedule(interval: NSTimeInterval, repeats: Bool, task: ((NSTimer) -> Void)? = nil) -> NSTimer? {
if !NSThread.isMainThread() {
return nil
}
@gonzalezreal
gonzalezreal / A.LICENSE.md
Last active January 26, 2023 19:43
Using Realm with Value Types

Copyright 2017 Guillermo Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U

@ryuichis
ryuichis / Event.swift
Created October 15, 2016 13:40
Swift 3 Struct & NSCoding
public struct Event {
public internal(set) var timeStamp: Date
public internal(set) var eventTag: String
public init(timeStamp: Date, tag: String) {
self.timeStamp = timeStamp
self.eventTag = tag
}
}
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveImage(image: UIImage, albumName: String, completion: (PHAsset?)->()) {
if let album = self.findAlbum(albumName) {
saveImage(image, album: album, completion: completion)
return
}
@acrookston
acrookston / README.md
Last active January 26, 2022 11:05
Xcode pre-action to build custom Info.plist

Automatic build versions from git in Xcode (and other goodies)

Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.

1. Xcode Scheme pre-action

Edit Xcode Scheme and add a pre-action script. Copy the contents of preaction.sh into the pre-action script box.