Skip to content

Instantly share code, notes, and snippets.

@bitwit
bitwit / gist:af3e12304a88f18ccee566540cf25cb0
Last active January 31, 2021 18:55
animation stack change after size class changes
import SwiftUI
final class SizeClassNotifier: ObservableObject {
@Published var currentSizeClass: UserInterfaceSizeClass =
.compact
func updateSizeClass(sizeClass: UserInterfaceSizeClass?) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.currentSizeClass = sizeClass ?? .compact
@bitwit
bitwit / Playground.swift
Created December 19, 2020 19:40
Conservation of Mass Jump
import UIKit
import PlaygroundSupport
import SwiftUI
struct ContentView: View {
var jumpAmount: CGFloat {
CGFloat(-time * time + time)
}
var scaleX: CGFloat { 1/scaleY }
@bitwit
bitwit / Int+ARKitMetricConversions.swift
Created August 7, 2018 16:27
Easy metric conversions for ARKit Floats using Int extensions
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 November 25, 2015 20:18
A functional javascript approach to a basic markdown parser. Inspired by a real interview question.
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 August 29, 2015 14:03
Angular js data example
<html>
<head>
<script type="text/preloaded">{"preloaded":true}</script>
</head>
<body>
<div ng-app="appModule"></div>
</body>
</html>
@bitwit
bitwit / app.js
Last active August 29, 2015 14:03
Angular data preloading
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);
- (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 February 20, 2014 20:27
Only open RFRateMe after a # of app uses
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 December 17, 2015 13:59
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
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 February 4, 2013 01:18
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/
#import <UIKit/UIKit.h>
#import "WebViewController.h"
@interface ViewController : WebViewController
@end