Skip to content

Instantly share code, notes, and snippets.

View stefanbc's full-sized avatar
🖖
Do; or do not. There is no // TODO

Stefan Cosma stefanbc

🖖
Do; or do not. There is no // TODO
View GitHub Profile
@stefanbc
stefanbc / plex-cleanup.py
Last active April 19, 2023 07:58
Python script that deletes watched videos from a Plex Media Server, writes the results to a log file and sends a notification via IFTTT webhook
#!/usr/bin/env python
import os
import requests
import json
import xmltodict
from datetime import datetime
# Set the script properties
PLEX_URL = 'http://localhost:32400'
@stefanbc
stefanbc / appsscript.json
Last active September 7, 2022 06:39
Plex Cleanup
{
"timeZone": "Europe/Bucharest",
"dependencies": {
"enabledAdvancedServices": []
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/gmail.metadata"
@stefanbc
stefanbc / replaceDiacritics.php
Last active October 2, 2018 07:58
Convert all diacritics in a string to a string without diacritics
function replaceDiacritics($str) {
return preg_replace(
array(
/* Lowercase */
'/[\x{0105}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u',
'/[\x{00E7}\x{010D}\x{0107}]/u',
'/[\x{010F}]/u',
'/[\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{011B}\x{0119}]/u',
'/[\x{00EC}\x{00ED}\x{00EE}\x{00EF}]/u',
'/[\x{0142}\x{013E}\x{013A}]/u',
@stefanbc
stefanbc / perms.md
Last active April 13, 2024 12:16
Set proper permissions on /var/www/

HOWTO

To set up permissions on /var/www where your files are served from by default:

sudo addgroup webmasters
sudo adduser $USER webmasters
sudo chown -R root:webmasters /var/www
sudo find /var/www -type f -exec chmod 664 {} \;
sudo find /var/www -type d -exec chmod 775 {} \;
@stefanbc
stefanbc / functions.php
Last active December 28, 2017 17:10
Convert Google Maps Longitude / Latitude to degrees, minutes, seconds, direction
<?php
function format_latlong($decimal, &$degrees, &$minutes, &$seconds, &$direction, $type = true) {
//set default values for variables passed by reference
$degrees = 0;
$minutes = 0;
$seconds = 0;
$direction = 'X';
//decimal must be integer or float no larger than 180;
//type must be Boolean
@stefanbc
stefanbc / README.md
Last active August 29, 2015 14:07 — forked from addyosmani/README.md
CSS Layout Debugger

CSS Layout Debbuger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@stefanbc
stefanbc / size.sql
Created August 4, 2014 09:34
Find out database size using a query (usable in phpMyAdmin)
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ;
@stefanbc
stefanbc / functions.php
Created July 23, 2014 12:54
Automatically add product to cart, on Woocommerce.
<?php
// Add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = THE_PRODUCT_ID;
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
@stefanbc
stefanbc / export.php
Last active March 28, 2017 09:45
Export CSV from osCommerce and import it in Prestashop.Instructions:* Place the script in your osC root folder* Call the script in your browser* Save the file* Import it in Prestashop* Map the fields* Import!* You're awesome! Note: Tested with osC 2.2 rc 2a and Ps 1.5.4.1
<?php
require('includes/application_top.php');
// Output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// Create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
@stefanbc
stefanbc / header.tpl
Created May 13, 2014 11:26
Login with Facebook using Login Radius in Prestashop
<!-- Requires dependencies https://github.com/carhartl/jquery-cookie -->
<script src="{$js_dir}jquery.cookie.js"></script>
{if $smarty.get.fb == 1 && $page_name == 'index'}
<script type="text/javascript">
$(document).ready(function(){
// console.log("BEFORE");
var cookie = $.cookie("loggedinFB");