Skip to content

Instantly share code, notes, and snippets.

View kaustubhn's full-sized avatar
🎯
Focusing

Kaustubh kaustubhn

🎯
Focusing
View GitHub Profile
@kaustubhn
kaustubhn / wordpress_relative_urls.php
Created October 28, 2023 10:54
Configure Wordpress for Relative URLS
// Paste this in functions.php above add_action('wp_footer', 'add_scripts');
//make other links relative
add_filter ('site_url', 'wp_make_theme_links_protocols_relative');
add_filter ('get_option_siteurl', 'wp_make_theme_links_protocols_relative');
add_filter ('stylesheet_directory_uri', 'wp_make_theme_links_protocols_relative');
add_filter ('template_directory_uri', 'wp_make_theme_links_protocols_relative');
add_filter ('wp_get_attachment_url', 'wp_make_theme_links_protocols_relative');
add_filter ('wp_get_attachment_thumb_url', 'wp_make_theme_links_protocols_relative');
add_filter ('the_permalink', 'wp_make_theme_links_protocols_relative');
@kaustubhn
kaustubhn / docker_clean.sh
Created March 31, 2023 05:39
Docker commands to clean dangling images, containers & volumes
# Check system usage for docker universe
docker system df
# Remove unsed containers
$ docker ps --filter “status=exited” -q | xargs -r docker rm --force
# or through a simpler built-in command
$ docker container prune --force
# Remove all containers
@kaustubhn
kaustubhn / install_docker.sh
Created March 2, 2023 12:52
Install Docker on Ubuntu 22.04
# Install Docker
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce -y
sudo systemctl status docker
sudo usermod -aG docker ${USER}
@kaustubhn
kaustubhn / install_wifi.sh
Created June 19, 2019 10:40
Install WIFI Driver for ubuntu 18 on HP Laptop
#!/bin/bash
apt update
apt install git build-essential dkms
git clone -b extended https://github.com/lwfinger/rtlwifi_new.git
dkms add ./rtlwifi_new
dkms install rtlwifi-new/0.6
modprobe -r rtl8723de
modprobe rtl8723de
echo "options rtl8723de ant_sel=3" | sudo tee /etc/modprobe.d/rtl8723de.conf
@kaustubhn
kaustubhn / parallel_function.py
Created June 14, 2018 10:43
Execute a python function in parallel - Template
from toolz import partition
from joblib import Parallel, delayed
def parallelize(func, iterator, n_jobs, extra):
extra = tuple(extra)
return Parallel(n_jobs=n_jobs)(delayed(func)(*(item + extra)) for item in iterator)
def iter_documents(file):
with open(file) as file_:
for line in file_:
@kaustubhn
kaustubhn / install_phantomjs.sh
Created October 24, 2017 05:45
Install PhantomJS on ubuntu
# Steps to install phantomjs on ubuntu16.04
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/
@kaustubhn
kaustubhn / crp.py
Created September 20, 2017 14:54
Chinese Restaurant Process
# Implementation of a chinese restaurant process function for a given list of word vectors.
def crp(vecs):
clusterVec = [[0.0] * 25] # tracks sum of vectors in a cluster
clusterIdx = [[]] # array of index arrays. e.g. [[1, 3, 5], [2, 4, 6]]
ncluster = 0
# probablity to create a new table if new customer
# is not strongly "similar" to any existing table
pnew = 1.0/ (1 + ncluster)
N = len(vecs)
rands = [random.random() for x in range(N)] # N rand variables sampled from U(0, 1)
@kaustubhn
kaustubhn / nginx.conf
Created December 11, 2015 07:02 — forked from phpdude/nginx.conf
Nginx image filter + caching of results.
location /resize {
alias /tmp/nginx/resize;
set $width 150;
set $height 100;
set $dimens "";
if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;