Skip to content

Instantly share code, notes, and snippets.

View mechalynx's full-sized avatar

mechalynx

  • Cold storage
View GitHub Profile
@mechalynx
mechalynx / README.md
Last active July 3, 2018 00:07
Handy ffmpeg stuff

None of these operations are destructive. That means they give you a new file, they don't write over the old one, so they're safe to try as long as you're not low on HDD space. If something goes wrong and it seems to be taking too long, just Ctrl+C and it'll stop.

Convert to mp4 and keep only one audio stream:

ffmpeg -i #VIDEOFILE -codec copy -map 0:v:0 -map 0:a:#N output.mp4

Where #VIDEOFILE is your video's filename (quote it if it has spaces in it) and #N is the index of the audio track you want to keep, starting with 0 for the first audio track (so if you have 3 tracks, they're 0, 1 and 2).

@mechalynx
mechalynx / memory-management.md
Last active July 1, 2018 13:51
Memory management

Memory management

When your PC runs out of space in real RAM it swaps out the parts of it that aren't being used much to the hard drive aka to "swap space". If this isn't done, either the process crashes or the OS crashes ("bluescreen").

Because HDD I/O operations have to be completed before code is allowed to continue (to preserve integrity, so you don't get race conditions) the OS will temporarily stop whatever is accessing that RAM. This is why programs go unresponsive or stutter when there's a lot of HDD activity related to them. In the case of swapping, this can cause other stuff to stutter and go unresponsive as well, since the memory being swapped may be theirs or they might be using the HDD.

When you're doing real-time stuff like games, you want to avoid swapping as much as possible obviously. This means making sure there is enough real RAM left for whatever you're doing. In order to ensure this, you need to end memory hog processes ahead of time.

For Windows, there's 2

@mechalynx
mechalynx / detect_leading_spaces.sh
Last active September 16, 2017 15:11
Detecting leading spaces in a string using bash
#! /usr/bin/env bash
# This function will remove all spaces surrounding a string by
# using echo and IFS. Then it aggressively removes instances of
# the string from itself and everything that follows. In other words
# it returns a string that is the difference of itself with spaces
# and without spaces, specifically leading spaces. The length
# of the returned string is equal to the number of leading spaces.
# Not tested for tabs and other characters, but more fine-tuned
@mechalynx
mechalynx / custom_deque.py
Created May 6, 2016 08:55
Python `deque` class with dynamically configurable length.
# -*- coding: utf-8 -*-
# should be under __main__ but __future__ imports
# are special and don't behave like other imports
# so this has to be at the beginning
from __future__ import print_function
from collections import deque