Skip to content

Instantly share code, notes, and snippets.

@shemigon
shemigon / reduce_dir_nesting.py
Created November 22, 2012 11:45
Reduce directory nesting: aa/bb/cc/dd/ee.ext => aa/bb/ccddee.ext
TARGET_DIR = '/full/path/to/dir/containing/dirs/to/reduce/'
TARGET_DIR_LEN = len(TARGET_DIR) + 1
CURRENT_DEPTH = 6
DESIRED_DEPTH = 2
last_dir = ''
for dirname, _, filenames in os.walk(TARGET_DIR):
path = dirname[TARGET_DIR_LEN:].split('/')
if filenames and len(path) >= CURRENT_DEPTH:
cur_dir = '/'.join(path[:DESIRED_DEPTH - CURRENT_DEPTH])
@shemigon
shemigon / plugin.js
Created April 25, 2011 12:52
CKEditor autosave plugin
/**
* Autosave plugin for CKEditor (requires jQuery)
*
* CKEDITOR.config.autosave_delay - delay in seconds before request is sent (located in config.js)
* #AUTO_SAVE_URL - input (usually hidden) with save url (located on the page)
*
* Server's supposed to send back {status: ok|error, (optional message: text)}
*
* Place it in plugins/autosave directory
* @author Boris Shemigon <i@boris.co>