Skip to content

Instantly share code, notes, and snippets.

View hungtruong's full-sized avatar

Hung Truong hungtruong

View GitHub Profile
  • Zingermans - amazing sandwiches
  • Lunch room - gourmet caferia food [smallish portions]
  • Afternoon Delight - not gourmet cafeteria food [close]
  • Mark's Carts - outdoor food carts [smallish portions]
  • Blue tractor - BBQ
  • Jersusalem Garden - falafel [cheap] [close]
  • Marnee Thai - thai
@hungtruong
hungtruong / keybase.md
Created March 12, 2014 17:36
something technical

Keybase proof

I hereby claim:

  • I am hungtruong on github.
  • I am hungtruong (https://keybase.io/hungtruong) on keybase.
  • I have a public key whose fingerprint is B1E1 7231 0901 3663 BD98 B7E6 CCF6 5E15 5446 A2B5

To claim this, I am signing this object:

@hungtruong
hungtruong / google_hangouts_css
Created May 13, 2014 15:45
Hide Google Hangouts last chat sent in user list with this css
@-moz-document domain("google.com") {
div.sQR2Rb {
display: none !important;
}
}
/// Prevents the user from swiping up to dismiss the app.
override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
return UIRectEdge.bottom
}
// Hides the home indicator on the inactive and passcode entry view
override func prefersHomeIndicatorAutoHidden() -> Bool {
switch passcodeViewMode {
case .inactive, .passcodeEntry:
return true
default:
return false
}
}
/// This method will start a timer to either "wake" the device or put it to sleep if it is in the right orientation.
/// On a timer because the real device seems to delay it by a bit.
func handleDeviceMotion(motion: CMDeviceMotion) {
// device is tilted up
if motion.attitude.pitch > 0.5 {
if tiltActionTimer == nil {
tiltActionTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (_) in
if self.passcodeViewMode == .inactive {
self.setPasscodeViewMode(.lockedScreen)
}
enum WorkoutSegment {
case warmup(duration: TimeInterval, powerLow: Double, powerHigh: Double)
case intervals(reps: Int, onDuration: TimeInterval, offDuration: TimeInterval, onPower: Double,
offPower: Double)
case steady(duration: TimeInterval, power: Double)
case cooldown(duration: TimeInterval, powerLow: Double, powerHigh: Double)
}
func wattage(for ftp: Int, interval: TimeInterval) -> Int {
switch self {
case .warmup(duration: let duration, powerLow: let powerLow, powerHigh: let powerHigh):
return Int((((interval / duration) * (powerHigh - powerLow)) + powerLow) * Double(ftp))
case .steady(duration: _, power: let power):
return Int(power * Double(ftp))
case .intervals(reps: _, onDuration: _, offDuration: _, onPower: _, offPower: _):
return 0
case .cooldown(duration: let duration, powerLow: let powerLow, powerHigh: let powerHigh):
return Int(((((duration - interval) / duration) * (powerHigh - powerLow)) + powerLow) * Double(ftp))
self.workoutSession = session
self.workoutBuilder = workoutSession.associatedWorkoutBuilder()
self.workoutBuilder.dataSource =
HKLiveWorkoutDataSource(healthStore: healthStore,
workoutConfiguration: workoutConfiguration)
self.workoutSession.delegate = self
self.workoutBuilder.delegate = self
self.workoutBuilder.beginCollection(withStart: Date()) { (_, _) in }
session.startActivity(with: Date())
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) {
for type in collectedTypes {
guard let quantityType = type as? HKQuantityType else {
return
}
switch quantityType {
case HKQuantityType.quantityType(forIdentifier: .heartRate):
guard let statistics = workoutBuilder.statistics(for: quantityType),
let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit)