Skip to content

Instantly share code, notes, and snippets.

View SpiffGreen's full-sized avatar
:octocat:
Available

Spiff Jekey-Green SpiffGreen

:octocat:
Available
View GitHub Profile
@SpiffGreen
SpiffGreen / index.html
Created July 5, 2022 02:29
Web1 - Frontend Heroku Hosting
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web App 1</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
@SpiffGreen
SpiffGreen / create.php
Created June 25, 2022 06:58
API with vanilla php
<?php
require_once "./config/db.php";
if ($_SERVER['REQUEST_METHOD'] === "POST") {
//Make sure that the content type of the POST request has been set to application/json
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if (strcasecmp($contentType, 'application/json') != 0) {
// throw new Exception('Content type must be: application/json');
exit('Content type must be: application/json');
@SpiffGreen
SpiffGreen / composer-setup.sh
Created June 20, 2022 13:14
Composer Setup
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'some-long-SHA-checksum-number-goes-here') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
@SpiffGreen
SpiffGreen / index.html
Created May 15, 2022 20:48
Temporal fix for html2canvas image generation for remote images
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js" integrity="sha512-BNaRQnYJYiPSqHHDb58B0yaPfCu+Wgds8Gp/gU33kqBtgNS4tSPHuGibyoeqMV/TJlSKda6FXzoEyYGjTe+vXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js" integrity="sha512-csNcFYJniKjJxRWRV1R7fvnXrycHP6qDR21mgz1ZP55xY5d+aHLfo9/FcGDQLfn2IfngbAHd8LdfsagcCqgTcQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
@SpiffGreen
SpiffGreen / ArrayCombination.js
Created May 2, 2022 14:59
A code snippet to produce permutation of an array
const test_array = [1, 2, 3];
function get_combinations(arr) {
var permArr = [],
usedChars = [];
function permute(input) {
var i, ch;
for (i = 0; i < input.length; i++) {
ch = input.splice(i, 1)[0];
usedChars.push(ch);
@SpiffGreen
SpiffGreen / ImageToAsciiText.js
Created April 28, 2022 06:46
Image pixel manipulation
/*
* @description An image to ascii text conversion library
*/
class ImageToAscii {
constructor(image) {
this.image = image;
this.toText = this.toText.bind(this);
}
@SpiffGreen
SpiffGreen / setup_video_feature.sh
Created April 2, 2022 05:29
Things to do after a new ubuntu installation
sudo apt install libdvdnav4 libdvd-pkg gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg
sudo apt install ubuntu-restricted-extras
@SpiffGreen
SpiffGreen / ast-to-html.js
Last active August 25, 2021 22:28
A simple implementation of ast-to-html and html-to-ast algorithms
const { htmlToAST, toks } = require("./html-to-ast");
const SELF_CLOSING_TAG = "SELF_CLOSING_TAG";
const OPENING_TAG = "OPENING_TAG";
const TEXT_ELEMENT = "TEXT_ELEMENT";
function astToHTML(ast) {
const start = "<" + ast.TagName + ">";
let mid = "";
const end = "</" + ast.TagName + ">";
@SpiffGreen
SpiffGreen / simple_markdown_parse.js
Created July 28, 2021 02:18
A simple function that evaluates and produces html from markdown
/**
* @description A simple function to parse markdown code into HTML
*/
const parseMarkdown = (str) => str.replace(/^# (.*$)/gim, "<h1>$1</h1>")
.replace(/^## (.*$)/gim, "<h2>$1</h2>")
.replace(/^### (.*$)/gim, "<h3>$i</h3>")
.replace(/^#### (.*$)/gim, "<h4>$i</h4>")
.replace(/^##### (.*$)/gim, "<h5>$i</h5>")
.replace(/^###### (.*$)/gim, "<h6>$i</h6>")
@SpiffGreen
SpiffGreen / app.js
Created July 25, 2021 00:41
A simple rule-based chatbot developed with javascript
const bot = require("./training");
console.log("Hello I'm Bujo. Let's Talk :)");
bot.converse();