Skip to content

Instantly share code, notes, and snippets.

View ozmos's full-sized avatar

Osamu Morozumi ozmos

View GitHub Profile
@ozmos
ozmos / to_html.sh
Last active July 3, 2023 04:12
Simple Markdown to HTML Shell Script
#! /bin/bash
# Simple script to convert markdown to html and apply some basic styles to headings and code snippets
# Written for PopOs and other Linux distros using dpkg as package manager
# Used for styling Moodle posts written in markdown
# pandoc must be installed for this script to work.
# first check if pandoc is installed
if dpkg -s pandoc | grep -q "install ok installed"
then
pandoc $1 -f markdown-auto_identifiers -t html -o $2
@ozmos
ozmos / imaginaryExponent.js
Created May 27, 2023 07:41
Find exponent of imaginary number in JavaScript
function imaginaryExponent(exponent) {
switch(exponent % 4) {
case 1:
return 'i';
break;
case 2:
return -1;
break;
case 3:
return '-i';
@ozmos
ozmos / Quadratic.py
Last active May 27, 2023 08:17
Quadratic Helper Class
class Quadratic:
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
self.x_vertex = self.find_x_of_vertex()
self.y_vertex = self.find_y_of_vertex()
self.vertex = (self.x_vertex,self.y_vertex)
self.parabola_direction = self.find_parabola_direction()
self.vertex_form = self.find_vertex_form()
@ozmos
ozmos / wp_post_install.sh
Created January 8, 2022 03:41
Post install script to run on Wordpress on servers which use mode_cache.
#!/bin/bash
# 1. ensure .htaccess has correct re-write rule for index.php
if grep -F "$RewriteRule . /index.php [L]" .htaccess; then
echo "Default WP rewrite rule detected. \nChanging default WP rewrite rule"
sed -i 's/RewriteRule\ \. \/index\.php\ \[L\]/RewriteRule\ \^\(\.\*\)\$\ \/index\.php\/\$1\ \[L\]/' .htaccess
fi
if grep -F "$RewriteRule ^(.*)$ /index.php/\$1 [L]" .htaccess; then
echo "Default WP rewrite rule has been changed. Preventing WP from writing to .htaccess"
@ozmos
ozmos / switch_php.fish
Created January 6, 2022 10:36
A simple fish script to change php versions in devilbox
function switch_php
set input_file ~/devilbox/.env
if grep 'PHP_SERVER='$argv $input_file
sed -i 's/^PHP_SERVER/#PHP_SERVER/' $input_file
sed -i 's/^#PHP_SERVER='$argv'/PHP_SERVER='$argv'/' $input_file
grep '^PHP_SERVER*' $input_file
else
echo "There is no container for PHP " $argv
end
end
@ozmos
ozmos / LaravelCsvSeeder.php
Last active June 29, 2021 09:45
Simple example of a Laravel Seeder class which seeds a table with data from a .csv file. Dependencies: parsecsv/php-parsecsv
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use ParseCsv\Csv;
use Illuminate\Support\Facades\Storage;
class PropertySeeder extends Seeder
@ozmos
ozmos / navigation.js
Created January 26, 2020 08:13
jQuery slideout navigation bar for WordPress
'use strict';
function slideOutNavBar ({$=jQuery, nav='nav', ul='ul', but='button', speed='fast'}) {
// target the childern of the parent nav container
const navBar = $(nav);
const button = navBar.find(but);
const panel = navBar.find(ul);
if (!navBar) {
console.error('Parent navbar not selected properly');
@ozmos
ozmos / factorial-calculator.js
Last active August 29, 2019 08:30
An example of trying to avoid using global variables by using a function which returns the value. This is for cases where the value is needed but not the reference. See lines 22 - 24, 49 - 51 and 80. I have posted this to get feedback on this as a coding practice. Is it weird? Unnecessary? Clever? Useful? Feel free to leave comments
// Portoflio Assignment Task 1
/*Create a special calculator that read a number from the user, checks that it is an integer and performs a series of mathematical calculations as listed:
calculates the number's factorial. A factorial is the product of an integer and all the integers below it; e.g., the factorial of 4 is equal to 24 (4 * 3 * 2 * 1).
Calculate the square and cube of the number. A number squared is a number that is multiplied by itself; e.g., 22 is equal to 4 (2 * 2). A number cubed is a number that is multiplied by itself twice e.g., 23 is equal to 8 (2 * 2 * 2).
*/
//prevent sloppy code
'use strict';
//factorial function, stored outside main function for modularity @link https://codeburst.io/learn-and-understand-recursion-in-javascript-b588218e87ea