Skip to content

Instantly share code, notes, and snippets.

View Kernix13's full-sized avatar
💭
Still looking for a job - but losing hope

Jim Kernicky Kernix13

💭
Still looking for a job - but losing hope
View GitHub Profile
@Kernix13
Kernix13 / index.html
Last active April 6, 2024 16:18
Back To Top Button
<!-- Simpler version on my portfolio site:
https://jameskernicky.netlify.app/
https://github.com/Kernix13/personal-portfolio
-->
<button id="back-to-top-btn"><i class="fa-solid fa-angle-up"></i></button>
<!-- Bootstrap icon instead of font awesome -->
<svg
xmlns="http://www.w3.org/2000/svg"
@Kernix13
Kernix13 / NetlifyFunctions.md
Created March 31, 2024 15:35
Netlify function example

Structure of a Netlify Function

  1. Create a /netlify folder and inside create /functions folder, and inside create a .js file for your function
  2. OPTIONAL: require MongoClient if you are using MongoDB
  3. Create an async function named handler
  4. OPTIONAL: Connect to the database, get your data, then close DB connection
  5. Return an object with statusCode, headers (optional), and body properties
@Kernix13
Kernix13 / app.js
Created March 31, 2024 15:07
Full-stack EJS, Node & Express app.js example
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const ejsMate = require('ejs-mate');
const methodOverride = require('method-override');
@Kernix13
Kernix13 / retreat.js
Created March 31, 2024 15:01
Mongoose model and schema
// npm i express mongoose
// create a /models folder, inside create retreat.js,
// model name = 'Retreat', the schema = RetreatSchema
const mongoose = require('mongoose');
const { Schema } = mongoose;
const RetreatSchema = new mongoose.Schema({
title: String,
image: String,
price: Number,
@Kernix13
Kernix13 / app.js
Created March 31, 2024 14:54
EJS views and first basic route (Node and Express.js)
// add to app.js
const path = require('path');
/* Set EJS as the view engine */
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// change res.send to res.render
app.get('/', (req, res) => {
res.render('home');
@Kernix13
Kernix13 / app.js
Created March 31, 2024 14:53
Basic Node and Express.js Server
// npm i express mongoose ejs
// in app.js
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Home Route');
});
app.listen(3000, () => {
@Kernix13
Kernix13 / loginAttempt.js
Created March 30, 2024 18:14
Set server cookie
// npm install cookie
const cookie = require('cookie');
const handler = async (event) => {
const body = JSON.parse(event.body);
// pick a generic username and password for now
if (body.username == "some_name" && body.password == "some_password") {
@Kernix13
Kernix13 / isAdmin.js
Last active March 30, 2024 18:12
Check for server cookie
// Setting cookie for logged in admin
// run npm install cookie then:
// petadoption is the name of the cookie for this example
const cookie = require('cookie');
function isAdmin(event) {
const incomingCookie = cookie.parse(event.headers.cookie || '');
if (incomingCookie?.petadoption == 'apsodifugyhtjrkelwqzmxncbv0918273645') {
return true;
@Kernix13
Kernix13 / functions.php
Created March 30, 2024 18:02
Google Analytics loaded via wp_print_scripts
/*
DELETE THIS COMMENT BLOCK
1. replace 'yourtheme' in yourtheme_google_print_scripts with your theme name
- it occurs twice in the code below
2. replace the URL below that ends with 'ABC123' with your URL
3. replace 'ABC123' argument below in the 'gtag' function
4. Paste all of the code to the bottom of your functions.php file in the child theme or custom theme
*/
function yourtheme_google_print_scripts() { ?>
<!-- Global site tag (gtag.js) - Google Analytics -->
@Kernix13
Kernix13 / recent-posts-category.php
Created July 26, 2023 15:21
WordPress Category Recent Posts
<!-- Add before endwhile in single.php or as a plugin -->
<aside class="bgcolor4">
<div class="container">
<h3 class="custom-title"><?php esc_html_e('Similar articles you may like... ', 'tower') ?></h3>
<div class="row">
<?php
$cats = wp_get_post_categories( get_the_ID(), ['fields'=>'ids',]);
$relatedPosts = get_posts(