Skip to content

Instantly share code, notes, and snippets.

View mortenjust's full-sized avatar

Morten Just mortenjust

View GitHub Profile
import Contacts
// Convert to the newer CNPostalAddress
func postalAddressFromAddressDictionary(addressdictionary: Dictionary<NSObject,AnyObject>) -> CNMutablePostalAddress {
let address = CNMutablePostalAddress()
address.street = addressdictionary["Street"] as? String ?? ""
address.state = addressdictionary["State"] as? String ?? ""
address.city = addressdictionary["City"] as? String ?? ""
@mortenjust
mortenjust / NSImage + withoutAlpha.swift
Created July 22, 2022 07:59
Remove alpha transparency from NSImage
extension NSImage {
func withoutAlpha() -> NSImage? {
// based on https://gist.github.com/mishimay/7b65167cf829e022f46dfa749d018661
guard let cgImage = self.cgImage(forProposedRect: nil, context: nil, hints: nil) else { return nil }
let context = CGContext(data: nil, width: cgImage.width, height: cgImage.height, bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: cgImage.bytesPerRow, space: cgImage.colorSpace!, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)!
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: context.width, height: context.height))
guard let newCg = context.makeImage() else { return nil }
return NSImage(cgImage: newCg, size: .zero)
@mortenjust
mortenjust / WeatherKit.ts
Created July 21, 2022 18:29
WeatherKit Typescript types
export interface WeatherKit {
currentWeather: CurrentWeather;
forecastDaily: ForecastDaily;
forecastHourly: ForecastHourly;
}
export interface CurrentWeather {
name?: string;
metadata?: Metadata;
asOf?: Date;
func getHSBA(color:UIColor) -> (hue:CGFloat, saturation:CGFloat, brightness:CGFloat, alpha:CGFloat) {
var hue:CGFloat = 0.0
var sat:CGFloat = 0.0
var bri:CGFloat = 0.0
var alpha:CGFloat = 0.0
color.getHue(&hue, saturation: &sat, brightness: &bri, alpha: &alpha)
return (hue:hue, saturation:sat, brightness:bri, alpha:alpha)
}
@mortenjust
mortenjust / activity.java
Created October 3, 2015 16:55
RemoteViews in a notification #android
void postNotification(){
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_remote);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(android.R.drawable.btn_plus)
.setContentTitle("My notification")
.setContentText("Hello World!");
The following are tv commercials in the style of a highly emotional lifestyle branding campaign from Nike. They are inspirational and upbeat. Feel something. Dream bigger. The script contains 11 short lines.
Company: Nike
Product: Shoes
Short emotional tagline: Never too far down
Script:
We've all been underestimated and counted out
In those moments we felt like it was over
But it's when we're given no chance
that we somehow found that last bit of strength to keep fighting
func usesAMPM() -> Bool {
let locale = NSLocale.currentLocale()
let dateFormat = NSDateFormatter.dateFormatFromTemplate("j", options: 0, locale: locale)!
if dateFormat.rangeOfString("a") != nil {
return true
}
else {
return false
}
}
Company: Apple
Product: Apple AR Glasses
Short emotional tagline: The future is closer than it appears
Script:
In our lifetimes we’ve seen technology change our lives
In ways we couldn’t imagine
In the past decade alone, it’s become an extension of who we are
So when we talk about the future
We don’t just mean flying cars and robots
We mean a future where we’re not tethered to our screens
Company: Danske Bank
Product: Vi låner penge ud til folk og tager renter
Short emotional tagline: Får du en god idé?
Script:
Hvad gør du, når du får en god idé?
Har du modet til at tro på den og gøre noget ved den?
Er du bange for, at andre vil tage din idé og gøre den bedre?
Eller er du bare bange for at tabe?
Så hvad gør du?
Siger du fra og sætter en stopper for din drøm?

1. Create a folder in Dropbox or Google Drive

We'll use ~/Dropbox/Macnotes in this example

2. Copy the notes folder to the new folder in Dropbox or Google Drive

We'll use Finder for this instead of terminal as the cp -r command also copies the contents of all aliases and the Notes folder has a lot of those. Quit notes Open terminal and enable hidden files in Finder:

defaults write com.apple.finder AppleShowAllFiles YES.