Skip to content

Instantly share code, notes, and snippets.

@snown
snown / MTRXAnimatedViewLayer.m
Last active August 29, 2015 14:01
Deceivingly simple answer to a view animation that keeps it's content in the same visual place as the view frame moves.
- (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key {
DDLogVerboseMethodCall(@" %@", [anim debugDescription]);
CAAnimation *finalAnim = anim;
if ([key isEqualToString:@"position"] && [anim isKindOfClass:[CABasicAnimation class]]) {
CABasicAnimation *contentsRectAnim;
CALayer *presentationLayer = [self presentationLayer];
if (presentationLayer) {
contentsRectAnim = [anim copy];
contentsRectAnim.keyPath = @"contentsRect";
@snown
snown / Array+prepend
Last active August 29, 2015 14:02
A little extension to Array to allow prepending an item. This is just an experiment, not necessarily the right way to do it.
extension Array {
mutating func prepend(newitem: T) {
insert(newitem, atIndex: 0)
}
mutating func prepend(itemArray: Array) {
for (index, item) in enumerate(itemArray) {
insert(item, atIndex: index)
}
}
}
@snown
snown / playgroundUtil
Last active August 5, 2016 08:23
Quick bash script for converting Swift playgrounds between Mac and iOS.
#!/usr/bin/env bash
VERSION=0.1.0
USAGE="$(basename "$0") [--ios|--mac] [-f ./file.playground] [Files...]
where:
-h Show this help text
--ios Tells the command to turn the playground into a iOS compatible playground (default).
--mac Tells the command to turn the playground into a iOS compatible playground.
-f The path to a playground file (or you can leave out and all trailing arguments are parsed for playgrounds).
@snown
snown / launch-list.sh
Created September 28, 2014 00:39
A script to search both root and user launchctrl scripts currently registered with the system
#!/usr/bin/env bash
LAUNCH_LIST_PATH=/tmp/launchList
touch $LAUNCH_LIST_PATH
launchctl list > $LAUNCH_LIST_PATH
sudo launchctl list >> $LAUNCH_LIST_PATH
head -n 1 $LAUNCH_LIST_PATH
grep "$@" $LAUNCH_LIST_PATH
@snown
snown / UITextView+MTRXUILabel.h
Created October 1, 2014 19:20
UITextView Category for initializing a text view with a specified UILabel object
//
// UITextView+MTRXUILabel.h
// Site Survey
//
// Created by Logan Holmes on 10/1/14.
// Copyright (c) 2014 Logan Holmes. All rights reserved.
//
#import <UIKit/UIKit.h>
@snown
snown / AccountController.php
Created March 15, 2015 01:40
FatalErrorException in AccountController.php: Class 'App\Facades\QueryCache' not found
<?php namespace App\Http\Controllers;
use App\Facades\QueryCache;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Account;
use DebugBar\DebugBar;
use Illuminate\Database\Eloquent\Builder as EloquentQuery;
@snown
snown / update-plexmediaserver
Last active January 14, 2017 00:23
A Plex Media Server update script for Linux. Checks local PMS if update is available, then attempts to download and install the update is one exists.
#!/usr/bin/env bash
scriptSudo() {
local SUDO_IS_ACTIVE
SUDO_IS_ACTIVE=$(sudo -n uptime 2>&1|grep "load"|wc -l)
if [[ ${SUDO_IS_ACTIVE} -le 0 ]]; then
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until `.osx` has finished
@snown
snown / roll.sh
Last active February 5, 2018 20:11
bash script for rolling nerdy dice
#!/usr/bin/env bash
# Only supports one die, and the most basic notation right now
# would like to complete support for dice notation as specified here:
# https://en.wikipedia.org/wiki/Dice_notation
_basename() { #portable basename
[ -z "${1}" ] && return 1 || _basename__name="${1%%/}"
[ -z "${2}" ] || _basename__suffix="${2}"
case "${_basename__name}" in
/*|*/*) _basename__name="$(expr "${_basename__name}" : '.*/\([^/]*\)')" ;;
@snown
snown / uniqueElements.sh
Created March 26, 2020 22:12
Get unique elements in Bash
function uniqueElements {
local input_array=( "$@" )
local IFS=$'\n'
local RESULT=( $(printf '%s\n' ${input_array[@]} | awk '!seen[$0]++') )
# Uncomment if you want the result to come back in a format that can easily be passed to `declare -a`
#echo $(declare -p RESULT | sed "s/^[^(]*// ; s/'$//")
echo "${RESULT[@]}"
}
@snown
snown / Get Frame.md
Last active April 28, 2020 19:09
Grab a frame of a video file (Specifically for Mac)

Installing the script

sudo mkdir -p /usr/local/bin &>/dev/null ; sudo curl -fsSL -o /usr/local/bin/getframe "https://gist.githubusercontent.com/snown/a818afd18c9e2087731bdf7ce0a85195/raw/getframe.sh" && sudo chmod a+x /usr/local/bin/getframe

Install the folder action

getframe install-folder-action