Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Open to work

Steph Crown Steph-crown

💻
Open to work
View GitHub Profile
@Steph-crown
Steph-crown / manifest.json
Created Jan 28, 2022
A web manifest file
View manifest.json
{
"name": "Studylove PWA",
"short_name": "Studylove",
"description": "This is a PWA tutorial created by Steph Crown",
"start_url": ".",
"background_color": "#B3D1FF",
"theme_color": "#0A0F75",
"display": "standalone",
"icons": [
{
@Steph-crown
Steph-crown / sw.js
Created Jan 28, 2022
Fetch event of service worker
View sw.js
// Runs whenever there is a fetch request
self.addEventListener("fetch", (event) => {
// Checks the cache to find matching request.
// If there is a cached version of the request, it returns the cached version, otherwise it makes a new request.
event.respondWith(
caches.match(event.request).then((res) => {
return res || fetch(event.request);
})
);
});
@Steph-crown
Steph-crown / sw.js
Last active Jan 28, 2022
A service worker file
View sw.js
// Listens to an install event
self.addEventListener("install", (event) => {
event.waitUntil(
// We try to open a cache named "assets".
// If it does not exist, a new one will be created and named "assets"
caches.open("assets").then((cache) => {
// Add an array of path to files you want to add to cache
return cache.addAll([
"./",
"./css/index.css",
@Steph-crown
Steph-crown / index.js
Last active Jan 28, 2022
A script to register a service worker
View index.js
// Checks if we can use serviceWorker.
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("sw.js")
.then((registration) => {
// The registration wass successful
console.log("Service worker registered");
console.log(registration);
})
@Steph-crown
Steph-crown / main.dart
Created Oct 16, 2020
Calculates product of prime factors of a number
View main.dart
///Checks if a number is prime
bool checkPrime(x) {
int factors = 0;
int i = 1;
//He number of factors of the number
while (i <= x) {
factors = x % i == 0 ? factors + 1 : factors;
i++;
}
@Steph-crown
Steph-crown / main.dart
Created Oct 16, 2020
Checks if a list is a subset of another list
View main.dart
///A function that checks if a list is a subset of another
bool subsetChecker(List list1, List list2) {
//Iterates through first array and checks if all element are in second array
return list1.every((item) => list2.contains(item));
}
void main() {
@Steph-crown
Steph-crown / main.dart
Created Oct 16, 2020
Palindrome checker
View main.dart
///A palindrome checker
bool checkPalindrome(String str) {
return str == reverseStr(str);
}
///A string reverser
String reverseStr(String str) {
return str.split('').reversed.join();
}
View palindrome checker
///A palindrome checker
bool checkPalindrome(String str) {
return str == reverseStr(str);
}
///A string reverser
String reverseStr(String str) {
return str.split('').reversed.join();
}
@Steph-crown
Steph-crown / main.dart
Created Oct 9, 2020
Uses while loop to print all letters in my name
View main.dart
void main(){
String name = 'Steph Crown';
int counter = 0;
while (counter < name.length) {
print(name[counter]);
++counter;
}
}
@Steph-crown
Steph-crown / main.dart
Created Oct 9, 2020
Prints out all the letters in my name
View main.dart
void main() {
String name = 'Steph Crown';
for (var j in name.split('')) {
print(j);
}
}