Skip to content

Instantly share code, notes, and snippets.

@jnjosh
jnjosh / WebKit-OmniFocus.applescript
Last active December 11, 2015 18:59
AppleScript for grabbing the title/url of the current tab in webkit and create an OmniFocus inbox item
tell application "WebKit"
set aTitle to name of current tab in front window
set aURL to URL of current tab in front window
end tell
tell application "OmniFocus"
set aTask to aTitle
set aNote to aURL
tell default document to make new inbox task with properties {name:aTask, note:aNote}
@jnjosh
jnjosh / gist:4589854
Created January 21, 2013 21:56
MPMediaItem issue...
MPMediaItem *item = ...; // From the Media Query
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
NSError *readerError = nil;
AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:asset error:&readerError];
if (! assetReader) {
NSLog(@"reader error for URL: %@ \r\n error:%@", url, [readerError localizedDescription]);
}
@jnjosh
jnjosh / fizzbuzz.hs
Last active December 10, 2015 14:49
Learning Haskell for fun. This gist is a log of changes I make to the fizzbuzz while learning. The revision history is the interesting part.
-- details: standard fizzbuzz, n % 3 = fizz, n % 5 = buzz, n % 15 = fizzbuzz
-- usage: ghci> fizzbuzz [1..100]
checkFizzbuzz :: Int -> String
checkFizzbuzz n
| mod n 15 == 0 = "fizzbuzz"
| mod n 5 == 0 = "buzz"
| mod n 3 == 0 = "fizz"
| otherwise = show n
@jnjosh
jnjosh / NSDictionary+Subtraction.h
Created February 1, 2012 01:45
A painfully simple and probably incomplete NSDictionary Subtraction method
@interface NSDictionary (Subtraction)
- (NSDictionary *)subtractDictionary:(NSDictionary *)dictionary;
@end
@jnjosh
jnjosh / TTPlaceholderTextView.h
Created January 18, 2012 21:21
TextView with a Placeholder option
//
// TTPlaceholderTextView.h
//
// Created by Joshua Johnson on 1/6/12.
// Copyright (c) 2012 Two Toasters. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TTPlaceholderTextView : UITextView
@jnjosh
jnjosh / gist:1469336
Created December 12, 2011 22:03
Calculate URL for Gravatar
static inline NSString *calculateURLForGravatar(NSString *email) {
const char *email_str = [email UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(email_str, strlen(email_str), result);
NSMutableString *hash = [NSMutableString stringWithString:@"http://www.gravatar.com/avatar/"];
for (int i = 0; i < 16; i++) {
[hash appendFormat:@"%02x", result[i]];
}
return [hash lowercaseString];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[webView setDelegate:self];
[webView loadHTMLString:@"<html><body><p id=\"content\">My Name is Josh</p></body></html>" baseURL:nil];
[self.window makeKeyAndVisible];
[self.window addSubview:webView];
return YES;
var fs = require("fs");
var file = "file.txt",
sum = 0,
chars = [];
/// @summary: aggregate values
function aggregater(value) {
if (parseInt(value, 10).toString() === value.toString()) {
sum += parseInt(value, 10);
return;
@jnjosh
jnjosh / lychrel.hs
Created September 20, 2010 00:32
Find Lychrel Numbers under 10,000 -- blatantly stolen from several samples
reverseNum :: (Integral a) => a -> a
reverseNum 0 = 0
reverseNum x = truncate 10 ^ (truncate (logBase 10.0 (fromIntegral x))) * (x `mod` 10) + reverseNum (x `quot` 10)
palindrome :: (Integral a) => a -> Bool
palindrome x = reverseNum x == x
lychrel :: (Integral a) => a -> a -> Bool
lychrel _ 100 = True
lychrel x y = if palindrome lych then False else lychrel lych (y + 1)
curl -i -H "Accept: application/json" --digest -u "<useremail>:<password>" http://my.cl.ly/items