This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias BlockerList = [[String: [String: String]]] | |
private static func generateBlacklistJSON(from trackerList: [String]) -> BlockerList { | |
var blacklist: BlockerList = [] | |
for tracker in trackerList { | |
blacklist.append([ | |
"action": ["type": "block"], | |
"trigger": ["url-filter": String(format: "https?://(www.)?%@.*", tracker)] | |
]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static func fetchAndParseTrackerList(completion: @escaping (BlockerList) -> Void ) { | |
var parsedLines: [String] = [] | |
// Fetch JSON file containing the list of trackers to block | |
Alamofire.request(Constants.trackerListURL).responseData { response in | |
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) { | |
let lines = utf8Text.components(separatedBy: .newlines) | |
for line in lines { | |
if line.starts(with: "#") || line.isEmpty { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"action": { | |
"type": "block" | |
}, | |
"trigger": { | |
"url-filter": "webkit.svg" | |
} | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func sendMessageToTelegram(withText text: String) { | |
// Send messages on telegram | |
let apiToken = "YOUR_TELEGRAM_TOKEN" | |
let chatId = "@YOUR_TELEGRAM_CHAT_NAME" | |
let strUrl = String(format: "https://api.telegram.org/bot%@/sendMessage?chat_id=%@&text=%@", apiToken, chatId, text.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!) | |
Alamofire.request(strUrl).responseJSON { response in | |
if let json = response.result.value { | |
print("JSON: \(json)") // serialized json response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Initiates HK queries for new data based on the given type | |
/// | |
/// - parameter type: `HKObjectType` which has new data avilable. | |
private func handleSample(_ sample: HKSample) { | |
switch sample.sampleType { | |
case HKObjectType.categoryType(forIdentifier: .sleepAnalysis): | |
guard let totalTimeAsleep = sample.metadata?["Asleep"] as? Double else { | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var myAnchor: HKQueryAnchor? | |
/// Sets up the observer queries for background health data delivery. | |
/// | |
/// - parameter types: Set of `HKObjectType` to observe changes to. | |
private func setUpBackgroundDeliveryForDataTypes(types: Set<HKObjectType>) { | |
for type in types { | |
guard let sampleType = type as? HKSampleType else { print("ERROR: \(type) is not an HKSampleType"); continue } | |
if let anchorData = UserDefaults.standard.object(forKey: "anchor") as? Data { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let healthStore = HKHealthStore() | |
/// Requests access to all the data types the app wishes to read/write from HealthKit. | |
/// On success, data is queried immediately and observer queries are set up for background | |
/// delivery. This is safe to call repeatedly and should be called at least once per launch. | |
func requestAccessWithCompletion(completion: @escaping AccessRequestCallback) { | |
guard HKHealthStore.isHealthDataAvailable() else { | |
debugPrint("Can't request access to HealthKit when it's not supported on the device.") | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import HealthKit | |
/// Types of data that this app wishes to read from HealthKit. | |
/// | |
/// - returns: A set of HKObjectType. | |
private func dataTypesToRead() -> Set<HKObjectType> { | |
return Set([ | |
HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis)!, HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.mindfulSession)! | |
]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let healthKitManager = HealthKitManager() | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
healthKitManager.requestAccessWithCompletion() { success, error in | |
if success{ print("HealthKit access granted") } | |
else { print("Error requesting access to HealthKit: \(error!)") } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
import re | |
import urllib.parse | |
import sys, os | |
import json | |
from requests_toolbelt import MultipartEncoder | |
BASE_URL = 'https://mbasic.facebook.com' |