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 / 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 / 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
/// 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
@barbaramartina
barbaramartina / Swift 3 - How to handle token registration.swift
Created November 5, 2016 11:08
Swift 3: How to print the token when the registration was successful or erroneous. And how to register actions and categories.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print(deviceTokenString)
//TODO: forward the token to your servers
// Optionally: registerNotificationCategories()
}
// iOS 10 working way to fade in a blurred view (changing alpha in the container does not work on iOS 10)
let effectView = UIVisualEffectView()
effectView.frame = toast.bounds
effectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(effectView) //replace view with whatever view you want to blur
UIView.animate(withDuration: 0.2) {
let blur = UIBlurEffect(style: .light)
effectView.effect = blur
@barbaramartina
barbaramartina / BlurEffect-Swift3.swift
Created July 9, 2017 12:19
Apply blur effect to a view in Swift 3
let effectView = UIVisualEffectView()
effectView.frame = view.bounds
effectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(effectView)
let e = UIBlurEffect(style: .dark)
effectView.effect = e