Skip to content

Instantly share code, notes, and snippets.

View hpez's full-sized avatar

Hassan Pezeshk hpez

View GitHub Profile
@hpez
hpez / kill-huge-processes.sh
Created December 27, 2018 12:52
A gist to kill processes taking more than i% cpu. Useful for closing huge processes really fast and rescuing!
#!/bin/bash
output="$(sudo ps -eo %cpu,pid --sort -%cpu)"
while read -r line; do
words=($line)
st=$(echo ${words[0]}'>'5 | bc -l) # Change the number '5' to any number kill the processes taking more than that percent of cpu
if [ "$st" = "1" ];
then
echo ${line}
exec sudo kill -9 ${words[1]}
@hpez
hpez / image_to_video.php
Last active March 30, 2018 16:17
Give it an array of addresses to image files, it turns them into a video and returns the address to that using FFMPEG
function pic2vid($picAddresses)
{
$prefix = uniqid("app"); //A prefix for temp files
foreach ($picAddresses as $key => $picAddress) {
copy($picAddress, sys_get_temp_dir() . '/' . $prefix . sprintf('%03d', $key + 1) . '.png');
if ($key == count($picAddresses) - 1)
copy($picAddress, sys_get_temp_dir() . '/' . $prefix . sprintf('%03d', $key + 2) . '.png');
}
$filename = uniqid();
shell_exec("/usr/local/bin/ffmpeg -framerate 0.5 -i " . sys_get_temp_dir() . '/' . $prefix . "%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p " . sys_get_temp_dir() . '/' . $filename . ".mp4 2>&1");