Skip to content

Instantly share code, notes, and snippets.

View Fogh's full-sized avatar

Anders Fogh Eriksen Fogh

View GitHub Profile
@Fogh
Fogh / gist:1147189
Created August 15, 2011 16:56
Get jQuery from Google API, and if unavailable get local version instead.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>
OnClick='<%# Response.WriteFile(Eval("ItemNumber").ToString() + "_c.pdf") %>'
@Fogh
Fogh / gist:1811381
Created February 12, 2012 22:59
MailComposeViewController - Send email in iOS
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
break;
case MFMailComposeResultSent:
@Fogh
Fogh / gist:2016978
Created March 11, 2012 16:11
Google Analytics Script
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
@Fogh
Fogh / DLog.m
Last active December 19, 2015 01:39
DLog - Only show logs when debugging. Add to your projects Prefix.pch file
#ifdef DEBUG
#define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#else
#define DLog(...) do { } while (0)
#endif
@Fogh
Fogh / gist:7768936
Last active December 30, 2015 03:19
CVRAPI.dk example
- (NSString *)getCompanyName
{
NSURL *url = [NSURL URLWithString:@"http://cvrapi.dk/10150817"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
NSDictionary *response = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *companyName = [response objectForKey:@"navn"];
return companyName;
}
@Fogh
Fogh / gist:9806281
Created March 27, 2014 12:18
WCF JSON Date to NSDate
- (NSDate *)deserializeJsonDateString:(NSString *)jsonDateString
{
NSInteger offset = [[NSTimeZone defaultTimeZone] secondsFromGMT];
NSInteger startPosition = [jsonDateString rangeOfString:@"("].location + 1;
NSTimeInterval unixTime = [[jsonDateString substringWithRange:NSMakeRange(startPosition, 13)] doubleValue] / 1000;
return [[NSDate dateWithTimeIntervalSince1970:unixTime] dateByAddingTimeInterval:offset];
}
@Fogh
Fogh / gist:9807038
Created March 27, 2014 13:01
NSDate to WCF JSON date string
- (NSString *)dateToJSONDate:(NSDate *)date
{
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"Z"];
return [NSString stringWithFormat:@"/Date(%.0f000%@)/", [date timeIntervalSince1970], [formatter stringFromDate:date]];
}
@Fogh
Fogh / CVRAPI.swift
Last active August 29, 2015 14:02
Get Company name by CVR number
import Cocoa
let baseUrl = "http://cvrapi.dk/api"
func getCompanyName(vat: String, country: String) -> String {
let urlString = baseUrl + "?search=\(vat)&country=\(country)"
let url = NSURL.URLWithString(urlString, relativeToURL: nil)
var error: NSError?
let data = NSData.dataWithContentsOfURL(url, options: nil, error: &error)
let response = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
@Fogh
Fogh / gist:0e1325d7e7593234c005
Last active August 29, 2015 14:06
Set version in Settings.bundle
cd "$PROJECT_DIR"
cd "$BUILT_PRODUCTS_DIR/$WRAPPER_NAME"
RELEASE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" Info.plist)
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:0:DefaultValue $RELEASE_VERSION" Settings.bundle/Root.plist