Skip to content

Instantly share code, notes, and snippets.

@bitwit
bitwit / Int+ARKitMetricConversions.swift
Created Aug 7, 2018
Easy metric conversions for ARKit Floats using Int extensions
View Int+ARKitMetricConversions.swift
import ARKit
// Example usage:
// let twentyCentimeters: Float = 20.cm
// let twoMeters: Float = 2.m
// let oneMillimeter: Float = 1.mm
// let extent: float3 = float3(20.cm, 10.cm, 1.m)
extension Int {
var mm: Float {
@bitwit
bitwit / BasicMarkdownParserExample.js
Last active Nov 25, 2015
A functional javascript approach to a basic markdown parser. Inspired by a real interview question.
View BasicMarkdownParserExample.js
var _ = require('underscore')
var lines = [
"#The test",
"###Hello World",
"This is a new paragraph.",
"It has a second line",
"",
"This is my new paragraph"
];
@bitwit
bitwit / index.html
Last active Aug 29, 2015
Angular js data example
View index.html
<html>
<head>
<script type="text/preloaded">{"preloaded":true}</script>
</head>
<body>
<div ng-app="appModule"></div>
</body>
</html>
@bitwit
bitwit / app.js
Last active Aug 29, 2015
Angular data preloading
View app.js
angular.module('appModule')
//app initialization
.constant('MY_CONFIG', {})
.config(['MY_CONFIG', function(MY_CONFIG){
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];
if(script.type === 'text/preloaded'){
var data = JSON.parse(script.innerHTML);
angular.extend(MY_CONFIG, data);
View ios view add shadow
- (void)setupShadowForView:(UIView *)view {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:view.frame cornerRadius:10];
CALayer *viewLayer = view.layer;
[viewLayer setShadowColor:[UIColor blackColor].CGColor];
[viewLayer setShadowOpacity:1.0f];
[viewLayer setShadowRadius:10.0f];
[viewLayer setShadowPath:[path CGPath]];
}
@bitwit
bitwit / gist:9122514
Created Feb 20, 2014
Only open RFRateMe after a # of app uses
View gist:9122514
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int timesOpened = [defaults integerForKey:@"timesOpened"];
NSLog(@"App has been opened %d times", timesOpened);
if(timesOpened >= 4){
[RFRateMe showRateAlert];
}
[defaults setInteger:(timesOpened+1) forKey:@"timesOpened"];
[defaults synchronize];
@bitwit
bitwit / Makefile
Last active Dec 17, 2015
Bridging Python and SMILE C++ Libraries For Linux Smile library availiable at: http://genie.sis.pitt.edu/index.php/downloads version used: Linux (x64) / gcc 4.4.5, March 6th 2013
View Makefile
CXX= g++
CXXFILES= pysmilebridge.cpp
CXXINTERMEDIATE= pysmilebridge.o
CXXOUTPUTLIBS= libpysmilebridge.so
CXXFLAGS= -O3 -DNDEBUG -ffast-math -Wall -fPIC
LIBS = -L/path/to/smile/ -lsmile
all: lib
lib:
@bitwit
bitwit / ViewController.h
Created Feb 4, 2013
The Objective-C ViewController from my blog entry An iOS5 Ready Native Web App Template http://www.bitwit.ca/blog/an-ios5-ready-native-web-app-template/
View ViewController.h
#import <UIKit/UIKit.h>
#import "WebViewController.h"
@interface ViewController : WebViewController
@end
@bitwit
bitwit / WebViewControllerDelegate.h
Last active Dec 12, 2015
The Objective-C WebViewControllerDelegate from my blog entry An iOS5 Ready Native Web App Template http://www.bitwit.ca/blog/an-ios5-ready-native-web-app-template/
View WebViewControllerDelegate.h
/**
* WebViewController is responsible for all
* messages that can be used in HTML
*/
@class WebViewController;
@interface WebViewControllerDelegate : NSObject <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, weak) WebViewController *webViewController;
@bitwit
bitwit / WebViewController.h
Last active Dec 12, 2015
The Objective-C WebViewController from my blog entry An iOS5 Ready Native Web App Template http://www.bitwit.ca/blog/an-ios5-ready-native-web-app-template/
View WebViewController.h
#import <UIKit/UIKit.h>
@class WebViewControllerDelegate;
@interface WebViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, strong) WebViewControllerDelegate *functionDelegate;
-(void)loadPageWithURL:(NSString *)url;
-(void)loadPageFromFile:(NSString *)html;
You can’t perform that action at this time.