Skip to content

Instantly share code, notes, and snippets.

View sevennineteen's full-sized avatar

Patric M DelCioppo sevennineteen

View GitHub Profile
@sevennineteen
sevennineteen / app.rb
Created September 10, 2011 19:05
Basic security check to prevent cross-site requests (using Sinatra)
require "rubygems"
require "sinatra"
require "json"
require "haml"
get '/' do
CURRENT_HOST = env['SERVER_NAME'] == 'localhost' ? "#{env['SERVER_NAME']}:#{env['SERVER_PORT']}" : env['SERVER_NAME']
haml :home
end
@sevennineteen
sevennineteen / gist:1224478
Created September 17, 2011 23:14
Set logger level on Heroku Sinatra app
require "logger"
configure do
LOG = Logger.new(STDOUT)
LOG.level = Logger.const_get ENV['LOG_LEVEL'] || 'DEBUG'
LOG.info 'I am logging something.'
end
@sevennineteen
sevennineteen / gist:1235375
Created September 22, 2011 17:14
Boilerplate to extend Day CQ's HTTP Polling Importer
package com.my.company.customimporter;
import java.io.IOException;
import java.io.InputStream;
import org.apache.sling.api.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.polling.importer.HttpImporter;
@sevennineteen
sevennineteen / delta_monitor.py
Created December 18, 2011 20:55
Produce high-level summary of file system changes since a given date
import codecs, os, glob
from datetime import datetime
import time
from stat import *
#----------------------------------------------------------
BASE_DIR = r'C:\some_folder'
FILE_DIRS = [
'some_subfolder_a',
'some_subfolder_b',
@sevennineteen
sevennineteen / tree_activation.py
Created January 25, 2012 23:21
CQ5 tree activation example
import httplib2
import urllib
import base64
from html2text import html2text
#----------------------------------------------------------
# INSTANCE-SPECIFIC CONSTANTS // customize before running
CQ_HOSTNAME = 'localhost'
CQ_SERVER = 'http://%s:4502' % CQ_HOSTNAME
USERNAME = 'admin'
@sevennineteen
sevennineteen / gist:2763408
Created May 21, 2012 17:25
Show HTTP request headers (Rack)
require 'sinatra'
get '/' do
@headers = env.reject {|k, v| k =~ /async*|rack*/}.sort.each
haml :index
end
@sevennineteen
sevennineteen / example.json
Created December 28, 2012 18:16
Example using Jinja2 to populate a JSON payload template
{ "path": "/content/geometrixx/my-first-jinja-page",
"properties": [
{ "name": "jcr:primaryType",
"value": "cq:Page" }],
"nodes": [
{ "path": "jcr:content",
"properties": [
{ "name": "jcr:primaryType",
"value": "cq:PageContent"},
@sevennineteen
sevennineteen / template-helpers.js
Created March 9, 2013 15:53
Simple Handlebars helper to dump current context to screen for debugging
define(['handlebars'], function (Handlebars) {
var templateHelpers = {
// Register all defined template helpers
load: function () {
// Render JSON representation of current context,
// e.g., {{{debug this}}}
Handlebars.registerHelper('debug', function (context) {
return new Handlebars.SafeString(