Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / image-url.ts
Last active September 28, 2023 15:25
Rotate image preview to compensate for EXIF orientation (Javascript / Typescript)
// Based on: https://stackoverflow.com/a/46814952/283851
/**
* Create a Base64 Image URL, with rotation applied to compensate for EXIF orientation, if needed.
*
* Optionally resize to a smaller maximum width - to improve performance for larger image thumbnails.
*/
export async function getImageUrl(file: File, maxWidth: number|undefined) {
return readOrientation(file).then(orientation => applyRotation(file, orientation || 1, maxWidth || 999999));
}
@izzygld
izzygld / WP-Graphql-Nav-Menu-Readme.md
Last active July 18, 2023 17:04
WP-Graphql Nav Menu Documentation

WP Grahql - Nav Menu

Implements navigation menu support with two new types: Menu and MenuItem. Each have singular and plural root queries. MenuItems are connected to both Menus and to themselves—this allows for the implementation of childItems (hierarchical nav menu queries):

Query{
  menus( location: MAIN ) {
    edges {
      node {
        id
@lynt-smitka
lynt-smitka / .htaccess
Last active July 6, 2024 01:04
Block hidden files except .well-known - Apache .htaccess + Nginx
RewriteRule "(^|/)\.(?!well-known\/)" - [F]
@izzygld
izzygld / repeater-meta.php
Created June 25, 2018 14:22
Hooking up ACF repeater fields to the shema.
//acf stats repeater
array (
'key' => 'field_5a27ee3a83076',
'label' => 'Stats',
'name' => 'stats',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
@loopmode
loopmode / DefaultComponent.js
Last active July 9, 2020 08:34
Safeguarding async chains in React
// we have an async "initialize" method that performs several calls consecutively.
// after each step in the async chain, we might have been unmounted already
// and performing any further calls becomes obsolete
class DefaultComponent extends React.Component {
// ...
componentDidMount() {
this._isMounted = true;
this.initialize();
}
componentWillUnmount() {
@timurcatakli
timurcatakli / webpack.config.js
Last active May 1, 2023 18:25
An Easy to Understand Webpack 4+ Configuration File with Comments
const publicPath = 'public';
// Node os module
// The os module provides a number of operating system-related utility methods.
// It can be accessed using:
const os = require('os');
// Using a single monolithic configuration file impacts comprehension and
// removes any potential for reusability.
// As the needs of your project grow, you have to figure out the means to manage
// webpack configuration more effectively.
@atoponce
atoponce / gist:07d8d4c833873be2f68c34f9afc5a78a
Last active June 26, 2024 09:36 — forked from tqbf/gist:be58d2d39690c3b366ad
Cryptographic Best Practices

Cryptographic Best Practices

Putting cryptographic primitives together is a lot like putting a jigsaw puzzle together, where all the pieces are cut exactly the same way, but there is only one correct solution. Thankfully, there are some projects out there that are working hard to make sure developers are getting it right.

The following advice comes from years of research from leading security researchers, developers, and cryptographers. This Gist was [forked from Thomas Ptacek's Gist][1] to be more readable. Additions have been added from

@gibatronic
gibatronic / README.md
Last active May 5, 2023 12:14
Node crypto.pbkdf2 example to securely store and check passwords.

password.js

Tiny Node.js module to securely hash and compare passwords using pbkdf2 with per password random salt.

Usage

To hash a password:

var password = require('./password');
@renehamburger
renehamburger / slimdown.js
Last active September 4, 2023 07:55
slimdown.js
'use strict';
/**
* Javascript version of https://gist.github.com/jbroadway/2836900
*
* Slimdown - A very basic regex-based Markdown parser. Supports the
* following elements (and can be extended via Slimdown::add_rule()):
*
* - Headers
* - Links
@skeggse
skeggse / crypto-pbkdf2-example.js
Last active May 21, 2024 09:21
Example of using crypto.pbkdf2 to hash and verify passwords asynchronously, while storing the hash and salt in a single combined buffer along with the original hash settings
var crypto = require('crypto');
// larger numbers mean better security, less
var config = {
// size of the generated hash
hashBytes: 32,
// larger salt means hashed passwords are more resistant to rainbow table, but
// you get diminishing returns pretty fast
saltBytes: 16,
// more iterations means an attacker has to take longer to brute force an