Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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-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 / 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 / journal-quick-format-git-mappings
Last active December 19, 2015 07:59
Clean up my quick text file journal entries into html I can slap into my blog. Put this in your ~/.vimrc file or create a vim script file that can be included in ~/.vimrc.
" ************* basic conversion script ******************
" the '/e' regexp flag in vim allows subsequent regexp to be
" run even if the current regexp doesn't have any hits
function! JournalBasicConversion(...)
" isolate each code block and surround with <pre...
:%s/^}}/ç/g
:%s/\n{{\(\([\r\n]\+[^ç]\+.*\)\+\)\nç/\r<pre class=\"code\">\1\r<\/pre>/eg
" create titles
:%s/^==\+ \(.\+\)$/<h4>\1<\/h4>/eg
@dcvezzani
dcvezzani / gist:4e210993c2a0b620cdec
Created April 16, 2015 22:41
move files to a new location; leave redirect behind
base_dst_path="/Volumes/Extra/dave/downloads"
for file in \
BW-1161.exe milkallergy-companion-and-cookbook.pdf iPhoneConfigUtility.dmg Screenhero.zip iPhotoLibraryUpgrader.dmg join.me.zip
do
#mv $file $base_dst_path
ln -s $base_dst_path/$file
#echo -e "# file was moved on "$(date +"%Y-%m-%d %H:%M:%S")"\nopen \"$base_dst_path/$file\"" > $file.txt
done
@dcvezzani
dcvezzani / multi_io.rb
Created October 27, 2015 20:39
Writes to both STDOUT and the specified file; can include as many IO streams as you want
# Usage example:
#
# log_filename = File.join(log_path, "#{Sinatra::Base.environment.to_s}.log")
# $log_file = File.open(log_filename, 'a+')
#
# STDOUT.sync = true if 'yes' == ENV['API_DEBUG']
# $log_file.sync = true if 'yes' == ENV['API_DEBUG']
#
# require 'logger'
# $logger = Logger.new MultiIO.new(STDOUT, $log_file)