Skip to content

Instantly share code, notes, and snippets.

View josfaber's full-sized avatar
🏠
Working from home

Jos josfaber

🏠
Working from home
View GitHub Profile
@josfaber
josfaber / trim.php
Created February 27, 2022 19:19
Trim including non-breaking spaces
View trim.php
echo trim($str, "\xC2\xA0");
@josfaber
josfaber / index.html
Created February 5, 2022 17:11
Inject multiple css assets with htmlWebpackPlugin
View index.html
<% for (var i in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[i] %>" rel="stylesheet">
<% } %>
@josfaber
josfaber / webpack.config.js
Created January 30, 2022 11:06
load .env in webpack config
View webpack.config.js
require('dotenv').config({ path: path.resolve( __dirname, '../../.env' ) });
module.exports = {
...
plugins: [
new HtmlWebpackPlugin( { template: './src/index.html' } ),
new webpack.DefinePlugin( {
@josfaber
josfaber / create-root-ca.sh
Created January 29, 2022 12:46
Create root authority and ssl self signed certificates
View create-root-ca.sh
#!/bin/bash
# file: selfsigned.csr.conf
# ---------------------------
# [req]
# default_bits = 2048
# prompt = no
# default_md = sha256
# distinguished_name = dn
@josfaber
josfaber / make-selfsigned-cert.sh
Last active January 29, 2022 11:00
Self signed certificate
View make-selfsigned-cert.sh
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout selfsigned.key -out selfsigned.crt -extensions san -config \
<(echo "[req]";
echo distinguished_name=req;
echo "[san]";
echo subjectAltName=DNS:localhost,DNS:example.net,DNS:www.example.net,IP:10.0.0.1
) \
-subj "/CN=example.com"
@josfaber
josfaber / server_url.php
Last active January 29, 2022 11:01
PHP get full server url
View server_url.php
$full_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
@josfaber
josfaber / cors-headers.php
Last active January 29, 2022 11:02
Allow specific domains and url's | Access-Control-Allow-Origin in PHP
View cors-headers.php
$origin = $_SERVER['HTTP_ORIGIN'];
$allowed_domains = [
'http://localhost',
'http://localhost:8080',
'http://localhost:8081',
'https://example.com',
'https://test.example.com',
'http://example.net',
];
@josfaber
josfaber / source-env.sh
Last active January 29, 2022 11:03
Source all .env variables in bash
View source-env.sh
set -o allexport;
. ./.env;
set +o allexport
# echo $VAR_NAME
@josfaber
josfaber / webpack.config.js
Created November 24, 2021 15:16
Add version to webpack-assets-manifest
View webpack.config.js
const WebpackAssetsManifest = require( 'webpack-assets-manifest' );
const manifest = new WebpackAssetsManifest( {
transform( assets, manifest ) {
assets["version" ] = new Date().getTime().toString();
},
} );
@josfaber
josfaber / datetostr.js
Created November 23, 2021 11:10
Date formatter with Intl
View datetostr.js
const dateToStr = (input) => {
if (input.length !== 6) {
return "wrong date syntax, use YYYYMM";
}
const parts = input.match(/([0-9]{4})([0-9]{2})/);
if (!parts) {
return "wrong date syntax, use YYYYMM";
}