Skip to content

Instantly share code, notes, and snippets.

View mcnaveen's full-sized avatar
🦄

MC Naveen mcnaveen

🦄
View GitHub Profile
@mcnaveen
mcnaveen / script.sh
Last active May 21, 2023 11:36
Periodically check home IP address and update on server to allow port 53
#!/bin/bash
# Setup Reference: https://blog.sbstp.ca/vps-pihole/
# Run this script as CRON Job in your laptop or any device.
# Author - mcnaveen<me@mcnaveen.com>
ip=$(curl -s https://api.ipify.org | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
ip_file="ip_address.txt"
vps_ip="YOUR_VPS_IP_ADDRESS"
if [[ -f $ip_file ]]; then
@mcnaveen
mcnaveen / index.js
Created May 11, 2023 05:19
Creating Videos Programatically using Nodejs and FFMpeg
const { spawn } = require("child_process");
const outputFile = "output.mp4";
const duration = 4; // Duration in seconds
const inputImage = "photo.jpg";
const outputDimensions = "1080:1920"; // Output video dimensions
const ffmpegCommand = `ffmpeg -loop 1 -t ${duration} -i ${inputImage} -i ${inputImage} -filter_complex "[0:v]scale=${outputDimensions},setsar=1:1[bg];[bg]boxblur=5:2[bg];[bg][1:v]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -c:v libx264 -preset superfast -pix_fmt yuv420p -t ${duration} ${outputFile}`;
const ffmpegProcess = spawn(ffmpegCommand, { shell: true });
@mcnaveen
mcnaveen / actions.yml
Created April 30, 2023 03:22
On New Tag create, copy the source to the server, build and restart pm2 service
name: Deploy Next.js Site via SSH
on:
push:
tags:
- "*"
jobs:
deploy:
runs-on: ubuntu-latest
@mcnaveen
mcnaveen / random.sh
Created January 7, 2023 18:42
feh & pywal random wallpaper with Dynamic color scheme
#!/bin/bash
while true; do
# Set a random wallpaper from the specified folder
feh --randomize --bg-fill ~/Pictures/Wallpapers/*
# Get the current wallpaper from .fehbg
wallpaper="$(cat "${HOME}/.fehbg" | awk -F "'" '{print $2}')"
# Apply pywal color scheme to desktop
@mcnaveen
mcnaveen / Dockerfile
Created June 28, 2022 07:22
Dockerfile for Simple Express API
FROM node:16
# Create app directory
WORKDIR /usr/src/app
# Copy package.json
COPY package*.json ./
# Install dependencies
RUN yarn install
@mcnaveen
mcnaveen / main.yml
Last active June 22, 2022 06:32
Scheduled Netlify Build with GitHub Actions
# .github/workflows/main.yml
name: Trigger Netlify Build
on:
schedule:
# Run at 0000 daily
- cron: '0 0 * * *'
jobs:
build:
name: Request Netlify Webhook
@mcnaveen
mcnaveen / index.php
Created June 6, 2022 17:46
Hide Payment gateway based on selected country
<?php
add_filter( 'woocommerce_available_payment_gateways', 'mcnaveen_payment_gateway_based_on_country' );
function mcnaveen_payment_gateway_based_on_country( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( WC()->customer->get_billing_country() !== 'IN' ) {
unset( $available_gateways['wc-razorpay'] );
} else {
if ( WC()->customer->get_billing_country() === 'IN' ) {
unset( $available_gateways['stripe'] );
@mcnaveen
mcnaveen / script popup.js
Last active May 28, 2022 16:59
Autofill popup fields - personalizery
<script type="text/javascript">
function personalizeryInit() {
let params = new URL(document.location).searchParams;
let name = params.get("firstname");
let email = params.get("email");
document.querySelector("#form-field-field_8fd15b6").value = name;
document.querySelector("#form-field-email").value = email;
}
personalizeryInit();
</script>
@mcnaveen
mcnaveen / script.js
Created May 28, 2022 16:24
Autofill Form with Personalizery
<script type="text/javascript">
function personalizeryInit() {
let params = new URL(document.location).searchParams;
let name = params.get("firstname");
let email = params.get("email");
document.querySelector("#form-field-name").value = name;
document.querySelector("#form-field-email").value = email;
}
personalizeryInit();
@mcnaveen
mcnaveen / file.js
Created January 29, 2022 15:54
Persist state after a page refresh in React
const storedValueAsNumber = Number(localStorage.getItem("limit"));
const [userLimit, setUserLimit] = useState(
Number.isInteger(storedValueAsNumber) ? storedValueAsNumber : 0
);
useEffect(() => {
localStorage.setItem("limit", String(userLimit));
}, [userLimit]);