Skip to content

Instantly share code, notes, and snippets.

@wilspi
wilspi / reverse-rename-files.sh
Created August 23, 2021 12:25
Rename files by splitting by "-" and reversing the order in a directory
dir="$1"
for f in "$dir"/*; do
#filename="${cat '$f'}"
filename=${f:13:10} # string of length 10 from index 13
arrIN=(${filename//-/ }) # split by "-"
reversefilename="${arrIN[2]}-${arrIN[1]}-${arrIN[0]}"
reversef="journal/2021/${reversefilename}.md"
mv $f $reversef
#echo $reversefilename
done
@wilspi
wilspi / middleware_log_req_res.py
Last active July 29, 2020 16:16
Middleware in django to log requests and responses
"""
Middleware to log `*/api/*` requests and responses.
"""
import socket
import time
import json
import logging
request_logger = logging.getLogger(__name__)
@wilspi
wilspi / pycharm_setup_realm.md
Last active March 16, 2020 15:19
Pycharm Setup for Realm

PyCharm Setup

Tested using PyCharm PyCharm 2018.3.7 (Professional Edition).
Note: Commands that are being run, need to be run in nix shell

  • Python:

    1. Run which python and update this in Preferences -> Project: project_name -> Project Interpreter -> Gear Icon -> Add -> Virtual Environment -> Existing Environment -> ... -> Add.
  • Rust:

@wilspi
wilspi / setup_nix.md
Last active August 12, 2020 10:20
Setup nix

Setup: Mac

If using Catalina

sudo mkdir -p /System/Volumes/Data/nix
sudo chown -R `whoami` /System/Volumes/Data/nix
echo "nix\t/System/Volumes/Data/nix" | sudo tee /etc/synthetic.conf
@wilspi
wilspi / wkhtmltopdf.sh
Last active December 11, 2019 20:08 — forked from Rajeshr34/wkhtmltopdf.sh
Wkhtmltopdf With Patched QT Setup: Ubuntu 16+ and Mac
# sudo apt-get install libfontenc1 xfonts-75dpi xfonts-base xfonts-encodings xfonts-utils openssl build-essential libssl-dev libxrender-dev git-core libx11-dev libxext-dev libfontconfig1-dev libfreetype6-dev fontconfig -y
# https://github.com/wkhtmltopdf/wkhtmltopdf/releases
if [ "$(uname -s)" = "Darwin" ]; then
# For Mac
cd ~
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.macos-cocoa.pkg
sudo installer -verbose -pkg wkhtmltox-0.12.5-1.macos-cocoa.pkg -target /
@wilspi
wilspi / setup_nix.sh
Last active July 15, 2020 15:10
Setup (nix)[https://nixos.org/nix/] on Arch Linux
#!/bin/sh
# Install nix via yay (AUR helper)
yay -S archlinux-nix
# Read: https://nixos.org/nix/manual/#ssec-multi-user
# Add nix builder groups
sudo groupadd -r nixbld
for n in $(seq 1 10); do sudo useradd -c "Nix build user $n" \
@wilspi
wilspi / main.rs
Last active May 10, 2019 15:07
Rust - abnormal behaviour - dangling reference
#[derive(Debug)]
pub enum Superheroes {
Superman(Superman),
Batman(Batman)
}
#[derive(Debug)]
pub struct Superman {
id: i32,
name: String,
@wilspi
wilspi / udp_server.py
Created February 12, 2019 14:08
Mock Statsd server
# -*- coding: utf-8 -*-
# Script to run UDP Server on 127.0.0.1:8126
# This mocks statsd server for testing
import socket
UDP_IP_ADDRESS = "127.0.0.1"
UDP_PORT_NO = 8126
@wilspi
wilspi / GetQuotes.py
Created March 17, 2018 05:16
Get Quotes from BrainyQuote.com
#!/usr/bin/python
from selenium import webdriver
from bs4 import BeautifulSoup
def getPage(url):
# open with chromedriver
browser = webdriver.Chrome()
browser.get(url)