Skip to content

Instantly share code, notes, and snippets.

View aokj4ck's full-sized avatar
❄️

Jack Alto aokj4ck

❄️
View GitHub Profile
// Construct startDate and endDate objects with NSDateComponents.
// See this article for more http://iaintheindie.com/2014/08/08/useful-nsdate-nscalendar-tricks/#StartEnd_of_the_Week
// For more examples of working with HealthKit see https://developer.apple.com/library/content/samplecode/Fit/Introduction/Intro.html
let workoutPredicate = NSPredicate(format: "(%K == %d) OR (%K == %d)",
HKPredicateKeyPathWorkoutType,
HKWorkoutActivityType.functionalStrengthTraining.rawValue,
HKPredicateKeyPathWorkoutType,
HKWorkoutActivityType.traditionalStrengthTraining.rawValue)
@aokj4ck
aokj4ck / test-decimal-numpy-array.py
Created July 10, 2015 01:36
Python: Decimal array with Numpy test
import numpy
import decimal
items = [decimal.Decimal(x) for x in range(0, 20)]
array = numpy.array(items, dtype=decimal.Decimal)
array.mean()
# OS X, python 2.7.6:
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
@aokj4ck
aokj4ck / UIViewController+PromptToast.swift
Last active August 29, 2015 14:09
Swift class extension on UIViewController using the navigation item to display a toast for a given number of seconds.
import UIKit
import Dispatch
struct PromptToast {
static let ErrorMessageDisplayDuration = 5.2
}
extension UIViewController {
func toast(message: String, duration: Double) {
/* Make sure we have a navigation controller */
@aokj4ck
aokj4ck / rename_numerical.sh
Created March 8, 2013 16:56
Wanted to rename a folder of images to a prefix with a number after each. Hacked this up instead of renaming them manually. Requires modifying to whatever prefix and filetype you want.
#!/bin/bash
count=1
files="$(ls)"
for X in $files
do
mv $X "prefix${count}.filetype"
count=$((count+1))
done
@aokj4ck
aokj4ck / csc.rb
Created March 12, 2012 00:06
Comment Spell Check with incomplete support for ignored words file
#!/usr/bin/env ruby
require 'raspell'
class CommentSpellCheck
SP = Aspell.new("en") #initialize our spell checker
SP.suggestion_mode = Aspell::NORMAL
SP.set_option("ignore-case", "false") #case sensitivity is important to us
# Regex to find text within documentation code comments, not plain // comments or regular block comments /* */. Only /** */ comments
@@comment_regex = /\/\*([\w\d\W\D]+?)\*\//
@aokj4ck
aokj4ck / shufflelinks.php
Created February 9, 2012 22:43
Shuffle your links on every page load/refresh.
@aokj4ck
aokj4ck / yga.sh
Created September 14, 2011 18:05
Yesterday's Git Activity (yga) gives you a text file `status.txt` with `git status` and yesterday's commit log.
#cd /Path/To/Repo
rm status.txt
touch status.txt
git status >> status.txt
echo '' >> status.txt
git log --since='08:00 yesterday' --until='20:00 yesterday' >> status.txt
open status.txt -e
@aokj4ck
aokj4ck / getAppNameAndVersionNumber
Created June 1, 2011 15:22
Retrieves the application name and version number which are set in info.plist
static NSString *getAppNameAndVersionNumber() {
NSString *number = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
NSString *nameAndVersion = [NSString stringWithFormat:@"%@_%@", appName, number];
return nameAndVersion;
}