Skip to content

Instantly share code, notes, and snippets.

@ajayjapan
ajayjapan / gist:73231c1df38c620fc6bf89c3a5b036c7
Created December 11, 2025 12:24
LiveStreamPreviewView.swift
import Foundation
import AVFoundation
import Observation
import SwiftUI
struct LiveStreamPreviewView: View {
@State var cameraPreview = CameraPreviewModel()
var body: some View {
@ajayjapan
ajayjapan / LightweightSocketIO.swift
Created December 8, 2025 06:25
A minimal Socket.IO-compatible client built on URLSessionWebSocketTask.
//
// LightweightSocketIO.swift
// fantrance
//
// A minimal Socket.IO-compatible client built on URLSessionWebSocketTask.
// It supports basic connect/disconnect, ping/pong, and event emit/on needed
// by FantranceSocketManager without pulling in the SocketIO dependency.
//
// Limitations (vs full Socket.IO client):
// - WebSocket-only: no HTTP long-polling fallback or upgrade flow.
@ajayjapan
ajayjapan / ios-url-schemes.json
Last active January 8, 2025 01:26 — forked from bartleby/iOS URL Schemes
iOS URL Schemes
{
"URL Schemes": {
"Apple Music": [
{
"description": "Opens an album in Apple Music",
"url": "music://geo.itunes.apple.com/us/albums/<albumID>"
},
{
"description": "Opens an artist in Apple Music",
"url": "music://geo.itunes.apple.com/us/artists/<artistID>"
{
"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 13, 2024 09:55
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);
}