This file contains 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
//Given a sorted bit array (values of either 0 or 1), determine the number of 1’s in the array. | |
// | |
//Perform this in O(log(N)) time complexity. | |
// | |
//Input: [0,0,0,1,1,1,1,1,1,1,1] | |
// | |
//Output: 8 | |
func numOnes(_ arr: [Int]) -> Int { |
This file contains 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
# Sort a Bit Array | |
func bitSort(_ arr: inout [Int]) { | |
var zerosCount = arr.filter { $0 == 0 }.count | |
var idx = 0 | |
while idx < arr.count { | |
arr[idx] = zerosCount > 0 ? 0 : 1 | |
zerosCount -= 1 | |
idx += 1 |
This file contains 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
UIWindow *window = [[UIWindow alloc] initWithFrame:rootWindow.bounds]; | |
window.hidden = NO; | |
window.windowLevel = UIWindowLevel_Background; | |
window.opaque = YES; | |
window.backgroundColor = UIColor.ows_materialBlueColor; | |
ScreenLockViewController *viewController = [ScreenLockViewController new]; | |
viewController.delegate = self; | |
window.rootViewController = viewController; |
This file contains 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
### Keybase proof | |
I hereby claim: | |
* I am nderkach on github. | |
* I am nderkach (https://keybase.io/nderkach) on keybase. | |
* I have a public key ASDzaBmzYWD5ZUcgOm4QY55kAjO3rA8NLqic3-KvhsHBzgo | |
To claim this, I am signing this object: |
This file contains 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
# def consecutive(arr): | |
# arr = sorted(arr) | |
# max_so_far_start = 0 | |
# max_so_far_end = 1 | |
# max_range = (0, 1) | |
# cur_i = 1 | |
# while cur_i <= len(arr): | |
# if cur_i != len(arr) and arr[cur_i] == arr[cur_i-1]+1: |
This file contains 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
Sales Path | |
The car manufacturer Honda holds their distribution system in the form of a tree (not necessarily binary). The root is the company itself, and every node in the tree represents a car distributor that receives cars from the parent node and ships them to its children nodes. The leaf nodes are car dealerships that sell cars direct to consumers. In addition, every node holds an integer that is the cost of shipping a car to it. | |
Take for example the tree below: | |
https://www.pramp.com/img/content/img_01.png | |
A path from Honda’s factory to a car dealership, which is a path from the root to a leaf in the tree, is called a Sales Path. The cost of a Sales Path is the sum of the costs for every node in the path. For example, in the tree above one Sales Path is 0→3→0→10, and its cost is 13 (0+3+0+10). |
This file contains 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 documentFolder = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.trackerblocker") | |
guard let jsonURL = documentFolder?.appendingPathComponent(Constants.blockerListFilename) else { | |
return | |
} | |
let attachment = NSItemProvider(contentsOf: jsonURL) |
This file contains 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 SafariServices | |
SFContentBlockerManager.reloadContentBlocker(withIdentifier: "ch.derka.TrackerBlocker.TrackerBlockerExtension", completionHandler: { error in | |
// Handle error | |
}) |
This file contains 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
guard let jsonData = try? JSONSerialization.data(withJSONObject: trackers, options: .prettyPrinted) else { | |
return | |
} | |
let documentFolder = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.trackerblocker") | |
guard let jsonURL = documentFolder?.appendingPathComponent(Constants.blockerListFilename) else { | |
return | |
} |
This file contains 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
class ContentBlockerRequestHandler: NSObject, NSExtensionRequestHandling { | |
func beginRequest(with context: NSExtensionContext) { | |
let attachment = NSItemProvider(contentsOf: Bundle.main.url(forResource: "blockerList", withExtension: "json"))! | |
let item = NSExtensionItem() | |
item.attachments = [attachment] | |
context.completeRequest(returningItems: [item], completionHandler: nil) | |
} | |
} |
NewerOlder