Skip to content

Instantly share code, notes, and snippets.

View mheob's full-sized avatar
🚀
AWESOME 🤘

Alex Böhm mheob

🚀
AWESOME 🤘
View GitHub Profile
@honza
honza / strip.js
Created August 3, 2011 14:30
Strip MS Word formatting in javascript
// Source: http://www.1stclassmedia.co.uk/developers/clean-ms-word-formatting.php
function CleanWordHTML( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;

Boolean() or !! (double bang, double negation)?

What's the best way to answer the question "true or false?" in JavaScript

JavaScript does not bother you too much with types (at first), which is both a blessing and a cure. But we all know the Boolean type. Boolean variables can either be true or false. Yes or no.

Every value in JavaScript can be translated into a boolean, true or false. Values that translate to true are truthy, values that translate to false are falsy. Simple.

This is about two ways to make that translation.

@ChristopherA
ChristopherA / brew-bundle-brewfile-tips.md
Last active November 18, 2024 14:50
Brew Bundle Brewfile Tips

Brew Bundle Brewfile Tips

Copyright & License

Unless otherwise noted (either in this file or in a file's copyright section) the contents of this gist are Copyright ©️2020 by Christopher Allen, and are shared under spdx:Creative Commons Attribution Share Alike 4.0 International (CC-BY-SA-4.) open-source license.

Sponsor

If you more tips and advice like these, you can become a monthly patron on my GitHub Sponsor Page for as little as $5 a month; and your contributions will be multipled, as GitHub is matching the first $5,000! This gist is all about Homebrew, so if you like it you can support it by donating to them or becoming one of their Github Sponsors.

@mheob
mheob / jsx.yaml
Last active February 8, 2021 15:48
Simple (plain) JSX and TSX syntax for the micro editor https://github.com/zyedidia/micro
# ~/.config/micro/syntax/jsx.yaml
filetype: jsx
detect:
filename: "\\.jsx$"
rules:
- include: "javascript"

How I Update Craft CMS 3.5.x and Craft CMS Plugins

⏳ 2 min read.

Update apnea: the temporary cessation of breath when updating Craft and Craft plugins.

This article describes the steps I follow to update Craft 3.5.x and plugins in a stress-free and reliable manner. 🧘

Photo of blue and pink sea by Harli Marten Photo by Harli Marten on Unsplash

@apurvajain
apurvajain / Commit_Message.md
Last active August 15, 2023 21:14
Commit Message Template

Commit Message Convention

type(scope): subject 

<body>
<footer>

1. Type of commit

@mheob
mheob / post-merge.sh
Created February 8, 2021 15:46
100HERZ - Craft CMS - Git Hook - post merge
#!/usr/bin/env bash
# git hook to run a command after `git pull` if a specified file was changed
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
echo "Checking yarn.lock ..."
@sindresorhus
sindresorhus / esm-package.md
Last active November 17, 2024 22:07
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@mheob
mheob / use-toggle.ts
Created October 19, 2021 07:55
Simple `useToggle` hook which returns the boolean state and the setter methods `on`, `off`, `toggle` and `reset`.
import { useState } from 'react'
export function useToggle(
initialState = false
): [boolean, { on: () => void; off: () => void; toggle: () => void; reset: () => void }] {
const [state, setState] = useState(initialState)
const handlers = {
on: () => {
setState(true)
},
@mheob
mheob / helpful-snippets.js
Last active September 1, 2022 13:50
JS - Helpful Snippets
// Detect if dark mode
const isDarkMode = () => globalThis.matchMedia?.("(prefers-color-scheme:dark)").matches ?? false;
isDarkMode();
// ---------------------------------------------------------------