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
@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 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 / lib.rs
Created June 20, 2021 18:43
Exercism.io Sublist in Rust
use std::cmp::Ordering;
#[derive(Debug, PartialEq)]
pub enum Comparison {
Equal,
Sublist,
Superlist,
Unequal,
}
@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 / 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 / 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"
const LIKE_FN_NAME = "getTurtleVideo";
const anObject = {
[LIKE_FN_NAME]() {
return "https://youtu.be/CMNry4PE93Y";
},
};
anObject[LIKE_FN_NAME]();
<template>
<time v-bind:datetime="dateObject | toISODate">
{{ dateObject | toPrettyDate }}
</time>
</template>
<script>
export default {
data() {
return {
<template>
<!-- 42 is a string -->
<Everything answer="42"></Everything>
<!-- 42 is a number -->
<Everything :answer="42"></Everything>
</template>
<template>
<!-- pass in the "like" variable that corresponds to the input-value by using v-model -->
<form v-on:submit.prevent="onSubmit(like)">
<label
>What do you like:
<input v-model="like" />
</label>
<input type="submit" />
</form>
</template>