Skip to content

Instantly share code, notes, and snippets.

View KrishanMadushanka's full-sized avatar

Krishan Madushanka KrishanMadushanka

View GitHub Profile
func readHourlyTotalStepCount() {
guard let stepCountType = HKObjectType.quantityType(forIdentifier: .stepCount) else {
fatalError("*** Unable to get the step count type ***")
}
var interval = DateComponents()
interval.hour = 1
let calendar = Calendar.current
let anchorDate = calendar.date(bySettingHour: 0, minute: 55, second: 0, of: Date())
func readTotalStepCount() {
guard let stepCountType = HKObjectType.quantityType(forIdentifier: .stepCount) else {
fatalError("*** Unable to get the step count type ***")
}
let query = HKStatisticsQuery.init(quantityType: stepCountType,
quantitySamplePredicate: get24hPredicate(),
options: [HKStatisticsOptions.cumulativeSum, HKStatisticsOptions.separateBySource]) { (query, results, error) in
let totalStepCount = results?.sumQuantity()!.doubleValue(for: HKUnit.count())
print("Total step count: \(totalStepCount ?? 0)")
import SwiftUI
import HealthKit
struct ContentView: View {
@EnvironmentObject var healthStore: HKHealthStore
var body: some View {
VStack {
Image(systemName: "globe")
import SwiftUI
import HealthKit
@main
struct HealthkitIntegrationApp: App {
private let healthStore: HKHealthStore
init() {
guard HKHealthStore.isHealthDataAvailable() else { fatalError("This app requires a device that supports HealthKit") }
app.post("/refund-separate", async (req, res) => {
const refund = await stripe.refunds.create({
charge: "<charge id>",
});
});
app.post("/refund-destination", async (req, res) => {
const refund = await stripe.refunds.create({
charge: "<charge id>",
reverse_transfer: true,
refund_application_fee: true,
});
});
app.post("/refund-direct", async (req, res) => {
const refund = await stripe.refunds.create(
{
charge: "<charge id>",
refund_application_fee: true,
},
{
stripeAccount: "<connected account id>",
}
);
const API_URL = 'http://localhost:8000';
const refund = async () => {
const response = await fetch(`${API_URL}/refund`);
};
app.post("/refund", async (req, res) => {
const refund = await stripe.refunds.create({
payment_intent: 'pi_Aabcxyz01aDfoo'
});
});
app.post("/transfer", async (req, res) => {
const transfer = await stripe.transfers.create({
amount: 2000,
currency: "sek",
destination: "CONNECTED_STRIPE_ACCOUNT_ID",
transfer_group: "your first group",
});
});