Skip to content

Instantly share code, notes, and snippets.

@lfbittencourt
lfbittencourt / fps-converter.sh
Last active January 23, 2024 13:57
120 to 60 FPS converter using ffmpeg
#!/bin/bash
for file in *.MP4; do
echo "Processing $file..."
output="${file%.MP4}-60fps.mp4"
ffmpeg -i "$file" -movflags use_metadata_tags -filter:v fps=60 "$output"
done
@lfbittencourt
lfbittencourt / .htaccess
Created April 5, 2018 18:58
Loads production assets in case files don't exist locally
<IfModule mod_rewrite.c>
RewriteEngine On
# Try production domain if file doesnt exists
RewriteCond %{HTTP_HOST} !^foo\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^uploads/.*$ http://foo.com/$0 [L,NC]
</IfModule>
@lfbittencourt
lfbittencourt / SimpleCrypt.php
Created March 23, 2018 19:55
Simple reversible hashing class
<?php
class SimpleCrypt
{
protected static $factor = 2 / 3 / 5 / 7 / 11 / 13 / 17 / 19 / 23 / 29;
public static function crypt($value)
{
$hash = ceil($value / self::$factor);
@lfbittencourt
lfbittencourt / .htaccess
Last active January 12, 2019 13:39
Force non-www SSL version of a site
<IfModule mod_rewrite.c>
RewriteEngine On
# Force non-www
RewriteCond %{HTTP_HOST} ^www\.foo\.com$ [NC]
RewriteRule ^(.*)$ https://foo.com/$1 [L,R=301]
# Force SSL
RewriteCond %{HTTP_HOST} ^foo\.com$ [NC]
RewriteCond %{SERVER_PORT} ^80$
@lfbittencourt
lfbittencourt / SimpleApi.php
Last active December 4, 2017 13:09
Simple REST API abstraction
<?php
class SimpleApi
{
private $baseUrl;
public function __construct($baseUrl)
{
$this->baseUrl = $baseUrl;
}
@lfbittencourt
lfbittencourt / prettify-json.sh
Created March 14, 2017 17:49
Prettify JSON from curl
curl foo bar | python -m json.tool
@lfbittencourt
lfbittencourt / .htaccess
Created February 7, 2017 13:11
Force SSL/https without redirect loop
<IfModule mod_rewrite.c>
RewriteEngine On
# Force SSL
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
@lfbittencourt
lfbittencourt / .htaccess
Created January 27, 2017 12:14
Replacing broken local images by production's (from https://stevegrunwell.github.io/wordpress-git/#/13)
<IfModule mod_rewrite.c>
RewriteEngine on
# Attempt to load files from production if
# they're not in our local version
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule wp-content/uploads/(.*) \
http://{PROD}/wp-content/uploads/$1 [NC,L]
</IfModule>
@lfbittencourt
lfbittencourt / .htaccess
Last active January 11, 2017 17:13
.htaccess to force www or non-www version
# IMPORTANT: if there are another rules, put these ones right after "RewriteEngine on"
# Force non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
# Force www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
@lfbittencourt
lfbittencourt / unserialize_after_fixing.php
Created December 20, 2016 17:54
An unserialize wrapper that gets rid of "Error at offset" errors.
<?php
/**
* This function fixes string lengths before unserializing a value,
* in case some content was found and replaced, for example.
*
* @param string $str
* @param array $options
* @return mixed
*/