Skip to content

Instantly share code, notes, and snippets.

View niksmac's full-sized avatar
🇮🇳
🧜 Merperson

Nikhil M niksmac

🇮🇳
🧜 Merperson
View GitHub Profile
@niksmac
niksmac / detect-mobile-browser.js
Last active January 17, 2024 08:48
Nodejs Express code to redirect mobile user agets
var express = require('express'),
app = express();
app.listen(80);
app.get('/', function(req, res){
var ua = req.header('user-agent');
// Check the user-agent string to identyfy the device.
if(/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile|ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(ua)) {
res.sendfile(__dirname + '/mobile.html');
} else {
res.sendfile(__dirname + '/index.html');
@niksmac
niksmac / SiteMaintenanceTemplate.html
Last active November 13, 2023 14:52 — forked from pitch-gist/gist:2999707
Simple Maintenance Template Page - HTML CSS
<!DOCTYPE html>
<html lang="en">
<head>
<title>Site Maintenance</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
@niksmac
niksmac / seo-guide.md
Last active September 19, 2023 07:08
Bare minimum SEO Guidelines for launching a website

Basic technical SEO guidelines for a webpage:

  1. Unique H1 Tag: Ensure there's only one H1 tag per page, which typically represents the main heading or topic of the page.
  2. Hierarchical Use of Heading Tags: Use H tags (H1 to H6) in a hierarchical manner. H1 for main topics, H2 for subtopics, H3 for further subtopics, and so on.
  3. Distributed Use of Headings: Use H2, H3, H4, etc., tags appropriately to break down content into readable and organized sections.
  4. Meta Description and Titles:
    • Title Tag: Ensure each page has a unique and descriptive title that's within 50-60 characters.
    • Meta Description: Write a concise summary of the page's content within 150-160 characters. It should be unique for each page.
  5. Social Media Integration: Incorporate social sharing buttons or links to improve visibility and shareability.
  6. URL Structure:
@niksmac
niksmac / tiffdump.py
Created July 8, 2023 06:24 — forked from pebbie/tiffdump.py
hopefully generic TIFF file format extraction tool (GeoTIFF, NEF, ARW)
"""
\description TIFF file format dump
\author paryan
"""
from __future__ import print_function
import argparse
from struct import *
import os
import os.path as path
@niksmac
niksmac / zmv-examples.md
Created March 7, 2017 05:58
ZMV-Examples (require autoload zmv)

rename a section of a filename, i. e. example.1.{txt,conf,db} or 12345.1.{wav,ogg,mp3} and

change the 1 to a 2 in the filename while preserving the rest of it.

$ zmv -n '(.)(<->)(.[^.]#)' '$1$(($2+1))$3' # would rename x.0001.y to x.2.y. $ zmv -n '(.0#)(<->)(.[^.]#)' '$1$(($2+1))$3'

Rename files to lower case

$ zmv '*' '${(L)f}'

serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)

$ autoload zmv

@niksmac
niksmac / fix_npm.sh
Last active January 9, 2023 22:36
Fixing npm permissions
#!/usr/bin/env bash
set -e
echo ''
info () {
printf "\r [ \033[00;34m..\033[0m ] $1\n"
}
@niksmac
niksmac / TouchIDSudo.md
Last active August 27, 2022 03:31
Use TouchID to Authenticate sudo on macOS

Use TouchID to Authenticate sudo on macOS

How to use TouchID to Authenticate sudo on macOS

Use your favorite text editor and open the file

/etc/pam.d/sudo

and add the following line

@niksmac
niksmac / iptables.md
Last active April 25, 2022 05:07
Persist iptables even after reboot Ubuntu

Set the rules

sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

On Ubuntu: sudo apt-get install iptables-persistent

Keybase proof

I hereby claim:

  • I am niksmac on github.
  • I am niksmac (https://keybase.io/niksmac) on keybase.
  • I have a public key ASDIN9pUfXhvZO_R2C2Co5XPM8HjOBrfznFX0WD80TDEVwo

To claim this, I am signing this object:

@niksmac
niksmac / sw-cache-clear.js
Created June 3, 2021 01:36
Clear service worker cache from browser
caches.keys().then(function (cachesNames) {
console.log("Delete " + document.defaultView.location.origin + " caches");
return Promise.all(cachesNames.map(function (cacheName) {
return caches.delete(cacheName).then(function () {
console.log("Cache with name " + cacheName + " is deleted");
});
}))
}).then(function () {
console.log("All " + document.defaultView.location.origin + " caches are deleted");
});