Skip to content

Instantly share code, notes, and snippets.

View mjuhl's full-sized avatar

Matt Juhl mjuhl

View GitHub Profile
@mjuhl
mjuhl / escapeHtml.js
Last active July 28, 2021 04:50
Escape HTML entities
const htmlEntities = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": "&#39;",
'&': "&amp;"
};
const htmlCharExpr = new RegExp(`[${Object.keys(htmlEntities).join('')}]`, 'g');
@mjuhl
mjuhl / async-promisify-example.js
Last active August 25, 2020 22:21
Example REPL using async/await and util.promisify
// use 'AsyncFunction' option
const { promisify } = require('util');
const fs = require('fs');
const writeFilePromise = promisify(fs.writeFile);
const readFilePromise = promisify(fs.readFile);
const filename = '/sv/clients/norway/test.txt';
@mjuhl
mjuhl / unset-all.css
Created August 17, 2020 04:11
CSS Black Magic 1
.unset-all {
all: unset;
}
<script>document.getElementsByTagName("html")[0].className += " js";</script>
{{:templateData.show_image}}
{{:templateData.show_title}}
<!-- both are true -->
{{/}}
{{/}}
{{:~exec(data.templateData.show_image === 'true' && data.templateData.show_title === 'true')}}
<!-- both are true -->
{{/}}
@mjuhl
mjuhl / .htaccess
Created September 16, 2014 22:34
How to do that Apache rewrite thingy where everything goes to index.php except static assets
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine on
# redirect everything to index.php, except files in /a and index.php
RewriteCond %{REQUEST_URI} !(a/|index\.php)
RewriteRule (.*) index.php?%{QUERY_STRING}&request_uri=$1
@mjuhl
mjuhl / git stuff.md
Last active December 19, 2015 15:39
@mjuhl
mjuhl / selectors.md
Last active December 18, 2015 19:39
CSS 2.1/IE 8 compatible selectors for use with querySelector in IE8

What DOES work?

    • (wildcard selector)
  • .class-one.class-two (multiple class names)

  • ~

  • [attr]

  • [attr=value]

@mjuhl
mjuhl / Preferences.sublime-settings
Created June 17, 2013 21:02
sublime text settings
{
"color_scheme": "Packages/Theme - Flatland/Flatland.tmtheme",
"find_selected_text": true,
"font_face": "Meslo LG L",
"font_options":
[
"no_round",
"subpixel_antialias"
],
"font_size": 11,
@mjuhl
mjuhl / obj.js
Last active December 18, 2015 12:39
(function (exports) {
var Obj = {
support: {
// checks if Object.defineProperty exists and works as expected (not the case in IE8)
'define_prop' : (function () {
try {
return return '_' in Object.defineProperty({}, '_', {});