Skip to content

Instantly share code, notes, and snippets.

View mortenjust's full-sized avatar

Morten Just mortenjust

View GitHub Profile
@mortenjust
mortenjust / Simple Regex Matcher.swift
Created November 1, 2015 18:03
Simple regular expression that returns a set of results
func findMatchesInString(rawdata:String, regex:String) -> [String]? {
do {
let re = try NSRegularExpression(pattern: regex,
options: NSRegularExpressionOptions.CaseInsensitive)
let matches = re.matchesInString(rawdata,
options: NSMatchingOptions.ReportProgress,
range:
NSRange(location: 0, length: rawdata.utf16.count))
extension NSTextView {
func append(string: String) {
self.textStorage?.appendAttributedString(NSAttributedString(string: string))
self.scrollToEndOfDocument(nil)
}
}

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.
let output = "Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 743x133, 2737 kb/s, SAR 1:1 DAR 9:16, 28.42 fps, 90k tbr, 90k tbn, 180k tbc (default)"
let re = try NSRegularExpression(pattern: ", (\\d.{0,}?)x(\\d.{0,}?), ",
options: NSRegularExpressionOptions.CaseInsensitive)
let matches = re.matchesInString(output,
options: NSMatchingOptions.ReportProgress,
range:
NSRange(location: 0, length: output.utf16.count))
ffprobe -select_streams v -show_streams emulatorz.mov 2>/dev/null | grep nb_frames | sed -e 's/nb_frames=//'
# grep nb_frames | sed -e 's/nb_frames=//'
color=$1
if [ -z $color ]
then
echo "OFF"
else
echo "ON" + $color
fi
func NSColorToHex(color: NSColor) -> NSString {
// Get the red, green, and blue components of the color
var r :CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
var rInt, gInt, bInt : Int
var rHex, gHex, bHex : NSString
Process: droptogif [24969]
Path: /Users/USER/Downloads/Drop to GIF.app/Contents/MacOS/droptogif
Identifier: com.mortenjust.droptogif
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: droptogif [24969]
User ID: 119147
Date/Time: 2015-10-09 11:01:10.428 -0700
@mortenjust
mortenjust / copy a file to pasteboard.swift
Created October 8, 2015 19:14
Copy the contents of a file to the clipboard so it can be pasted in Photoshop or Google Docs
func copyFileToPasteboard(filename:String){
print("copying \(filename) to paste")
var pasteboard = NSPasteboard.generalPasteboard()
pasteboard.clearContents()
pasteboard.writeFileContents(filename);
var gifData = NSData(contentsOfFile: filename);
pasteboard.setData(gifData, forType: "com.compuserve.gif");
pasteboard.setData(gifData, forType: String(kUTTypeGIF)); // crap! only copies the first frame. Worthless for us, the gif people
}
func selectFolder(){
let openPanel = NSOpenPanel();
openPanel.title = "Select a folder to watch for videos"
openPanel.message = "Videos you drop in the folder you select will be converted to animated gifs"
openPanel.showsResizeIndicator=true;
openPanel.canChooseDirectories = true;
openPanel.canChooseFiles = false;
openPanel.allowsMultipleSelection = false;
openPanel.canCreateDirectories = true;
openPanel.delegate = self;