Skip to content

Instantly share code, notes, and snippets.

{
"id": 302228,
"content": "Philadelphia reported 126 new COVID-19 cases and 17 deaths Friday.",
"bert_tags": [
"Philadelphia"
],
"identifier": "default",
"article_id": 5097
}
import spacy
nlp = spacy.load("en_core_web_sm")
article = "I have lived in Philadelphia for most of my life. I went to school in New York City."
doc = nlp(article)
[sent for sent in doc.ents]
# Output: [Philadelphia, New York City]
import spacy
nlp = spacy.load("en_core_web_sm")
article = "This is the content of the article. It consists of many sentences."
doc = nlp(article)
[sent.text for sent in doc.sents]
# Output: [‘This is the content of the article.’, ‘It consists of many sentences.’]
@ajayjapan
ajayjapan / example.swift
Last active November 28, 2018 11:15
UNLocationNotificationTrigger Example
// Define the content of the notification
let content = UNMutableNotificationContent()
content.title = place.title
content.body = place.blurb
content.sound = UNNotificationSound.default()
// Define the region
let region = CLCircularRegion(center: place.coordinate(), radius: place.radius ?? 100, identifier: place.identifier)
region.notifyOnEntry = true
region.notifyOnExit = false
@ajayjapan
ajayjapan / motionMonitoring.swift
Last active November 29, 2018 13:01
Here App Motion Monitoring and Notification Skipping Logic
// MARK - Motion Tracking Logic
func startTrackingMotionActivity(handler: @escaping (CMMotionActivity) -> Void) {
manager.startActivityUpdates(to: .main) { (activity) in
guard let activity = activity else { return }
if let lastActivity = self.currentActivity, lastActivity.automotive {
self.stoppedDrivingAt = Date() // now
}
self.currentActivity = activity
handler(activity)
@ajayjapan
ajayjapan / regionMonitoring.swift
Last active November 28, 2018 09:23
Here App Region Monitoring and Notification Trigger Logic
// MARK: - Significant location change montioring logic
// Called at launch of application if permission is already granted
func startMonitoringSignificantLocationChanges() {
locationManager.startMonitoringSignificantLocationChanges()
}
// Called by location manager if there is a significant location change
func locationManager(_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]) {
@ajayjapan
ajayjapan / permutations.m
Last active October 3, 2016 01:55
Given a string return all the permutations of that string.
-(NSArray<NSString> *)permutationsOfString:(NSString *)s {
NSMutableArray<NSString> *res = [NSMutableArray array];
if (s.length == 1) {
[res addObject:s];
} else if (s.length > 1) {
int lastIndex = s.length - 1;
String last = s.substring(lastIndex);
String rest = s.substring(0, lastIndex);
res = merge(permutation(rest), last);
}
@ajayjapan
ajayjapan / main.m
Created October 3, 2016 01:46
Two functions on how to handle zero elements in an NSArray
#import <Foundation/Foundation.h>
#import <stdio.h>
@interface MyClass : NSObject
@end
@implementation MyClass
// 1. returns the number of non-zero elements (4)
+ (int)numberOfZeroElementsInArray:(NSArray *)array {
@ajayjapan
ajayjapan / RPSGameViewController.m
Created October 2, 2015 21:36
1. Modify line 402 in RPSGameViewController.m 2.logging in and out multiple times 3. get 308 error
case 4: { // Login and logout
if ([FBSDKAccessToken currentAccessToken]) {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Clear up all the user defaults here.
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
[defaults synchronize];
@ajayjapan
ajayjapan / gist:5e7ba49e51f1ca24b76d
Created August 28, 2014 18:16
Adjust content size of collection view when flexible iOS 8 simulator size changes
@interface UICollectionViewFlowLayout (InvalidateOnBoundsChange)
@end
@implementation UICollectionViewFlowLayout (InvalidateOnBoundsChange)
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewLayoutInvalidationContext *context = [super invalidationContextForBoundsChange:newBounds];
CGRect oldBounds = self.collectionView.bounds;
CGFloat widthAdjustment = newBounds.size.width - oldBounds.size.width;