Skip to content

Instantly share code, notes, and snippets.

@hughgrigg
hughgrigg / switch-magento-downloadables-link.sql
Last active August 29, 2015 14:07
Switch LK downloadables to use S3
@hughgrigg
hughgrigg / magento-media-s3.sh
Last active November 30, 2016 14:40
Syncing Magento media to AWS S3
# Obviously needs editing to suit situation!
rsync -rv --exclude="js" --exclude="css_secure" --exclude="css" --exclude="downloadable" --exclude="catalog" --exclude="import" broadmar@mceuk004-fs.nexcess.net:/home/broadmar/loveknitting.com/current/public/media/ ~/lk-media-download/
aws s3 sync --recursive --acl="public-read" ~/lk-media-download s3://loveknitting-media/media
@hughgrigg
hughgrigg / magento-remove-invalid-fk-option-entity-int-rows.sql
Created October 22, 2014 15:20
Removing invalid rows from Magento eav_attribute_option and catalog_product_entity_int
# Delete option rows pointing to non-existent attributes
DELETE `option`
FROM `eav_attribute_option` AS `option`
LEFT JOIN `eav_attribute`
ON `eav_attribute`.`attribute_id` = `option`.`attribute_id`
WHERE `eav_attribute`.`attribute_id` IS NULL;
# Delete product attribute int rows pointing to non-existent attributes
DELETE `entity_int`
FROM `catalog_product_entity_int` AS `entity_int`
@hughgrigg
hughgrigg / magento-find-unused-options.py
Created October 23, 2014 08:43
Find unused options in Magento database
import MySQLdb, sys, time
# Lists out unused attribute options in a Magento DB
# This script generates an SQL query you can use but doesn't make any changes
# to DB on its own
db = MySQLdb.connect(
host="localhost",
user="root",
passwd="",
@hughgrigg
hughgrigg / gulpfile.js
Last active August 29, 2015 14:18
Jekyll WordPress import post processing gulpfile for Hugo
// This is a throwaway / single-use gulpfile I used to process and tidy up the
// files resulting from using Jekyll's WordPress exporter. I wanted to move from
// WordPress to Hugo with a relatively large number of posts; this gulpfile let
// me quickly process all the content files and get on with building the site.
var
gulp = require('gulp'),
replace = require('gulp-replace'),
rename = require('gulp-rename'),
entities = require('gulp-html-entities'),
@hughgrigg
hughgrigg / gulpfile.js
Created May 11, 2015 05:43
Gulp insert front-matter date from filename
// Throwaway Gulp script to insert dates from file-names into the front-matter
// of content source files
var gulp = require('gulp'),
through = require('through2');
gulp.task('insert-dates', function() {
return gulp.src('content/posts/**/*.md')
.pipe(through.obj(
function(file, enc, callback) {
@hughgrigg
hughgrigg / magento-convert-drop-down-attribute-to-varchar.sql
Created August 26, 2015 15:17
Convert Magento drop-down attribute into varchar attribute
INSERT INTO catalog_product_entity_varchar
(entity_type_id, attribute_id, store_id, entity_id, `value`)
SELECT
4 AS entity_type_id,
216 AS attribute_id,
`existing_value`.store_id,
`existing_option_id`.entity_id,
`existing_value`.`value`
FROM `eav_attribute_option_value` AS `existing_value`
INNER JOIN catalog_product_entity_int AS `existing_option_id`
@hughgrigg
hughgrigg / bbc-radio4.sh
Created March 15, 2016 15:22
BBC Radio 4 on the command line
#!/bin/sh
mplayer http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p
@hughgrigg
hughgrigg / recursive-image.py
Created March 31, 2016 14:17
Python recursive image
from __future__ import division
import argparse
from PIL import Image
from math import log
parser = argparse.ArgumentParser()
parser.add_argument("start_file", help="filename of initial image")
parser.add_argument(
"-x",
"--xpercent",
@hughgrigg
hughgrigg / elasticsearch-ids.sh
Last active August 2, 2016 14:15
Pull out query IDs from ElasticSearch
curl -XGET 'http://makersearch.prod.lovecrafts.cool:9200/read-model/_search' -d '
{
"query": {
"filtered": {
"filter": {
"and": [
{
"bool": {
"must": {
"term": {