Skip to content

Instantly share code, notes, and snippets.

@dcvezzani
dcvezzani / xxx_create_bcms_my401k_widgets.rb
Created June 4, 2013 14:02
When generating a custom content block type in BrowserCms, the migration generated uses 'def change'. A down migration doesn't appear to work and it is required to go back to the self.up and self.down notation.
class CreateBcmsMy401kWidgets < ActiveRecord::Migration
def self.up
Cms::ContentType.create!(:name => "BcmsMy401k::Widget", :group_name => "BcmsMy401k::Widget")
create_content_table :bcms_my401k_widgets, :prefix=>false do |t|
t.integer :user_id
t.string :name
t.text :description
t.timestamps
end
@dcvezzani
dcvezzani / apache-cxf-java-client-app-spring-configuration-ClientConfig.xml
Created May 31, 2013 19:51
Java client example for Spring configuration for Apache CXF-enabled client that will be establishing an encrypted connection (SSL via HTTPS) with a server, also powered by Apache CXF.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
@dcvezzani
dcvezzani / apache-cxf-java-client-app-spring-configuration.java
Created May 31, 2013 19:48
Java client snippet for configuration for Apache CXF-enabled client that will be establishing an encrypted connection (SSL via HTTPS) with a server, also powered by Apache CXF.
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
public final class UCIDMServicesClient {
private UCIDMServicesClient() {
}
public static void main(String args[]) throws java.lang.Exception {
@dcvezzani
dcvezzani / apache-cxf-spring-client-config-web.xml
Created May 31, 2013 19:40
Sample web.xml file for a Apache CXF-enabled client that will be establishing an encrypted connection (SSL via HTTPS) with a server, also powered by Apache CXF.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>UCPath-WS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
@dcvezzani
dcvezzani / dynamically-determine-the-route-namespace
Created May 30, 2013 15:57
Dynamically determine the route namespace for a bcms content block resource.
var cms_namespace = "<%= link_to("xxx", block_path(@block)).match(/href=\"\/([^\/]+)/)[1] %>";
@dcvezzani
dcvezzani / bash-extract-shutterstock-thumbnails.sh
Created April 8, 2013 14:41
Scrape thumbnails from shutterstock summary references.
# download html summaries
# paste in html reference to stockphoto summary page
# use wget to download a static page
wget http://www.shutterstock.com/pic-12539920/stock-photo-pretty-young-woman-with-arms-raised-standing-on-beach.html?src=1pUEJjjRjtTVA1C8FaQDfw-2-41
wget http://www.shutterstock.com/pic.mhtml?id=97713707
wget http://www.shutterstock.com/pic.mhtml?id=123208630
wget http://www.shutterstock.com/pic.mhtml?id=111719192
wget http://www.shutterstock.com/pic.mhtml?id=59363377
wget http://www.shutterstock.com/pic.mhtml?id=53308978
@dcvezzani
dcvezzani / truncate-tables-through-active-record.rb
Created April 6, 2013 14:39
[via Rails console] Truncate selected tables using ActiveRecord.
%w[bcms_my401k_articles bcms_my401k_article_versions].each do |t|
ActiveRecord::Base.connection.execute("truncate table #{t}")
end
@dcvezzani
dcvezzani / browsercms-app-helpers-cms-form-builder.rb
Created April 5, 2013 15:27
Adds rich text editor (rich text only, no plain text option) form helper.
# rails-app/browsercms/app/helpers/cms/form_builder.rb
#
# Adds additional form fields to the Rails FormBuilder which can be used to create CMS forms.
#
class Cms::FormBuilder < ActionView::Helpers::FormBuilder
...
# Renders a WYWIWYG rich text editor.
def cms_richtext_editor(method, options = {})
@dcvezzani
dcvezzani / browsercms-app-views-cms-form-builder-cms-richtext-editor.html.erb
Last active December 15, 2015 20:40
I wanted to make use of the form helpers that come with browsercms, but I don't want to provide ability to switch between CKEditor and plain text.
<%# rails-app/browsercms/app/views/cms/form_builder/_cms_richtext_editor.html.erb %>
<% tds = Time.now.strftime("%H%M%S") %>
<% id_with_tds = "#{id}_#{tds}" %>
<%= content_for :html_head do %>
<%= javascript_tag do %>
jQuery(function($) { setup_select_box_<%= id_with_tds %>(); })
<% end %>
<% end %>
@dcvezzani
dcvezzani / app-assets-javascripts-my401k-plan-sponsor-create-new-content-wizard.js
Last active December 15, 2015 20:40
Manage CKEditor instances with persisting data and successfully loading editors on an html page through an Ajax call.
/*
updates form controls with the content of the editors
typically called just before persisting to the database
*/
function CKupdate(){
if(typeof(CKEDITOR) != "undefined"){
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
}
}