Skip to content

Instantly share code, notes, and snippets.

View stemwinder's full-sized avatar

Joshua Smith stemwinder

View GitHub Profile
@stemwinder
stemwinder / LVM on Ubuntu howto
Created March 6, 2018 21:22 — forked from runozo/LVM on Ubuntu howto
Using LVM on Linux and resize swap partition
# RESCAN FOR NEWLY ADDED HDS
echo "- - -" > /sys/class/scsi_host/host#/scan
fdisk -l
# NEW LOGICAL VOLUME
sudo fdisk /dev/sdb
# then create a new partition of type 8e (Linux LVM)
# create a phisical volume
sudo pvcreate /dev/sdb1
# create new volume group
@stemwinder
stemwinder / ffmpeg-multi-instances-xargs.md
Created October 7, 2017 18:07 — forked from Brainiarc7/ffmpeg-multi-instances-xargs.md
This gist will show you how to launch multiple ffmpeg instances with xargs, very useful for NVIDIA NVENC based encoding where standard GPUs limit the maximum simultaneous encode sessions to two.

Spawning multiple ffmpeg processes with xargs:

On standard NVIDIA GPUs (Not the Quadros and Tesla lines), NVENC encodes are limited to two simultaneous sessions. The sample below illustrates how to pass a list of AVI files to ffmpeg and encode them to HEVC on two encode sessions:

$ find Videos/ -type f -name \*.avi -print | sed 's/.avi$//' |\
  xargs -n 1 -I@ -P 2 ffmpeg -i "@.avi" -c:a aac -c:v hevc_nvenc "@.mp4"

This will find all files with the ending .avi in the directory Videos/ and transcode them into HEVC/H265+AAC files with the ending .mp4. The noteworthy part here is the -P 2 to xargs, which starts up to two processes in parallel.

@stemwinder
stemwinder / transient-clustering-gnu-parallel-sshfs.md
Created October 7, 2017 05:10 — forked from Brainiarc7/transient-clustering-gnu-parallel-sshfs.md
How to set up a transient cluster using GNU parallel and SSHFS for distributed jobs (such as FFmpeg media encodes)

Transient compute clustering with GNU Parallel and sshfs:

GNU Parallel is a multipurpose program for running shell commands in parallel, which can often be used to replace shell script loops,find -exec, and find | xargs. It provides the --sshlogin and --sshloginfile options to farm out jobs to multiple hosts, as well as options for sending and retrieving static resources and and per-job input and output files.

For any particular task, however, keeping track of which files need to pushed to and retrieved from the remote hosts is somewhat of a hassle. Furthermore, cancelled or failed runs can leave garbage on the remote hosts, and if input and output files are large, sending them to local disk on the remote hosts is somewhat inefficient.

In a traditional cluster, this problem would be solved by giving all nodes access to a shared filesystem, usually with NFS or something more exotic. However, NFS doesn't wo

@stemwinder
stemwinder / array_remove_similar.php
Created August 15, 2017 17:12 — forked from danielmartins/array_remove_similar.php
PHP: Remove duplicates items of an array based on similarities
<?php
/**
* This functions runs like array_unique but is based on similarity
* and the math is based on similar_text to know better, see: php.net/similar_text
*
* @param [type] $array [description]
* @param integer $howMuch [description]
* @param [type] $callback [description]
* @return [type] [description]
@stemwinder
stemwinder / myisam-to-innodb.sql
Created May 17, 2017 02:33
Generate SQL statements to convert all database tables from MyISAM to InnoDB
SELECT CONCAT('ALTER TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ' engine=InnoDB;')
FROM information_schema.TABLES WHERE ENGINE = 'MyISAM';
@stemwinder
stemwinder / flac2alac.sh
Last active May 21, 2017 20:11
FLAC & ALAC Commands
# delete all FLAC files recursively
find ./* -depth -type f -name \*.flac -delete
# list all FLAC files recursively
find ./* -depth -type f -name \*.flac
# convert all FLAC files to ALAC recursively
find ./* -depth -type f -name \*.flac | parallel -j+0 --gnu nice -n 19 ffmpeg -i "{}" -c:a alac "{.}.m4a"
# convert FLAC to ALAC and strip album art
@stemwinder
stemwinder / xhr-capture.js
Created April 14, 2017 01:23
Injectable JS to capture XHR responses
// http://stackoverflow.com/a/10796951
(function(XHR) {
"use strict";
var element = document.createElement('div');
element.id = "interceptedResponse";
element.appendChild(document.createTextNode(""));
document.body.appendChild(element);
var open = XHR.prototype.open;
@stemwinder
stemwinder / README.md
Created February 3, 2017 18:04 — forked from jehaby/README.md
Debug PHP in Docker with PHPStorm and Xdebug

Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple:
FROM php:5

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
@stemwinder
stemwinder / duplicate-rows.sql
Last active July 13, 2016 15:19
Duplicate / Copy rows in MySQL table
-- http://stackoverflow.com/a/8077952/3530438
CREATE TEMPORARY TABLE tmp SELECT * from invoices WHERE ...;
ALTER TABLE tmp drop ID; # drop autoincrement field
# UPDATE tmp SET ...; # just needed to change other unique keys
INSERT INTO invoices SELECT 0,tmp.* FROM tmp;
DROP TABLE tmp;
@stemwinder
stemwinder / eloquent-parent-orderby.php
Last active May 3, 2020 18:24
Eloquent: Order parent results by relationship column
<?php
$products = Shop\Product::join('shop_products_options as po', 'po.product_id', '=', 'products.id')
->orderBy('po.pinned', 'desc')
->select('products.*') // just to avoid fetching anything from joined table
->with('options') // if you need options data anyway
->paginate(5);
// SELECT clause is there in order to not appending joined columns to your Product model.
// Originaly found at: http://stackoverflow.com/questions/23530051/laravel-eloquent-sort-by-relation-table-column