Skip to content

Instantly share code, notes, and snippets.

Avatar
💯

Jordan Coeyman acoyfellow

💯
View GitHub Profile
@acoyfellow
acoyfellow / autocomplete.html
Created Apr 19, 2021
PhoneSites autocomplete example
View autocomplete.html
<script async
src="https://maps.googleapis.com/maps/api/js?key=***YOURAPIKEY***&libraries=places&callback=initMap">
</script>
<script>
window.initMap= function(){
const input = document.querySelector('input[name="address"]');
const options = {
componentRestrictions: { country: "us" },
fields: ["address_components", "geometry", "icon", "name"],
types: ["establishment"],
@acoyfellow
acoyfellow / hooks.js
Last active Jun 12, 2021
hooks.js CSP example
View hooks.js
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
// https://scotthelme.co.uk/content-security-policy-an-introduction/
// scanner: https://securityheaders.com/
const rootDomain = `your-domain.com`; // or your server IP for dev
const directives = {
'img-src': [
"*",
"'self'",
@acoyfellow
acoyfellow / example.html
Created Mar 24, 2021
Add a textarea into PhoneSites
View example.html
<-- 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 Mar 24, 2021
SvelteKit + pdf-lib
View pdf.pdf.js
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 Mar 18, 2021
SvelteKit server route example
View test.js
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 Mar 30, 2021
Example using firebase-admin in SK
View firebaseAdmin.js
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 Mar 18, 2021
Example of how to initialize firebase@exp
View firebaseClient.js
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 Mar 30, 2021
SvelteKit + firebase example in $layout.svelte
View $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 Apr 23, 2021
SvelteKit /src/hooks.js with cookie + firebase-admin
View hooks.js
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 Mar 10, 2021
peter custom script
View example.html
<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>