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 / perms.md
Last active April 22, 2024 07:51
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 / 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 / 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 February 20, 2014 07:06
Custom Functions for Contact Form 7
<?php
// Get date from Contact Form 7 before email send
add_action("wpcf7_before_send_mail", "wpcf7_save_data");
function wpcf7_save_data(&$wpcf7_data) {
// Here is the variable where the data are stored!
$user_nume = $wpcf7_data->posted_data['user_nume'];
$user_email = $wpcf7_data->posted_data['user_email'];
// Set the cookies
setcookie('os_username', $user_nume, time() + (10*365*24*60*60));
@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 / 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 / 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 / remove_slug.php
Created September 19, 2013 07:32
These functions remove the slug from a permalink for a custom post type. These should be placed in functions.php in your theme and the permalink structure should be /%postname%/
<?php
add_filter('post_type_link','custom_post_type_link',10,3);
function custom_post_type_link($permalink, $post, $leavename) {
$url_components = parse_url($permalink);
$post_path = $url_components['path'];
$post_name = end(explode('/', trim($post_path, '/')));
if(!empty($post_name)) {
@stefanbc
stefanbc / functions.php
Created February 26, 2014 08:58
Add Checkbox option to General Settings
<?php
$new_general_setting = new new_general_setting();
class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'OPTION_NAME', 'esc_attr' );
add_settings_field('OPTION_NAME', '<label for="OPTION_NAME">'.__('OPTION_LABEL_TEXT' , 'OPTION_NAME' ).'</label>' , array(&$this, 'fields_html') , 'general' );