Skip to content

Instantly share code, notes, and snippets.

View acoyfellow's full-sized avatar
🤖
Building

Jordan Coeyman acoyfellow

🤖
Building
View GitHub Profile
@acoyfellow
acoyfellow / example.html
Created March 24, 2021 19:28
Add a textarea into PhoneSites
<-- place this in the Custom Code section, or in a clode block below the form -->
<script>
var form= document.querySelector('form');
var submitBtn= document.getElementById('submit');
var textareaWrap= document.createElement('div');
textareaWrap.className= 'relative db cf';
var textareaLabel= document.createElement('label');
textareaLabel.innerHTML= 'Textarea Label Here';
textareaWrap.appendChild(textareaLabel);
var textarea= document.createElement('textarea');
@acoyfellow
acoyfellow / pdf.pdf.js
Last active May 3, 2022 07:33
SvelteKit + pdf-lib
import pkg from 'pdf-lib/cjs/index.js';
const { PDFDocument } = pkg;
export const get = async (req, context) => {
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage();
page.drawText('You can create PDFs!');
const pdfBytes = await pdfDoc.save();
return {
body: Buffer.from(pdfBytes, 'binary'),
@acoyfellow
acoyfellow / test.js
Last active March 18, 2021 15:54
SvelteKit server route example
import { firebase } from "$services/firebaseAdmin";
export const get = async (req, context) => {
const globalRef = firebase.firestore().collection('global');
let data = {
now: Date.now()
};
const snapshot = await globalRef.get();
snapshot.forEach(doc => {
@acoyfellow
acoyfellow / firebaseAdmin.js
Last active March 30, 2021 20:42
Example using firebase-admin in SK
import admin from "firebase-admin";
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'your-url' // ...
});
};
const firebase = admin;
@acoyfellow
acoyfellow / firebaseClient.js
Created March 18, 2021 15:33
Example of how to initialize firebase@exp
import { initializeApp } from 'firebase/app';
import { getAuth, onAuthStateChanged } from "firebase/auth";
import { getFirestore } from 'firebase/firestore';
import { getStorage } from "firebase/storage";
let ssrAuthed = window.ssrUser;
const firebaseConfig = {
// ...
};
@acoyfellow
acoyfellow / $layout.svelte
Last active March 30, 2021 20:42
SvelteKit + firebase example in $layout.svelte
<script>
import "./styles.css";
import { session } from "$app/stores";
import { onMount, setContext } from "svelte";
import { writable } from "svelte/store";
let store = writable({});
setContext("store", store);
$: user = $session.user || null;
onMount(async () => {
@acoyfellow
acoyfellow / hooks.js
Last active April 23, 2021 07:09
SvelteKit /src/hooks.js with cookie + firebase-admin
import * as cookie from 'cookie';
import { firebase } from "$services/server/firebase";
const firestore = firebase.firestore();
export async function getContext({ headers }) {
let user = null;
try {
const cookies = cookie.parse(headers.cookie || "");
const sessionId = cookies["__session"];
@acoyfellow
acoyfellow / example.html
Created March 10, 2021 19:33
peter custom script
<script>
window.success= function(){
if(formData['Finance-Pre-Approved']==='Yes'){
redirect= "https://stellaproperty.phonesites.com/getfinanceprequalified";
}else if(formData['Finance-Pre-Approved']==='No'){
redirect= "https://phonesites.com";
};
};
</script>
@acoyfellow
acoyfellow / phonesites-redirect-example.html
Created March 9, 2021 11:53
Redirect based on Choice (PhoneSites.com)
<script>
window.success= function(){
if(formData.url==='A'){
redirect= "https://google.com";
}else if(formData.url==='B'){
redirect= "https://phonesites.com";
}else if(formData.url==='C'){
redirect= "https://yahoo.com";
};
};
@acoyfellow
acoyfellow / sapper-to-svelte-kit-conversion.md
Last active August 12, 2021 11:28
My personal Sapper to Svelte-Kit Cheat Sheet (this is not-official, and pre launch, don't use this unless you like fighting dragons and breaking changes)
  • change how you access goto -- from: import { goto } from "@sapper/app"; -- to: import { goto } from "$app/navigation";

  • change how you access sessions --from: