Skip to content

Instantly share code, notes, and snippets.

View jitheshkt's full-sized avatar

Jithesh KT jitheshkt

View GitHub Profile
@jitheshkt
jitheshkt / index.js
Last active November 19, 2021 18:01
Caching REST API response to browser HTTP cache
let controller = new AbortController();
const trans = await fetch('/api/something.json',{cache: "only-if-cached", mode: "same-origin", signal: controller.signal}).then(res => {
const date = res.headers.get("date"), dt = date ? new Date(date).getTime() : 0;
console.log('hit cache');
if (dt < (Date.now() - 100000)) {
console.log('refresh time');
// if older than 1 minute
controller.abort()
controller = new AbortController();
return fetch('/api/something.json', {cache: "reload", mode: "same-origin", signal: controller.signal});
@jitheshkt
jitheshkt / functions.php
Last active July 22, 2021 04:16
Simple Portfolio Gallery Shortcode for WordPress
//The CSS & JS part is completely based on this W3S article: https://www.w3schools.com/howto/howto_js_portfolio_filter.asp
function shortcode_posts_showcase() {
$args = array(
'posts_per_page' => -1,
'post_type' => 'post'
);
$query = new WP_Query($args);
$posts_result = $query->posts;
@jitheshkt
jitheshkt / README.md
Last active December 5, 2020 10:32
Setup PHP 7.4 FPM with Apache on fresh Ubuntu Instance

Setup PHP 7.4 FPM with Apache on fresh Ubuntu Instance

sudo apt update
sudo apt upgrade

Install apache

sudo apt install apache2 libapache2-mod-fcgid
@jitheshkt
jitheshkt / instructions.txt
Last active December 6, 2023 16:16
Installing SSL on WSL2 Apache
# The idea is, we don't install certificates on WSL, instead we install them on
# Windows and point the path at WSL Apache/Ngnix configuration file.
# We use mkcert to generate certificates.
# https://github.com/FiloSottile/mkcert
# Install mkcert on Linux. Even though we don't generate certificate here,
# I am installing this only to check the constant is properly set or not.
# If you're Linux Ninja like my friend Bombay, you could do it without
# This package for sure.
@jitheshkt
jitheshkt / install-virtualenv-windows.sh
Created January 13, 2020 15:55
Install Python virtualenv on Windows 10
# Run windows Power Shell as administrator
pip install virtualenv
pip install virtualenvwrapper-win
# navigate the power shell to your project directory
virtualenv dev
cd dev
Set-ExecutionPolicy AllSigned
Set-ExecutionPolicy RemoteSigned
cd ..
.\dev\Scripts\activate
@jitheshkt
jitheshkt / docker-compose.yml
Created December 29, 2019 08:43
Transmission client with Docker-compose & Traefik 2.0
version: "2"
services:
transmission:
image: linuxserver/transmission
container_name: transmission
environment:
- PUID=1001
- PGID=1001
- USER=username #optional
- PASS=password #optional
@jitheshkt
jitheshkt / traefik.yml
Created December 29, 2019 07:54
Traefik 2.0 Docker Container Configuration
api:
dashboard: true
entryPoints:
http:
address: ":80"
https:
address: ":443"
providers:
@jitheshkt
jitheshkt / docker-compose.yml
Last active December 29, 2019 08:37
Apache and Traefik 2.0 with Docker Compose
version: "3"
networks:
proxy:
external: true
services:
public_apache:
image: httpd
labels:
@jitheshkt
jitheshkt / docker-compose.yml
Created December 29, 2019 07:44
Traefik 2.0 with Docker Compose
version: '3'
services:
traefik:
image: traefik:v2.0
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks: