Skip to content

Instantly share code, notes, and snippets.

View xdesro's full-sized avatar
👨‍💻
Doing some coding for the 'Net.

Henry Desroches xdesro

👨‍💻
Doing some coding for the 'Net.
View GitHub Profile
@xdesro
xdesro / .eleventy.js
Created October 27, 2022 19:44
Hint VS Code for eleventyConfig autocompletion.
/**
* @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
*/
module.exports = (eleventyConfig) => {
return {};
};
@xdesro
xdesro / killport.sh
Last active March 2, 2023 19:01
Kill processes at a given port.
function killport {
echo '🚨 Killing all processes at port' $1
lsof -ti tcp:$1 | xargs kill
}
@xdesro
xdesro / index.js
Created June 1, 2021 18:24
Check if the current device is using a mouse with both CSS and JavaScript.
if (matchMedia('(pointer:fine)').matches) {
// This browser has a mouse or other fine-control device as its primary input.
}
@xdesro
xdesro / optional-chaining.js
Created May 20, 2021 16:25
Using optional chaining operators instead of logical and operators.
// Before
const postsByAuthor = (posts) => {
return this.posts.filter(
(post) => post.author && post.author.fields.name == this.teamMember.name
);
},
// After
const postsByAuthor = (posts) => {
return this.posts.filter(
@xdesro
xdesro / MarginTop.js
Created August 17, 2020 18:31
Godforsaken margin-top React component.
const MarginTop = (props) => (
<div>
{Array.from(Array(props.spacing)).map((br) => (
<br />
))}
{props.children}
</div>
);
ReactDOM.render(
@xdesro
xdesro / twitter-engagement-alignment.md
Created August 6, 2020 17:54
An alignment chart for analyzing the different styles of engagement on Twitter dot com.

Twitter Engagement Alignment Chart

😇 Good

Lawful Good

  • Like
  • Clean Retweet

Neutral Good

  • Like
@xdesro
xdesro / lexical-this-in-sass.scss
Created May 28, 2020 16:33
Caching specificity context using Sass' &.
.nav-item {
&__link {
color: red;
}
$this: &;
&:first-of-type {
&__link {
// this won't work 😞
color: blue;
}
[...document.querySelectorAll('a')].forEach(a => a.remove());
// ⚓️ anchors away
@xdesro
xdesro / _mixins.scss
Created February 7, 2020 16:26
A mixin for tokenizing `@media` queries.
$bkpoints: (
xs: 27rem,
sm: 37.5rem,
md: 56.25rem,
lg: 62.5rem,
xl: 120rem
);
// ^ This was for a particular client, you can use whichever
breakpoints are best for your use case.
@xdesro
xdesro / component-sans-moment.js
Last active December 11, 2019 17:58
Converting moment.js to vanilla JavaScript with `.toLocaleDateString()`
// This is meant to be a Vue component, cause my site https://henry.codes is built with Nuxt.js. I put the .js extension on there for that fresh Gist syntax highlighting.
export default {
computed: {
postDate() {
return new Date(this.post.fields.publishDate).toLocaleDateString("en-US", { month: "short", year: "2-digit" });
}
}
};