Skip to content

Instantly share code, notes, and snippets.

@misterdai
misterdai / getUploadData.cfm
Created July 1, 2010 12:20
Retrieves upload information without using CFFile
<cfscript>
function getUploadData() {
var local = {};
local.result = {};
if (cgi.request_method Eq 'post') {
local.uploads = form.getPartsArray();
if (StructKeyExists(local, 'uploads')) {
local.count = ArrayLen(local.uploads);
for (local.u = 1; local.u Lte local.count; local.u++) {
local.info = GetFileInfo(form[local.uploads[local.u].getName()]);
@misterdai
misterdai / sessionStop.cfm
Created July 1, 2010 12:22
Stops a Coldfusion session
<cffunction name="sessionStop" output="false">
<cfset var local = StructNew() />
<cfif Not StructKeyExists(application, 'applicationName')>
<cfthrow message="Application.applicationName is missing." />
</cfif>
<cftry>
<cfset local.sid = session.cfid & '_' & session.cftoken />
<cfset local.jTracker = CreateObject('java', 'coldfusion.runtime.SessionTracker') />
<cfset local.jTracker.cleanUp(application.applicationName, local.sid) />
<cfcatch type="any">
@misterdai
misterdai / applicationStop.cfm
Created July 1, 2010 12:24
CF7/8 version of ApplicationStop()
<cffunction name="ApplicationStop" returntype="boolean" output="false">
<cfif IsDefined('application')>
<cftry>
<!--- This is just in case there's no app scope but variables.application --->
<cfset CreateObject('java', 'coldfusion.runtime.ApplicationScopeTracker').cleanUp(application) />
<cfreturn true />
<cfcatch type="any"></cfcatch>
</cftry>
</cfif>
<cfreturn false />
@misterdai
misterdai / applicationRestart.cfm
Created July 1, 2010 12:24
Flag the application to run onApplicationStart
<cffunction name="ApplicationRestart" returntype="boolean" output="false">
<cfif IsDefined('application')>
<cftry>
<!--- This is just in case there's no app scope but variables.application --->
<cfset application.setIsInited(false) />
<cfreturn true />
<cfcatch type="any"></cfcatch>
</cftry>
</cfif>
<cfthrow message="No application scope found." />
<cfcomponent output="false">
<cffunction name="init" access="public" output="false">
<cfscript>
var local = {};
variables.jObject = CreateObject('java', 'some.java.object.with.set.Methods').init();
variables.methods = {};
local.methods = variables.jObject.getClass().getMethods();
local.len = ArrayLen(local.methods);
@misterdai
misterdai / logsessionactivity.cfm
Created February 2, 2012 15:33
Adobe ColdFusion, CFML based file that could be called periodically to log session activity for an application. (AdobeCF only, tested on 8.0.1 should work on 9).
<cfscript>
start = Now();
/*
=== Session Logger ===
== ChangeLog ==
* More config options.
* Supports CREATED, ACCESSED, UPDATED, REMOVED.
* Detects changes in the log keys and redisplays in log if changed.
* Windows newline ending, configurable.
@misterdai
misterdai / redstrap.js
Created April 18, 2012 15:04
Bookmarklet that will redesigns Redmine for Twitter Bootstrap. NOT for permanent usage OR as a theme JS file. Only to promote better theme support (http://www.redmine.org/issues/9754) for consideration.
// Bookmarklet to alter Redmine theme to look like twitter bootstrap
// Only a concept to test the design
// Suggest you minify first (removing comments), before bookmarking
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.7.2",function($,L){
// BEGIN
$(function() {
$('link[rel=stylesheet]').remove();
$('head')
@misterdai
misterdai / filler.js
Created July 31, 2012 14:44
Form filler
$('input[type=text],textarea').each(function() {$(this).val(Math.random().toString(36).substring(3))});
$('select').each(function() {
var el = this;
if (el.multiple) {
$('option', el).each(function() {
this.selected = (Math.random() > 0.5);
});
} else {
@misterdai
misterdai / bookmarklet
Created September 19, 2012 13:59
Bookmarklet do remove blank code lines and turn comments into tooltips.
javascript:(function(){$('.gist .line br').each(function(){if($(this).siblings().length==0){$(this).parent().remove();}});$('.c, .cm, .c1, .cs','.gist').each(function(){var el=$(this);var parent=el.parent();if(el.siblings().length > 0){var comment=parent.attr('data-comment');comment=(typeof comment==='undefined')%3F'':(comment+'\n');parent.attr('data-comment',comment+el.text());el.remove();}else{var nextParent=parent.next();var comment=parent.attr('data-comment');comment=(typeof comment==='undefined')%3F'':(comment+'\n');nextParent.attr('data-comment',comment+el.text());parent.remove();}});$('html > head').append('<style>*[data-comment] {position:relative; background-color:%23dfd;} *[data-comment]:hover {background-color: %23efe;} *[data-comment]:after, *[data-comment]:before {content:""; opacity:0; z-index:999;} *[data-comment]:hover:after, *[data-comment]:focus:after {opacity:0.94; display:block; content:attr(data-comment); position:absolute; bottom:25px; padding:3px; background:%23efe; border:2px solid %23
@misterdai
misterdai / application.cfc
Created November 21, 2012 10:17
Just a test for use within wordpress (oooh that rhymes :P)
<cfcomponent output="false">
<cffunction name="onError">
<cfargument name="exception" required="true" />
<cfargument name="eventName" type="string" required="true" />
<cfif StructKeyExists(arguments.exception, 'rootcause')
And StructKeyExists(arguments.exception.rootCause, 'type')
And arguments.exception.rootCause.type Eq 'coldfusion.runtime.AbortException'>
<!--- CF7: Work around for CfAbort and CfLocation causing this to run --->
<cfreturn />
</cfif>