Skip to content

Instantly share code, notes, and snippets.

@iAmWillShepherd
iAmWillShepherd / ExampleBehaviour.cs
Last active May 14, 2024 15:30
Snippet showing how to initialize OneSignal Unity SDK
using System;
using UnityEngine;
using UnityEngine.UI;
using OneSignalSDK;
public class ExampleBehaviour : MonoBehaviour
{
public OSConfigData configData;
public string externalId;
@iAmWillShepherd
iAmWillShepherd / OS.tsx
Last active April 24, 2024 20:05
Code snippet for initializing OneSignal in React Native
import * as React from 'react';
import { APP_ID } from '@env';
import { OneSignal} from 'react-native-onesignal';
class OS extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { };
}
@iAmWillShepherd
iAmWillShepherd / MyApp.swift
Last active April 24, 2024 20:22
Snippet showing OneSignal User Model SDK initialization in Swift for Apple devices.
import SwiftUI
import DotEnv
import OneSignalFramework
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
@iAmWillShepherd
iAmWillShepherd / main.dart
Created April 24, 2024 19:47
Snippet for initializing OneSignal User Model SDK in Flutter
import 'package:flutter/material.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
import 'package:flutter_application_la/live_actiivties_manager.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@iAmWillShepherd
iAmWillShepherd / swift-if-vs-guard.md
Created June 29, 2022 15:01
If statements vs Guard statements
if true {
  print("This statement gets executed when condition is true")
}

vs.

guard true else {
@iAmWillShepherd
iAmWillShepherd / swift-return-closure.md
Created June 17, 2022 19:18
How to return a closure from a function.
func greetingMaker(greeting: String)  -> (String) -> String {
  return {
      "\(greeting), \($0)"
  }
}

let hello = greetingMaker(greeting: "Hello")

hello("world") // "Hello, World"
@iAmWillShepherd
iAmWillShepherd / remove-vscode.sh
Created April 11, 2022 17:58
Removes all VSCode artifacts
#!/bin/sh
rm -rfv .vscode ~/Library/Application\ Support/Code ~/Library/Caches/com.microsoft.VSCode ~/Library/Saved\ Application\ State/com.microsoft.VSCode.savedState
@iAmWillShepherd
iAmWillShepherd / dart-late-keyword.dart
Last active February 25, 2022 17:05
Lazily initialize variables in Dart using the late keyword
void main() {
late String s = superCostlyInitializer(); // `s` is not initialized yet
print(s); // `s` is initialized now that it's needed
}
String superCostlyInitializer() {
return "A lot of work went into initializing this result";
}
@iAmWillShepherd
iAmWillShepherd / dart-format.md
Created February 22, 2022 16:40
How to ensure dart fomatting guidelines are enforced in your repo.

Using Dart's format command enables you to format all dart files in a project. Setting the --set-exit-if-changed flag will cause the formatter to return an exit code that can be used in CI to pass or fail a build.

$ dart format -o none --set-exit-if-changed
@iAmWillShepherd
iAmWillShepherd / dart-assign-if-null.dart
Created January 25, 2022 01:49
Syntax for Dart's assign if null operator
void main() {
var middleName = middle("iAmWillShepherd");
middleName ??= "This assignment won't happen.";
print(middleName); // Logs 'S' in the console
var noMiddle = middle("No middle exists");
noMiddle ??= "This assignment will happen.";
print(noMiddle); // This assignment will happen.
}