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 / start
Last active April 20, 2024 08:15
Start Python virtual environment and install packages
#!/bin/sh
# USAGE:
# source start
venv_folder=".venv"
packages=(
"pygame==2.5.2"
"numpy==1.26.0"
@josfaber
josfaber / trim.php
Created February 27, 2022 19:19
Trim including non-breaking spaces
echo trim($str, "\xC2\xA0");
@josfaber
josfaber / index.html
Created February 5, 2022 17:11
Inject multiple css assets with htmlWebpackPlugin
<% 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
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
#!/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
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
$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
$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
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
const WebpackAssetsManifest = require( 'webpack-assets-manifest' );
const manifest = new WebpackAssetsManifest( {
transform( assets, manifest ) {
assets["version" ] = new Date().getTime().toString();
},
} );