Skip to content

Instantly share code, notes, and snippets.

@simofacc
simofacc / drupal7.php
Last active January 31, 2016 08:42
Drupal 7 – Enable a theme from a custom module via code
<?php
function mymodule_init()
{
$themes = list_themes(); //Get all the available themes
if ($themes['mythemename']->status == 0) {
//if mythemename status is 0 i.e. disabled
theme_enable(array(
'mythemename'
)); //enable theme
}
@simofacc
simofacc / youtube-hide.js
Last active October 25, 2017 07:49
How to stop a youtube iframe video after closing a popup
//Cache jQuery object in a variable
var $youtubeIframeId = $('#YourIFrameID');
//First get the iframe URL
var url = $youtubeIframeId.attr('src');
//Then assign the src to an empty String, this then stops the video from playing
$youtubeIframeId.attr('src', '');
// Finally reassign the iframe URL (url) back to the iframe, so when you hide the video and show it again you still have the correct source
@simofacc
simofacc / .htaccess
Created January 31, 2016 08:48
Setting environment variables in Magento using .htaccess
############################################
## If developing on localhost, uncomment this to enable developer mode
SetEnvIf REMOTE_ADDR ^127.0.0.1 MAGE_IS_DEVELOPER_MODE
# Default store
SetEnvIf HOST ^store1.yourdomain.com.au$ MAGE_RUN_CODE=default
SetEnvIf HOST ^store1.yourdomain.com.au$ MAGE_RUN_TYPE=store
# Store two variables
SetEnvIf HOST ^store2.yourdomain.com.au$ MAGE_RUN_CODE=store_two
@simofacc
simofacc / httpd.conf
Created January 31, 2016 08:50
Setting environment variables in Magento using httpd.conf
documentroot "c:/xampp/htdocs/magento"
servername magento.server.dev
SetEnv MAGE_IS_DEVELOPER_MODE "1"
@simofacc
simofacc / post-to-curl.php
Last active February 6, 2016 16:23
Wordpress - Send post data to 3rd party service via curl
<?php
/**
* @package Post-to-Curl
* @version 1.0
*/
/*
Plugin Name: Post-to-Curl
Plugin URI: http://www.simonfacciol.info
Description: Send post data / status to 3rd party service via curl
Author: Simon Facciol
@simofacc
simofacc / check_resolution.py
Created February 24, 2016 09:20
Check the resolution of images in a directory and output the incorrect image filenames
import Image
import os
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for file in files:
if file.endswith(('.jpg')):
img = Image.open(os.path.join(os.curdir, file))
size = img.size
if ((410, 300) != size):
name = file + ' '
@simofacc
simofacc / mysql-slug.sql
Last active March 13, 2016 00:28
MySQL trigger to generate a slug before inserting a new row
CREATE DEFINER=`[USER_NAME]`@`%` TRIGGER `[DATABASE_NAME]`.`Slug` BEFORE INSERT ON `[TABLE_NAME]`.`games` FOR EACH ROW
BEGIN
IF NEW.slug IS NULL THEN
SET NEW.slug = LOWER(TRIM(NEW.name));
SET NEW.slug = REPLACE(NEW.slug, ':', '');
SET NEW.slug = REPLACE(NEW.slug, ')', '');
SET NEW.slug = REPLACE(NEW.slug, '(', '');
SET NEW.slug = REPLACE(NEW.slug, ',', '');
SET NEW.slug = REPLACE(NEW.slug, '\\', '');
SET NEW.slug = REPLACE(NEW.slug, '?', '');
@simofacc
simofacc / rename.py
Created March 13, 2016 00:49
Python, rename files using csv file map
import os
import csv
with open('old-names-new-names.csv', 'rb') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in csvreader:
name = row[0] + '.jpg'
new = row[1] + '.jpg'
if os.path.exists(name):
os.rename(name, new)
@simofacc
simofacc / gulp.js
Last active March 16, 2016 18:13
Gulp setup
/**
* Created by simonfacciol on 13/02/16.
*/
var gulp = require('gulp'),
fs = require('fs'),
del = require('del'),
plugins = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/,
lazy: true,
@simofacc
simofacc / changelog.sh
Created April 7, 2016 07:38
Github changelog generator
#!/bin/bash
# Author:Andrey Nikishaev
# Modified: Simon Facciol
echo "CHANGELOG"
echo ----------------------
git for-each-ref --sort=-taggerdate --format '%(tag)-%(*authordate)' refs/tags | grep 'release' | while read RES ; do
IFS='-' read -a arrRES <<< "${RES}"
TAG=${arrRES[0]}
DAT=${arrRES[1]}
echo