Skip to content

Instantly share code, notes, and snippets.

View Antrikshy's full-sized avatar

Antriksh Yadav Antrikshy

View GitHub Profile
@Antrikshy
Antrikshy / bmw_drive_recorder_extract.py
Last active May 12, 2024 22:05
Extract and rename BMW Drive Recorder video clips
"""
Script to extract video files written by the BMW Drive Recorder in my 2024 model
and rename them using the date and time in the directory names that it writes
into USB storage.
This is free and unencumbered software released into the public domain and comes
with no warranties.
Requirements:
@Antrikshy
Antrikshy / persistence.js
Created September 5, 2022 21:42
A painless localStorage manager in JS ES6, with support for partitioning keys so that different parts of a project don't step on each other's toes
/*
If you're viewing this on GitHub Gist, see a full guide, including React Router examples at:
https://antrikshy.com/code/painless-partitioned-localstorage-with-namespaces-react-router
*/
export default class PersistenceHandler {
constructor(prefix="Project-Name") {
this.prefix = prefix;
}
@Antrikshy
Antrikshy / interrupt_handling_python_script.py
Created February 21, 2022 00:49
Python snippet for elegantly handling interruptions, like keyboard interrupts, in simple scripts that can be structured around this
import signal
import sys
def _handle_interrupt(signum, _):
signal.signal(signum, signal.SIG_IGN)
# Any cleanup steps go here
sys.exit(signal.SIGINT)
signal.signal(signal.SIGINT, _handle_interrupt)
# Rest of script...
@Antrikshy
Antrikshy / lang_by_dev_type.py
Created June 5, 2019 05:31
Script to re-process Stack Overflow Developer Survey 2019 data to get tech popularity stats by self-reported developer type
import csv
from collections import Counter
have_tally = {}
want_tally = {}
# Get the dataset at insights.stackoverflow.com/survey
path_to_datum = '/path/to/downloaded/developer_survey_2019/survey_results_public.csv'
# This *should* work without too much modification with SO survey datasets from other
@Antrikshy
Antrikshy / job_hunt.sh
Created August 11, 2016 07:20
Tired of manually trudging through website source code for easter eggs and invitations to apply for jobs?
declare -a arr=("google.com" "facebook.com"
"amazon.com" "yahoo.com" "flickr.com"
"youtube.com" "twitter.com" "reddit.com") # etc etc
for i in "${arr[@]}"
do
echo "$i"
curl -L --silent "$i" | grep -E "hiring|jobs"
# Maybe even look for easter eggs this way!
done
@Antrikshy
Antrikshy / data_split.py
Last active May 17, 2022 09:07
Simple, configurable Python script to split a single-file dataset into training, testing and validation sets
import random
import math
# Configure paths to your dataset files here
DATASET_FILE = 'data.csv'
FILE_TRAIN = 'train.csv'
FILE_VALID = 'validation.csv'
FILE_TESTS = 'test.csv'
# Set to true if you want to copy first line from main
@Antrikshy
Antrikshy / majority_element.py
Last active August 29, 2015 14:19
O(nlogn) majority element algorithm
def majority_element(a):
n = len(a)
if n == 1:
return a[0]
if n == 0:
return None
k = n/2
elem1 = majority_element(a[:k])
elem2 = majority_element(a[k+1:])
@Antrikshy
Antrikshy / quibbler.conf
Created April 11, 2015 07:15
nginx config for Quibbler.co, Express.js apps listening on port 3000
# Goes in /etc/nginx/conf.d/
upstream quibbler {
server 127.0.0.1:3000;
}
server {
listen 0.0.0.0:80;
server_name quibbler.co www.quibbler.co;
@Antrikshy
Antrikshy / websitename.conf
Last active August 29, 2015 14:18
Upstart config for Express.js app
# Goes in /etc/init/
description "Blah server"
start on startup
start on filesystem and started networking
stop on shutdown
respawn
chdir /home/username/folder
@Antrikshy
Antrikshy / tester-pa3.py
Last active May 1, 2016 20:44
CSE 100 Fall '14 Network Planning (pa3) Tester
#!/usr/bin/env python
import os, sys, subprocess, time
import filecmp as fc
# --------------------------------------------------------------------------------------------------------
# Backport of Python 2.7's subprocess.check_output function from https://gist.github.com/edufelipe/1027906
def check_output(*popenargs, **kwargs):
r"""Run command with arguments and return its output as a byte string.
Backported from Python 2.7 as it's implemented as pure python on stdlib.