Skip to content

Instantly share code, notes, and snippets.

View NickyMeuleman's full-sized avatar
🏎️
When not coding, I'm simracing

Nicky Meuleman NickyMeuleman

🏎️
When not coding, I'm simracing
View GitHub Profile
<template>
<!-- 42 is a string -->
<Everything answer="42"></Everything>
<!-- 42 is a number -->
<Everything :answer="42"></Everything>
</template>
<template>
<time v-bind:datetime="dateObject | toISODate">
{{ dateObject | toPrettyDate }}
</time>
</template>
<script>
export default {
data() {
return {
const LIKE_FN_NAME = "getTurtleVideo";
const anObject = {
[LIKE_FN_NAME]() {
return "https://youtu.be/CMNry4PE93Y";
},
};
anObject[LIKE_FN_NAME]();
@NickyMeuleman
NickyMeuleman / keybindings.json
Last active December 3, 2020 18:57
Use one keyboard shortcut to toggle focussing the terminal in VSCode
[
{
"key": "ctrl+shift+`",
"command": "terminal.focus",
"when": "!terminalFocus"
},
{
"key": "ctrl+shift+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
@NickyMeuleman
NickyMeuleman / MathBlock.js
Created June 13, 2021 00:32
Ideal KaTeX MDX usecase
/** @jsx jsx */
import React from "react";
import TeX from "@matejmazur/react-katex";
import { jsx } from "theme-ui";
const CodeBlock: React.FC<IProps> = ({
children,
title,
...props
}) => {
@NickyMeuleman
NickyMeuleman / index.js
Last active June 13, 2021 18:04
Check if a string contains at least one of a number of different substring options
const validOptions = ["corgi", "beagle", "dachshund"];
const string1 = "The labrador jumped";
const string2 = "The corgi jumped";
validOptions.some((option) => string1.includes(option)); // false
validOptions.some((option) => string2.includes(option)); // true
@NickyMeuleman
NickyMeuleman / lib.rs
Created June 21, 2021 14:09
Exercism.io Rust, proverb
// adding one item to an iterator by calling .chain() with an argument that implements IntoIterator
pub fn build_proverb(list: &[&str]) -> String {
match list.is_empty() {
true => String::new(),
false => list
.windows(2)
.map(|window| format!("For want of a {} the {} was lost.", window[0], window[1]))
.chain(
// first() returns an Option which implements IntoIterator and can be .chain()ed to an other iterator
list.first()
@NickyMeuleman
NickyMeuleman / index.js
Created June 22, 2021 13:58
JavaScript URL and URLSearchParams
async function getReleaseInfo({ track = "", artist = "" }) {
let url = new URL("https://api.discogs.com/database/search");
let searchParams = new URLSearchParams();
searchParams.append("key", process.env.DISCOGS_CONSUMER_KEY);
searchParams.append("secret", process.env.DISCOGS_CONSUMER_SECRET);
searchParams.append("per_page", 10);
if (artist.length) {
searchParams.append("artist", artist);
}
if (track.length) {
@NickyMeuleman
NickyMeuleman / lib.rs
Created June 25, 2021 15:06
Check if a number is an Armstrong number
pub fn is_armstrong_number(num: u32) -> bool {
let digits: Vec<_> = num
.to_string()
.chars()
.filter_map(|n| n.to_digit(10))
.collect();
let num_digits = digits.len() as u32;
num == digits.iter().map(|n| n.pow(num_digits)).sum()
}
@NickyMeuleman
NickyMeuleman / lib.rs
Created July 3, 2021 14:46
exercism.io isbn-verifier
/// Determines whether the supplied string is a valid ISBN number
pub fn is_valid_isbn(isbn: &str) -> bool {
let numbers: Vec<u32> = isbn
.chars()
.filter_map(|c| match c {
'X' if Some('X') == isbn.chars().last() => Some(10),
_ => c.to_digit(10),
})
.collect();
if numbers.len() != 10 {