Skip to content

Instantly share code, notes, and snippets.

@akarsh1995
akarsh1995 / caps_lock_mod.fish
Last active October 16, 2023 18:16
Fish script to mod CAPSLOCK to ESCAPE and CAPSLOCK + h j k l to arrow keys on Arch Linux wayland + sway.
#!/usr/bin/env fish
# locations
set intercept_dir_loc /etc/interception
set mapping_loc $intercept_dir_loc/dual-function-keys/caps2escape.yaml
set daemon_config_loc $intercept_dir_loc/udevmon.d/my-keyboards.yaml
set file_name_symbols alt_gr_mapped_to_caps_lock
set xkb_symbols_loc $HOME/.xkb/symbols/$file_name_symbols
set sway_config_loc $HOME/.config/sway/config
@vvolhejn
vvolhejn / torch_conv_layer_to_fully_connected.py
Last active December 8, 2024 16:10
Convert PyTorch convolutional layer to fully connected layer
"""
The function `torch_conv_layer_to_affine` takes a `torch.nn.Conv2d` layer `conv`
and produces an equivalent `torch.nn.Linear` layer `fc`.
Specifically, this means that the following holds for `x` of a valid shape:
torch.flatten(conv(x)) == fc(torch.flatten(x))
Or equivalently:
conv(x) == fc(torch.flatten(x)).reshape(conv(x).shape)
@alexander-malafeev
alexander-malafeev / ideapad_battery_conservation
Created February 19, 2020 20:51
Script to control battery conservation mode on Lenovo Yoga S940 in Linux. Should work on all ideapad laptops.
#!/bin/bash
# script is based on answers at https://askubuntu.com/questions/1038471/problem-with-lenovo-battery-threshold
# and relies on the module ideapad-laptop
# arguments are status, on and off are self-explanatory
if [ "$1" == "status" ]
then
cat /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode
elif [ "$1" == "on" ]
then
sudo echo 1 | sudo tee /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode
@emzo
emzo / gist:cda9cfc61031395c570373d165773241
Last active October 30, 2022 18:18
Make Offline Mirror of a Site using `wget`
https://www.guyrutenberg.com/2014/05/02/make-offline-mirror-of-a-site-using-wget/
Sometimes you want to create an offline copy of a site that you can take and view even without internet access. Using wget you can make such copy easily:
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent http://example.org
Explanation of the various flags:
--mirror – Makes (among other things) the download recursive.
--convert-links – convert all the links (also to stuff like CSS stylesheets) to relative, so it will be suitable for offline viewing.
@Spindel
Spindel / model.py
Last active March 22, 2023 01:19
Interview question model.
import uuid
import random
from afase.models.meta import Base
from sqlalchemy import (
Column,
Text,
Date,
ForeignKey,
@patrickgill
patrickgill / m3u8download.sh
Last active June 1, 2025 11:06
download m3u8 ts segments, then decode, join, and remux them! (HTTP Live Streaming TS files)
# download
aria2c -x 5 -i file.m3u8
# decode (example)
openssl aes-128-cbc -d -K 15D0F46608409DA364E3F5D92BDE9F61 -iv 00000000000000000000000000000000 -nosalt -in G00000000.ts -out G00000000.d.ts
# join all ts files
cat *.ts > out.ts
# convert ts output file
@rain1024
rain1024 / tut.md
Last active June 13, 2025 18:20
Install pdflatex ubuntu

PdfLatex is a tool that converts Latex sources into PDF. This is specifically very important for researchers, as they use it to publish their findings. It could be installed very easily using Linux terminal, though this seems an annoying task on Windows. Installation commands are given below.

  • Install the TexLive base
sudo apt-get install texlive-latex-base
  • Also install the recommended and extra fonts to avoid running into the error [1], when trying to use pdflatex on latex files with more fonts.
@jiffyclub
jiffyclub / markdown_doc
Last active August 1, 2023 11:16
This script turns Markdown into HTML using the Python markdown library and wraps the result in a complete HTML document with default Bootstrap styling so that it's immediately printable. Requires the python libraries jinja2, markdown, and mdx_smartypants.
#!/usr/bin/env python
import argparse
import sys
import jinja2
import markdown
TEMPLATE = """<!DOCTYPE html>
<html>