Skip to content

Instantly share code, notes, and snippets.

@codejockie
codejockie / numberToOrdinal.js
Created February 23, 2019 23:56 — forked from jondwx/numberToOrdinal.js
Number to Ordinal Format
function numberToOrdinal(i) {
var j = i % 10,
k = i % 100;
if (j == 1 && k != 11) {
return i + "st";
}
if (j == 2 && k != 12) {
return i + "nd";
}
if (j == 3 && k != 13) {
@codejockie
codejockie / countChange.js
Created February 23, 2019 23:56 — forked from zestime/countChange.js
JavaScript ver. of Counting coins
function countChange(money, coins) {
if (money == 0) return 1;
if (money < 0 || coins.length == 0) return 0;
return countChange(money - coins[0], coins) + countChange(money, coins.slice(1));
}
@codejockie
codejockie / Basic_React_Gotchas.md
Created February 26, 2019 21:31 — forked from joeytwiddle/Basic_React_Gotchas.md
Some things we learned in the first few months of using React

Basic React Gotchas

Note: This document was written for someone who already knows React fairly well, because it was initially a list of suggested talking points for a presentation they were planning. Ideally this document should be expanded to include clear examples for the final target audience, which is React beginners.

setState does not apply the update immediately

// Constructor
this.state = { foo: 0 };
@codejockie
codejockie / a1_tester.py
Created April 2, 2019 21:19
Calendar tester
import urllib.request
url = "http://comp2152.gblearn.com/2019/winter/a1_tester.php"
tester_file = urllib.request.urlopen(url)
exec(tester_file.read())
@codejockie
codejockie / deleteGitBranches.sh
Created October 22, 2019 06:06
A tiny utility function to delete old (unused) git branches
function deleteOldBranches() {
for branchName in $(git branch)
do
# We do not want to delete the master branch
if [ $branchName != 'master' ] && [ $branchName != '*' ]
then
echo 🛠 Deleting $branchName
git branch -D $branchName
fi
done
const memoize = require('memoize')
const date = memoize(function(seed, cb) {
setTimeout(function() {
cb(null, Date.now(), seed)
}, 100)
})
date({ name: "John", username: "codejockie" }, function(err, d1, seed1) { // given a set of arguments
console.log(d1, seed1) // 1304606051552
@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

const axios = require('axios') // import axios from 'axios'
const axiosInstance = axios.create({
baseURL: "https://api.themoviedb.org/3/",
})
export default axiosInstance
@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,
}
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"