Skip to content

Instantly share code, notes, and snippets.

View jonkarna's full-sized avatar

Jon Karna jonkarna

View GitHub Profile
@jonkarna
jonkarna / input_default_value.js
Created March 26, 2009 21:12
jQuery: Automatically set value of input based on title of input
$("input[type=text][title]").each(function() {
$(this).val($(this).attr("title"));
if($.trim($(this).val()) == "")
$(this).val($(this).attr("title"));
$(this).focus(function() {
if($(this).val() == $(this).attr("title"))
$(this).val("");
}).blur(function() {
if($.trim($(this).val()) == "")
@jonkarna
jonkarna / external_links.js
Created March 26, 2009 21:14
jQuery: XHTML 'strict' compliant solution to opening links in new window
@jonkarna
jonkarna / generate_key.bat
Created September 22, 2009 20:16
script that I made to simplify the openssl process of taking a pem from FirstData and creating a p12
@echo off
cd C:\OpenSSL\bin
:: inputting store number
:inputStoreNumber
set sStoreNumber=
set /P sStoreNumber=Store #: %=%
if "%sStoreNumber%"=="" goto inputStoreNumber
:: inputting store password
FileUtils.rm_r takes an array
tmpfiles = Dir.glob("./**/.tmp")
FileUtils.rm_r tmpfiles
mp3files = Dir.glob("c:/**/*.mp3")
#the two ** == recursive
mp3files.each{|file| do_something_with(file) }
@jonkarna
jonkarna / RESTfulFilter.cfc
Created December 8, 2009 22:04
Making a contact form restful with Mach-II / Coldfusion
<cfcomponent display="RESTfulFilter" extends="MachII.framework.EventFilter">
<cffunction name="filterEvent" returnType="boolean">
<cfargument name="event" type="MachII.framework.Event" required="true" />
<cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />
<cfargument name="paramArgs" type="struct" required="false" default="#StructNew()#" />
<cfset var requestMethod = cgi.REQUEST_METHOD />
<cfset var _method = arguments.event.getArg("_method", requestMethod) />
<cfset var restMethod = "" />
@jonkarna
jonkarna / asi_jet_center.rake
Created May 25, 2011 14:17
Rake task for copying an updated flash file and resources
require 'ftools'
SPOTLIGHT_REGEX = "Z:/Active Projects/ASI JetCenter/FlashSpotlight/[^.]*.swf"
SPOTLIGHT_Z = Dir.glob SPOTLIGHT_REGEX
SPOTLIGHT_WEB = "flash/newjets.swf"
file SPOTLIGHT_WEB => SPOTLIGHT_Z do
if SPOTLIGHT_Z.length > 1
puts "Error: more than one files found that match regex"
puts " - " + SPOTLIGHT_REGEX
else
@jonkarna
jonkarna / test_prepare.rake
Created May 25, 2011 14:51
Removes test db creation and purging. I created this so that I could run my tests against a database backup.
Rake::TaskManager.class_eval do
def delete_task(task_name)
@tasks.delete(task_name.to_s)
end
Rake.application.delete_task("db:test:prepare")
Rake.application.delete_task("db:test:purge")
end
namespace :db do
namespace :test do
@jonkarna
jonkarna / tomcat-rake
Created June 29, 2011 20:57
Executing rake tasks against a deployed project on tomcat
cd `dirname $0`/.. && java -cp lib/jruby-core-1.6.2.jar:lib/jruby-stdlib-1.6.2.jar:lib/gems.jar org.jruby.Main -S rake "$@" RAILS_ENV=cron
@jonkarna
jonkarna / delegate_with_hash.rb
Created February 13, 2012 21:24
Do multiple delegates with an array of hashes. Just an idea.
def delegate_with_hash(to, array_of_hashes)
array_of_hashes.each do |h|
methods = Array[h.delete(:methods)]
delegate methods, h.merge(:to => to)
end
end
class ApplicationResponder < ActionController::Responder
def to_json
if has_errors?
display_errors
elsif save? || destroy?
render action: :show
else
super
end