Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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<[email protected]>
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
upstream freshrss {
server 127.0.0.1:3500;
keepalive 64;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
@mcnaveen
mcnaveen / blurhash.sh
Created July 11, 2023 10:41
Bash Script to Generate blurhash for all the images in the folder.
#!/bin/bash
# Prerequisite: Node, NPX
folder_path="Wallpapers"
for file_path in "$folder_path"/*.{jpg,png,jpeg}; do
if [[ -f "$file_path" ]]; then
echo "Generating Blurhash for $file_path"
npx blurhash-cli "$file_path" --local
echo "============================================"
@mcnaveen
mcnaveen / findProperty.js
Created August 6, 2023 15:55
Notion Helper Function to find property value by name
const findPropertyValue = (results, propertyName) => {
const property = results.find((item: { properties: { Key: { title: { text: { content }; }[]; }; }; }) => item.properties.Key.title[0].text.content === propertyName);
return property ? property.properties.Value.rich_text[0].text.content : null;
};
// then just do
const somevar = findPropertyValue(response.results, "My Phone Number")
// Table should follow this structure
https://imgur.com/a/P2kssZV
Image will be uploaded
@mcnaveen
mcnaveen / file.md
Created August 18, 2023 05:44
Use MacBook in Camshell Mode (Lid Closed) without power adapter connected

Open the terminal and run the below command

pmset -g | grep hibernatemode

Note down the number in safe place, you'll need this later if you want to disable it

Now, run the below commands one by one.

#!/bin/bash
# URL of the Android Studio download page
URL="https://developer.android.com/studio"
# CSS selector to target the element
SELECTOR="#agree-button__studio_linux_bundle_download"
# Use curl to fetch the web page content and pipe it to grep
# -s: Silent mode (suppresses progress meter)