Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Answering Questions, & Questioning Answers

Saamer Mansoor saamerm

💭
Answering Questions, & Questioning Answers
View GitHub Profile
@saamerm
saamerm / alertlottie.json
Created Jul 15, 2022
An alert Lottie json file
View alertlottie.json
{"v":"5.7.1","fr":15,"ip":10,"op":45,"w":500,"h":500,"nm":"Comp 2","ddd":0,"assets":[{"id":"image_0","w":844,"h":821,"u":"","p":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0wAAAM1CAMAAAB0boGMAAAAJHpUWHRDcmVhdG9yAAAImXNMyU9KVXBMK0ktUnBNS0tNLikGAEF6Bs5qehXFAAAACXBIWXMAAAABAAAAAQBPJcTWAAAARVBMVEVHcEz4t6j3ppT4r5770sn/9vP/8O3+4tz62tP/6eX5v7H7zMH2nYnzf2XzinH1lH7////xc1b5xbnwZ0fvWzntQhzuTys7zAZPAAAAF3RSTlMAYXdsPAwUJzIdVkWDrJ6QBbxOzd397XBBxq0AACAASURBVHja7J3Lduu4DkQ1MClx9UT//7X3nkQiUUCBpF+JHQNW/La7B96ngAJILUtERERERERExGzs5CoiImIGG31hV+r1iIgIjsbXvX/Hflyrq51C9fVkkBXxgRrUfv9f9/dvgvYDo6V3tezmrXulC744IuJTlKjJzyKwOAMemFjk3QpYxS2YivgAjBalPpagPkXyrerTS8sGBVUBVcSfgkhK0QLlz4NDyp2ANmQq4q/kdI2jqRTuMUxptEKmIt4/pavF0FwOl/4dc1dXSFVzOZbgKeKdSLJytPT5OfA47uz1ilEkX03qYz2lEkVWiFTEu1RHO5h1XQFKp8YkT5PIE/i0+PyUaIVIRbyHHi3GoKM6dCDAGEn/j3q1J/XE8exxl6hTArEbOoFLeBMRL1chLVj3OwglyZDC5zzasy5OxxvUQfK+QQKIvamIiNcQpN11vFvmJSESpNSH53VKQpkSQQnfKzkySDaoko/TEhIV8Qok+RSpZA5+7iA4CIcESjzeyWv2W/D7sSzrVVPLHnOzEb+b3PkoqVpIZ2RCeHYC0I2xI31WqByRWhCpUKiIn8Ooz
@saamerm
saamerm / SwiftUICoreMotionView.swift
Last active Feb 14, 2022
Sample using CoreMotion and SwiftUI to help understand how to use CMMotionManager and CoreMotion to get values of gravity, user acceleration, heading (2), attitude (pitch, roll, yaw), magnetic field
View SwiftUICoreMotionView.swift
// Sample using CoreMotion and SwiftUI to help understand how to use CMMotionManager and CoreMotion to get values of gravity, user acceleration, heading (2), attitude (pitch, roll, yaw), magnetic field
// based on this beautiful example https://github.com/gsachin/DynamicFontRandD/blob/e4f7cc611d1d23573b4026bcc291bee60bf60e91/FontTextStrok/WaveView.swift
// that uses BAFluidView https://github.com/antiguab/BAFluidView
import SwiftUI
import CoreMotion
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
struct WaveView: View {
var motionManager = CMMotionManager()
@saamerm
saamerm / BackgroundNoiseAlert.swift
Created Feb 6, 2022
SwiftUI code to record audio from the user's mic and in real-time alert the user if there is a loud noise
View BackgroundNoiseAlert.swift
//
// BackgroundNoiseAlert.swift
//
// Created by Saamer Mansoor on 2/2/22.
//
import AVFoundation
import UserNotifications
import SwiftUI
@saamerm
saamerm / ContentView.swift
Created Dec 9, 2021
The simplest way possible to make an async call using SwiftUI, using the ChuckNorris ICNDB API as an example
View ContentView.swift
import Foundation
import SwiftUI
struct ContentView: View {
@State private var joke: String = ""
var body: some View {
Text(joke)
Button {
Task {
let (data, _) = try await URLSession.shared.data(from: URL(string:"https://api.chucknorris.io/jokes/random")!)
let decodedResponse = try? JSONDecoder().decode(Joke.self, from: data)
@saamerm
saamerm / JokeService.swift
Created Dec 1, 2021
Simplest way to make an API call in Swift
View JokeService.swift
import Foundation
private actor JokeServiceStore {
func load() async throws -> String {
let (data, _) = try await URLSession.shared.data(from: URL(string:"https://api.chucknorris.io/jokes/random")!)
let decodedResponse = try? JSONDecoder().decode(Joke.self, from: data)
return decodedResponse?.value ?? ""
}
}
class JokeService: ObservableObject {
View Steps to Migrate MVVMCross using PCL.txt
### Steps to perform migration of MvvmCross using PCL
(primarily done is Visual Studio for Mac)
This tutorial migrates
- PCL .Net solution to .NetStandard,
- MvvmCross 5 solution to MvvmCross 7.1,
- Android to AndroidX
#### The beginning
1. Create a new repository, with a Migration suffix
2. Inside it, create a New Blank Native Xamarin Template
@saamerm
saamerm / LeaderboardAPI.js
Last active Apr 3, 2021
Free and universal leaderboard/scoreboard for Games using Google Sheets
View LeaderboardAPI.js
// Note: For this to work, you just need to put your spreadsheet ID here in lines 26 and 43 and follow this tutorial https://medium.com/@prototypemakers/simplest-universal-free-game-leaderboard-with-google-sheets-5ab548db009f
// to see the steps for implementing this
// POST and GET API Entry points
// ------------
function doPost(request){
var requestObject = JSON.parse(request.postData.contents);
var result = processPostRequest(requestObject);
return ContentService
@saamerm
saamerm / IconSwitchService.cs
Created Dec 5, 2020
iOS Native Service that is connected to the Xamarin.Forms in order to progr.ammatically switch the App Icon after user installation. This is useful for allowing the user to personalize their app
View IconSwitchService.cs
using System.Threading.Tasks;
using AppIconUpdater.iOS;
using Xamarin.Forms;
using ui = UIKit.UIApplication;
[assembly: Dependency(typeof(IconSwitchService))]
namespace {YourNamespace}.iOS
{
public class IconSwitchService : IIconSwitchService
{
public async Task SwitchAppIconAsync(string iconName)
@saamerm
saamerm / AndroidAudioRecordingPlaybackService.cs
Created Dec 3, 2020
Sample Audio Recording service used for a Xamarin Forms application to record & play audio even if the user goes to the background. I expected to inherit from Android's Service, but I didn't need to do that
View AndroidAudioRecordingPlaybackService.cs
using Android;
using Android.App;
using Android.Media;
using Android.OS;
using Java.IO;
[assembly: Xamarin.Forms.Dependency(typeof(BackgroundRecord.Droid.AudioRecordingService))]
[assembly: UsesPermission(Manifest.Permission.RecordAudio)]
[assembly: UsesPermission(Manifest.Permission.ReadExternalStorage)]
[assembly: UsesPermission(Manifest.Permission.WriteExternalStorage)]
@saamerm
saamerm / TimeTrackingService.cs
Created Nov 30, 2020
Backgrounding service sample for Android
View TimeTrackingService.cs
using System;
using System.Timers;
using Android.App;
using Android.Content;
using Android.OS;
namespace SampleBackgroundServices.Droid
{
public class TimeTrackingService : Service
{