Skip to content

Instantly share code, notes, and snippets.

@BoDonkey
BoDonkey / iconsList.txt
Created June 15, 2023 09:58
List of icons in Vue-material-design-icons v4.12.1
AbTesting
Abacus
AbjadArabic
AbjadHebrew
AbugidaDevanagari
AbugidaThai
AccessPoint
AccessPointCheck
AccessPointMinus
AccessPointNetwork
@BoDonkey
BoDonkey / index.js
Created March 30, 2023 21:00
Adds testing for a forbidden schema name of "type"- code gets inserted after line 181 of `/piece-type/index.js`
const badFieldName = Object.keys(self.fields).indexOf('type') !== -1;
if (badFieldName) {
throw new Error('@apostrophecms/piece-type field property name cannot be "type"');
}
@BoDonkey
BoDonkey / pieces-malformed.js
Created March 30, 2023 20:55
test to check if the schema field is forbidden
const t = require('../test-lib/test.js');
const assert = require('assert');
let apos;
const apiKey = 'this is a test api key';
describe('Pieces malformed', function () {
this.timeout(t.timeout);
after(async function () {
@BoDonkey
BoDonkey / index.js
Created March 12, 2023 12:44
Webpack options to use vue2 front-end components in ApostropheCMS
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const path = require('path');
module.exports = {
// When not in production, refresh the page on restart
options: {
refreshOnRestart: true
},
webpack: {
extensions: {
@BoDonkey
BoDonkey / middleware.js
Created January 20, 2023 20:44
Middleware for redirecting based on locale
module.exports = {
...
middleware(self, options) {
return {
checkLanguage(req, res, next) {
// if you are only doing this for the homepage, check that is the page being requested
// possibly using req.originalUrl or the url property
// https://v3.docs.apostrophecms.org/reference/module-api/module-overview.html#middleware-self
// make sure
// if not a page you need to redirect just return next()
@BoDonkey
BoDonkey / translation.js
Created December 15, 2022 18:18
Translates an i18n JSON file to a different language
const fs = require('fs').promises;
const translate = require('google-translate-api-x');
async function translateIt(file) {
try {
// read file and parse it as JSON
const data = await fs.readFile(file, 'utf8');
const obj = JSON.parse(data);
// prepare an array of translation keys and an array of translation strings
@BoDonkey
BoDonkey / ColorPicker.vue
Created December 5, 2022 10:32
Vue color picker code written by chatGPT
// Define the component
Vue.component('gradient-picker', {
// The component's options go here
data() {
return {
angle: 0, // The angle of the gradient
colors: [ // An array of objects representing the gradient's colors
{
color: '#000000', // The color's hex code
start: 0, // The color's start position in the gradient (as a percentage)
@BoDonkey
BoDonkey / password-reset-thoughts.md
Created September 14, 2022 19:14
password reset

TLDR; Basically you have to implement a button in Vue that when click redirects to a page that collects the users email and checks they exist. Then you generate a (time-sensitive?) code you send them by email. That email redirects to a third page which collects and error sniffs the new password. If it checks out, the password is changed or an error is thrown.

Within an a2 project, the password reset code is primarily in node_modules/apostrophe/lib/modules/apostrophe-login. There is code in the index.js file, plus several HTML pages in the views folder of that folder. The passwordResetRequest.html file is a form for requesting a password change.

@BoDonkey
BoDonkey / docker.md
Created September 14, 2022 14:23
Building Docker images for Apostrophe

Building Docker images for Apostrophe projects

Docker is a containerization platform that lets developers build an image for their projects and then run it anywhere. This guide is for production, not development. If you want to use Docker as a development environment, you can explore using a persistent Docker volume for your project, but bear in mind that commands like npm install can be very slow in such a configuration.

The initial steps of this guide will assume that you will be hosting your database, project, and uploaded assets on the same server. The second part will outline steps for configuring to use the AWS S3 service for hosting assets. Finally, the third portion will provide guidance for using the MongoDB Atlas multi-cloud database.

Creating the image

Install Docker

Docker can be installed on Mac, Windows, and Linux machines with either a CLI interface or using the Docker Desktop application, which acts as a graphical interface to the Docker engine. For this

@BoDonkey
BoDonkey / javascript-proxy-as-rest-client.js
Created February 8, 2022 10:42 — forked from DavidWells/javascript-proxy-as-rest-client.js
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
return async function(id = "") {
const response = await fetch(`${url}/${key}/${id}`)
if (response.ok) {
return response.json();