Skip to content

Instantly share code, notes, and snippets.

View schalkneethling's full-sized avatar
🇺🇦
The world wants peace, not war ✌️

Schalk Neethling schalkneethling

🇺🇦
The world wants peace, not war ✌️
View GitHub Profile
@schalkneethling
schalkneethling / bash
Last active February 4, 2022 11:09
Random snippets
# count all `index.html` and `index.md` files in the current directory recursively.
find . -iname 'index.html' -o -iname 'index.md' | wc -l
// https://nationalkitty.com/cat-ancestry-where-do-cats-come-from/
const pantherinae = {
roar: function () {
console.log(`${this.name} is roaring!`);
},
domesticated: false,
size: "large",
sound: "roar",
};
This file has been truncated, but you can view the full file.
{
"/files/en-us/games/anatomy/index.md": {
"title": "Anatomy of a video game",
"slug": "Games/Anatomy",
"tags": ["Games", "JavaScript", "Main Loop", "requestAnimationFrame"]
},
"/files/en-us/games/examples/index.md": {
"title": "Examples",
"slug": "Games/Examples",
"tags": ["Demos", "Example", "Games", "Web"]
@schalkneethling
schalkneethling / copy-file.js
Last active December 29, 2021 11:50
A bunch of useful and perhaps not commonly known Nodejs tips and notes
'use strict'
const { pipeline } = require('stream')
const { join } = require('path')
const { createReadStream, createWriteStream } = require('fs')
// this is highly performant for large files
// as the read and write happens in small chunks
pipeline(
createReadStream(__filename),
createWriteStream(join(__dirname, 'out.txt')),
@schalkneethling
schalkneethling / binary-search.js
Created July 23, 2021 20:30
A simple binary search implementation
function binarySearch(id, array) {
const mid = Math.floor(array.length / 2);
if (array[mid].id === id) {
return array[mid];
} else if (array[mid].id < id) {
return binarySearch(id, array.slice(mid));
} else {
return binarySearch(id, array.slice(0, mid));
}
function calculateMealPrice(mealCost, tipPercent, taxPercent) {
const tipAmount = (tipPercent / 100) * mealCost;
const taxAmount = (taxPercent / 100) * mealCost;
return Number.parseInt(Math.round(mealCost + tipAmount + taxAmount), 10);
}
calculateMealPrice(12.00, 20, 8);
@schalkneethling
schalkneethling / index.js
Last active August 15, 2020 19:02
What is the output in index.js?
const fs = require("fs");
const { update } = require("./util");
const entries = ["one", "two"];
function doUpdate() {
let fileContents = fs.readFileSync("./sample.json", "utf8");
fileContents = update(fileContents, entries);
console.log(entries); // what will this output?
}
{
"Font face": {
"scope": "css, scss",
"prefix": "fontface",
"body": [
"@font-face {",
" font-family: \"$1\";",
" font-display: swap;",
" src: url(\"$2\") format(\"woff2\"),",
" url(\"$3\") format(\"woff\");",
@schalkneethling
schalkneethling / vscode-javascript.json
Last active May 29, 2020 11:11
VSCode JavaScript User Snippets
{
"describe block": {
"prefix": "describe",
"body": [
"describe('$1', () => {",
"",
" it('$2', () => {",
" $3",
" expect(data).toBe('{}');",
" });",
@schalkneethling
schalkneethling / config.yml
Last active November 21, 2019 14:05
Basic config.yml for NetlifyCMS
backend:
name: git-gateway
branch: netlify-published-content
media_folder: "static/images/uploads" # Media files will be stored in the repo under static/images/uploads
public_folder: "/images/uploads" # The src attribute for uploaded media will begin with /images/uploads
collections:
- name: "homepage" # Used in routes, e.g., /admin/collections/blog
label: "Homepage" # Used in the UI