Skip to content

Instantly share code, notes, and snippets.

View mortenjust's full-sized avatar

Morten Just mortenjust

View GitHub Profile
@mortenjust
mortenjust / copy image to clipboard.c
Created October 7, 2015 21:47
Copy image to clipboard
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
if([path isEqualToString:@"-"])
{
// http://caiustheory.com/read-standard-input-using-objective-c
func openAndSelectFile(filename:String){
let files = [NSURL(fileURLWithPath: filename)];
NSWorkspace.sharedWorkspace().activateFileViewerSelectingURLs(files);
}
@mortenjust
mortenjust / activity.java
Created September 9, 2015 02:07
Start an activity without back stack and kill current activity
Intent i = new Intent(this, WatchFaceActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
@mortenjust
mortenjust / gist:2158504
Created March 22, 2012 14:00
getDistance calculate distance in km in javascript
function getDistance(lon1, lat1, lon2, lat2) {
var R = 6371; // Radius of the earth in km
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c; // Distance in km
}
@mortenjust
mortenjust / ColorInterpolator.swift
Last active June 28, 2023 12:04
Interpolate colors with easing functions
import AppKit
import SwiftUI
/// Based on https://github.com/ipedro/SmoothGradientView
/// See documentation on `interpolate:`
///
/// How to use:
///
/// You can interpolate any array of `CGColor`, `NSColor` or `Color`to any array of any of the 3 supported types.
///
//
// Blobs.swift
// SwiftUI Demos
//
// Created by Morten Just on 1/31/23.
//
import SwiftUI
struct Blobs: View {
// Appdelegate, view did finish loading
var win = NSApplication.sharedApplication().windows.first!
win.titlebarAppearsTransparent = true
win.movableByWindowBackground = true
win.styleMask = win.styleMask | NSFullSizeContentViewWindowMask;
win.title = ""
//
// DarkModeMasker.swift
// SwiftUI Demos
//
// Created by Morten Just on 1/22/23.
// https://twitter.com/joshguospace/status/1617101052192649216?s=12
import SwiftUI
import Charts
//
// DarkModeMasker.swift
// SwiftUI Demos
//
// Created by Morten Just on 1/22/23.
// https://twitter.com/joshguospace/status/1617101052192649216?s=12
import SwiftUI
import Charts
import SwiftUI
// MARK: Main
struct TwitterBluePlus: View {
@State var topMenuItems : [MenuItem] = [MenuItem(title: "For you", icon: nil), MenuItem(title: "Following", icon: nil)]
@State var selectedIdx = 0
var selected : MenuItem { topMenuItems[selectedIdx] }