Skip to content

Instantly share code, notes, and snippets.

View barbaramartina's full-sized avatar

Bar barbaramartina

View GitHub Profile
// See http://mindsea.com/2012/12/18/downscaling-huge-alassets-without-fear-of-sigkill for details
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>
// Helper methods for thumbnailForAsset:maxPixelSize:
static size_t getAssetBytesCallback(void *info, void *buffer, off_t position, size_t count) {
ALAssetRepresentation *rep = (__bridge id)info;
NSError *error = nil;
@barbaramartina
barbaramartina / lambdas.hs
Last active April 7, 2016 10:40
Haskell piece to generate a SVG file with a set of lambda paths
module LambdasSVG where
import System.IO
import Data.String
import System.Random
writeSVG :: [String] -> String
writeSVG [] = error "No data to be written"
writeSVG xs = "<svg xmlns=\"http://www.w3.org/2000/svg\">" ++ foldr (++) "" xs ++ "</svg>"
@barbaramartina
barbaramartina / AsynchronousOperation.swift
Created April 8, 2016 09:07
A documented subclass of an asynchronous NSOperation in Swift
//
// This is an implementation of an asynchronous operation subclass.
// BASED ON: ConcurrentOperation.swift: Created by Caleb Davenport on 7/7/14.
// The original implementation has been completed with specific links to the documentation in order
// to make sure all the guidelines for subclassing an async operation are followed and learn more about
// how it should be correctly implemented, as well as having links available to help our memory to remember all
// the requirements a subclass of NSOperation should fullfit when it runs asynchronously.
//
// From Apple Docs:
// If you are creating a concurrent operation, you need to override the following methods and properties at a minimum:
@barbaramartina
barbaramartina / SynchronousOperation.swift
Created April 8, 2016 14:46
Subclssing a NSOperation to make a synchronous child + Links to the appropiate Apple documentation
//
// MySynchronousOperation.swift
// operationqueues
//
// Created by Barbara Rodeker on 3/3/16.
// Copyright © 2016 Barbara M. Rodeker. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
@barbaramartina
barbaramartina / SimpleObserver.swift
Created April 8, 2016 14:56
How to create an observer of operations and queues in Swift. Which properties you can observe + docs links
//
// An Observer class intended to show how KVO works on operations and queues
//
// Created by Barbara Rodeker on 3/3/16.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
@barbaramartina
barbaramartina / givemefood.rb
Created April 14, 2016 17:29
GiveMeFoodBot: A humble bot for Telegram in Ruby
require 'telegram/bot'
require 'google_places'
token = 'YOUR-TOKEN-FOR-BOT'
@googleClient = GooglePlaces::Client.new('YOUR-GOOGLE-PLACES-TOKEN')
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
if message.location
l = message.location
@barbaramartina
barbaramartina / unit-tests-templates.swift
Created May 26, 2016 10:53
Swift: Unit testing templates
// see: https://www.youtube.com/watch?v=Y3t8e_rUyTk&list=PLwu90VQm-yTobHYmgVdvZu5sBdyPPxW9S and http://ladyandtech.blogspot.de/2016/03/swift-testing-with-xctest.html
import XCTest
@testable import YOUR_MODULE_NAME
class yourTestCase: XCTestCase {
override func setUp() {
/// This is how you could use standar user defaults for sharing app between your app and your extensions.
/// You should have groups capability enable in your app and extensions and use the same group name everywhere.
/// For more info see: https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html
/// -initWithSuiteName: initializes an instance of NSUserDefaults that searches the shared preferences search list for the domain 'suitename'. For example, using the identifier of an application group will cause the receiver to search the preferences for that group. Passing the current application's bundle identifier, NSGlobalDomain, or the corresponding CFPreferences constants is an error. Passing nil will search the default search list.
if let defaults = UserDefaults(suiteName: "yourapp.group.name") {
defaults.set("VALUE", forKey: "KEY")
}
@barbaramartina
barbaramartina / register-your-app-notifications.swift
Created October 2, 2016 17:43
Swift 3 code about how to register you app to handle notifications. An initial setup for your AppDelegate.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// In iOS 8 and later, apps that use either local or remote notifications must register the types of user interactions the app supports. Apps can ask to badge icons, display alert messages, or play sounds. When you request any of these interaction types, the system checks the types of interactions the user has allowed for your app. If the user has disallowed a particular type of interaction, the system ignores attempts to interact with the user in that way.
// The user can change the notification settings for your app at any time using the Settings app. Because settings can change, always call the registerUserNotificationSettings: at launch time and use the application:didRegisterUserNotificationSettings: method to get the response.
let center = UNUserNotificationCenter.current()
center.requestAuthorization(opt
@barbaramartina
barbaramartina / Swift 3 - Registering your App for Push Notifications.swift
Created November 5, 2016 11:06
How to register your app for push notifications in Swift 3
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// In iOS 8 and later, apps that use either local or remote notifications must register the types of user interactions the app supports. Apps can ask to badge icons, display alert messages, or play sounds. When you request any of these interaction types, the system checks the types of interactions the user has allowed for your app. If the user has disallowed a particular type of interaction, the system ignores attempts to interact with the user in that way.
// The user can change the notification settings for your app at any time using the Settings app. Because settings can change, always call the registerUserNotificationSettings: at launch time and use the application:didRegisterUserNotificationSettings: method to get the response.
let center = UNUserNotificationCenter.current()
center.requestAuthorization(opt