Skip to content

Instantly share code, notes, and snippets.

View codejockie's full-sized avatar

John C. Kennedy codejockie

View GitHub Profile
@codejockie
codejockie / download.js
Created October 5, 2021 18:25
Download a file in JS
function download(fileUrl, filename) {
const a = document.createElement("a")
a.href = fileUrl
a.setAttribute("download", filename)
a.click()
}
// With Axios
import axios from "axios"
@codejockie
codejockie / crlf-to-lf.sh
Created March 23, 2021 21:15
DOS2Unix Line Endings (End Of Line)
# brew install dos2unix
find . -name '*.*' -print0 |xargs -0 dos2unix
// Redux basics
// Redux is made up of 3 key parts, namely:
// Store
// Reducer
// Action/ActionCreator
const store = {
cartReducer: {},
profileReducer: {},
};
@codejockie
codejockie / js-modulus-fix.js
Last active November 12, 2020 11:30
How to handle JS modulus operator
// The following fixes the inconsisties in the JS % (modulus) operator when used on fractional numbers
// Example 1
// Multiply both sides of operand by 10000
let remainder = (100 * 10000) % (0.33 * 10000);
// Example 2
// Divide the numbers, then apply the modulus of result by 1
remainder = (100 / 0.33) % 1;

Keybase proof

I hereby claim:

  • I am codejockie on github.
  • I am codejockie (https://keybase.io/codejockie) on keybase.
  • I have a public key ASCRr5z1RHJ2EqiU25TuXRQHvlNVEbzC4tITsZGRLmd-LQo

To claim this, I am signing this object:

@codejockie
codejockie / codility_solutions.txt
Created July 27, 2020 04:50 — forked from lalkmim/codility_solutions.txt
Codility Solutions in JavaScript
Lesson 1 - Iterations
- BinaryGap - https://codility.com/demo/results/trainingU2FQPQ-7Y4/
Lesson 2 - Arrays
- OddOccurrencesInArray - https://codility.com/demo/results/trainingFN5RVT-XQ4/
- CyclicRotation - https://codility.com/demo/results/trainingSH2W5R-RP5/
Lesson 3 - Time Complexity
- FrogJmp - https://codility.com/demo/results/training6KKWUD-BXJ/
- PermMissingElem - https://codility.com/demo/results/training58W4YJ-VHA/
import React from "react"
import { uploadAdapterPlugin } from "./utils/UploadAdapter"
const CustomEditor = () => (
<CKEditor
editor={ClassicEditor}
data="<p>Hello from CKEditor 5!</p>"
config={{}}
onInit={(editor) => {
editor.ui.view.editable.element.style.height = "200px"
@codejockie
codejockie / romanArabic.ts
Last active June 15, 2020 13:08
Roman numerals to Arabic numerals
const romanMap: { [key: string]: number } = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000,
}
const axios = require('axios') // import axios from 'axios'
const axiosInstance = axios.create({
baseURL: "https://api.themoviedb.org/3/",
})
export default axiosInstance
@codejockie
codejockie / TroubleshootMacAudio.md
Created May 4, 2020 08:10
Fix: Sound on a Mac That Randomly Stops with Any Browser

Audio in Your Mac Not Working: How to Fix It?

First things first: Before you spend a whole afternoon trying to fix non-existing sound issues, first check for minor issues, such as volume and connection to your speakers. Check if you have muted the volume. On top of this, take time to check if your external speakers or headphones are blown out. If everything looks okay, try the following solutions:

Method #1: Check the Sound Settings

To rule out sound settings as the cause of the problem, head to System Preferences, and then follow these steps:

First, select Sound > Output. Check your sound settings for discrepancies. For instance, if you are using a laptop, you may want to choose the Internal