Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
maxpeterson / migrate_to_feincms.py
Created October 5, 2011 11:27
Management command to migrate structure.page to feincms
from django.core.management.base import BaseCommand
from django.conf import settings
from incuna.structure.models import Page as StructurePage
from feincms.module.page.models import Page as FeinPage
from feincms.content.richtext.models import RichTextContent
def migrate_pages(structure_pages, template, region, parent=None, **options):
"""
Migrate the structure pages and their children (recursively)
"""
@maxpeterson
maxpeterson / wiki2md.sh
Created May 12, 2012 20:42
Convert Trac Wiki to Markdown
# Convert Trac wiki to Markdown
# Based in https://gist.github.com/619537/94091aa59bdf6d6e5ad2fbb063465b2d160156ad
#
#
################################################################################
# Single line code snippets
# {{{XXX}}}
# ==>
# `XXX`
# sed -i '' -Ee 's/{{{(.*)}}}/`\2`/' $@
@maxpeterson
maxpeterson / gist:3331075
Created August 12, 2012 10:21
Close frozen shell
[enter]
~
.
@maxpeterson
maxpeterson / withenv
Created September 24, 2012 09:31
Run a shell with environment variables set.
#!/bin/bash
display_usage() {
echo -e "\nUsage: $0 [command] \n"
echo -e "Execute the specified command with environment variables set."
echo -e "If no command is specified then execute a new shell.\n"
}
if [[ ( $1 == "--help") || $1 == "-h" ]]; then
display_usage
@maxpeterson
maxpeterson / .jamrc
Last active October 13, 2015 16:38
Cloudant CustomSearch for creating a private jamjs.org
exports.repositories = [
{
url: "https://USERNAME:PASSWORD@USERNAME.cloudant.com/DATABASE",
search: "https://USERNAME:PASSWORD@USERNAME.cloudant.com/DATABASE/_design/lucene/_search/jam"
},
"http://jamjs.org/repository"
];
@maxpeterson
maxpeterson / gist:4502176
Last active December 10, 2015 22:28
Fix require paths when migrating to jamjs
# Replace `lib/edetail` with `edetail`
grep -rl 'lib/edetail' project | xargs sed -i '' -e "s|[\"']lib/edetail/\(.*\)[\"']|'edetail/\1'|"
# Replace `underscore` with `lodash`
grep -rl 'lib/require-underscore/wrapper' project | xargs sed -i '' -e "s|[\"']lib/require-underscore/wrapper[\"']|'lodash'|"
# Replace `backbone` with `backbone-zepto`
grep -rl 'lib/require-backbone/wrapper' project | xargs sed -i '' -e "s|[\"']lib/require-backbone/wrapper[\"']|'backbone-zepto'|"
# Replace `zepto` plugins
for file in $(shopt -s nullglob; echo screenshots/*.jpg); do
echo convert "$file" -resize 200x150 "${file%%.*}-thumb.${file##*.}";
cp "$file" "${file%%.*}-full.${file##*.}";
convert "$file" -resize 200x150 "${file%%.*}-thumb.${file##*.}";
done;
@maxpeterson
maxpeterson / gist:6116594
Created July 30, 2013 20:25
Basic queue to ensure that calls are not called concurrently.
// The Veeva API can only accept one call at a time
// A queue is used to avoid calling the API while a call is in progress.
var Queue = (function () {
var queue = [];
var empty = true;
return {
// Add a function to the queue
// (it will be called immediately if the queue is empty)
push: function (fn) {
queue.push(fn);
@maxpeterson
maxpeterson / gist:6116613
Created July 30, 2013 20:28
Queue to ensure that functions are not called concurrently. Created to wrap Veeva API calls that can not be called concurrently.
// The Veeva API can only accept one call at a time.
// A queue is used to avoid calling the API while an earlier call is in progress.
var Queue = (function () {
var queue = [];
var empty = true;
return {
// Add a function to the queue
// (it will be called immediately if the queue is empty)
push: function (fn) {
queue.push(fn);
@maxpeterson
maxpeterson / gist:6122758
Last active December 20, 2015 11:19
Update key messages ins slides.yaml from key messages downloaded from Veeva report.
# Split key messages data
awk -F "\",\"" '{print $3 " " substr(substr($4, 0, match($4, /.zip/)-1), 26)}' keymessages.csv
# sed
awk -F "\"*,\"*" '{print " -e \"s/keyMessageId: "substr(substr($4, 0, match($4, /.zip/)-1), 26)"/keyMessageId: "$3"/\"\\"}' keymessages.csv \
| xargs -J % sed % -i '' project/data/slides.yaml