Skip to content

Instantly share code, notes, and snippets.

View fsalehpour's full-sized avatar

Faramarz Salehpour fsalehpour

View GitHub Profile
@fsalehpour
fsalehpour / ghostscript-tips.sh
Last active June 13, 2022 19:32
Tips to do things with ghostscripts
# Reduce the size of a PDF file
# https://askubuntu.com/a/256449/112818
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output_reduced.pdf input.pdf
# Convert a PDF to grayscale colour
# https://superuser.com/a/164857/989263
gs \
-sOutputFile=output_gray.pdf \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
# create hardsubs for a video from a SRT file using FFMPEG
# https://stackoverflow.com/a/21369850/1887369
ffmpeg -i video.mp4 -vf "subtitles=subs.srt:force_style='Fontname=Times New Roman,Fontsize=24,PrimaryColour=&H0000ff&'" output.mp4
## to take only a section of the video:
ffmpeg -ss 00:02:00 -copyts -i video.mkv -ss 00:02:00 -vf "subtitles=subs.srt:force_style='Fontsize=24,Fontname=Times New Roman'" -to 00:02:30 cut.mp4
# convert the pixel format using the format filter
# https://stackoverflow.com/a/54196619/1887369
@fsalehpour
fsalehpour / today.zsh
Last active September 17, 2019 17:41
A zsh function that prints all the shell commands ran by the current user since the beginning of the today!
#!/usr/bin/env zsh
function today (){
if [[ 0 -eq $# ]]; then
lines=10
else
lines="$1"
fi
output=$(fc -lin -$lines)
#!/bin/sh
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
@fsalehpour
fsalehpour / watermark.bash
Last active November 5, 2017 11:21
Script to add a scrolling watermark and scaling a video in one go using `ffmpeg`
#!/bin/bash
dir=$(pwd)
(cd $1
mkdir -p output
for i in *
do
output="output/$(echo $i | sed 's/\..*$/\.mp4/')"
@fsalehpour
fsalehpour / alog.php
Last active November 2, 2017 10:05
regex to extract data from Apache's access log
<?php
$pattern = '/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) \- \- \[([^\]]+)\] "([A-Z]+) ([^" ]+) [^"]*" ([0-9]+) ([0-9]+) "([^"]*)" "([^"]*)"/';
$heads = 'IP, timestamp, method, URI, status, size, referrer, agent' . PHP_EOL;
fputs(STDOUT, $heads);
while ($entry = fgets(STDIN)) {
preg_match($pattern, $entry, $segments);
@fsalehpour
fsalehpour / API.md
Created October 15, 2016 11:21 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

(function(A,f){var r,m,x,n="undefined",y={version:"3.2.3",css:"#font-friend{overflow:hidden;position:fixed;bottom:0;left:30px;background-color:#fff;background-color:rgba(255,255,255,0.93);width:740px;color:#222;-webkit-box-shadow:1px 1px 5px rgba(0,0,0,.3);-moz-box-shadow:1px 1px 5px rgba(0,0,0,.3);box-shadow:1px 1px 5px rgba(0,0,0,.3);z-index:10000;text-align:left;height:310px}#font-friend,#ff-drop h6,#ff-drop li{line-height:1.5!important}#ff-drop{padding:12px 12px 12px 36px}#ff-toggle{background-color:#222;color:#eee;display:block;width:12px;height:16px;padding:0 1px 0 3px;position:absolute;top:0;left:0;font-size:16px;line-height:1!important;cursor:pointer;z-index:10001;-moz-transition:.25s all ease-in-out;-webkit-transition:.25s all ease-in-out;-o-transition:.25s all ease-in-out;transition:.25s all ease-in-out}#ff-toggle sup{font-size:13px;line-height:1!important;vertical-align:super;display:none}.open #ff-toggle sup{display:inline}#ff-toggle:hover{color:#fff;background-color:#555}.open #ff-toggle{width:au
@fsalehpour
fsalehpour / sqllog-laravel4.php
Last active December 25, 2015 08:29
SQL query logging for Laravel 4. Put it somewhere to run, like app/filters.php. Thanks to Shawn McCool
<?php
// Logs SQL queries as info
// Thanks to @ShawnMcCool
// Link to the original content by Shawn McCool:
// https://github.com/LaravelIO/laravel-io/blob/master/app/filters.php#L71
Event::listen('illuminate.query', function($sql, $bindings)
{
foreach ($bindings as $val) {
@fsalehpour
fsalehpour / ytdl.bash
Created September 19, 2013 19:11
Youtube downloader using youtbue-dl
#!/bin/bash
python2.6 $HOME/bin/youtube-dl -F $1
echo -n "Enter the number of your file format choice: "
read format
python2.6 $HOME/bin/youtube-dl -t -f $format $1