Skip to content

Instantly share code, notes, and snippets.

@Macagare
Macagare / gist:3999349
Created November 2, 2012 07:51
Coldfusion: paypal api
<!-- read post from PayPal system and add 'cmd' -->
<CFSET str="cmd=_notify-validate">
<CFLOOP INDEX="TheField" list="#Form.FieldNames#">
<CFSET str = str & "&#LCase(TheField)#=#URLEncodedFormat(Form[TheField])#">
</CFLOOP>
<CFIF IsDefined("FORM.payment_date")>
<CFSET str = str & "&payment_date=#URLEncodedFormat(Form.payment_date)#">
</CFIF>
<CFIF IsDefined("FORM.subscr_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.subscr_date)#">
@Macagare
Macagare / compareTables.sql
Created April 3, 2017 11:19
compare two table for missing ids
SELECT table1.ID
FROM table1
LEFT OUTER JOIN table2 ON table1.ID = table2.ID
WHERE table2.ID IS NULL
@Macagare
Macagare / gist:4502095
Created January 10, 2013 13:40
JavaScript: Limit the number of characters in a textarea
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Code source: http://www.devcurry.com/2009/08/limit-number-of-characters-in-textarea.html THANKS -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Limit Number of Characters in a TextArea</title>
<script type='text/javascript'
src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
@Macagare
Macagare / normalize.cfm
Last active December 25, 2015 06:49
normalize query string for query of queries
<cffunction name="normalizeChar" returntype="string" hint="Replaces characters with their non accented closest equivalents" output="true">
<cfargument name="str" type="string" required="true" />
<cfreturn ReplaceList( str,"á,é,í,ó,ú,ý,à,è,ì,ò,ù,â,ê,î,ô,û,ã,ñ,õ,ä,ë,ï,ö,ü,ÿ,À,È,Ì,Ò,Ù,Á,É,Í,Ó,Ú,Ý,Â,Ê,Î,Ô,Û,Ã,Ñ,Õ,Ä,Ë,Ï,Ö,Ü",
"a,e,i,o,y,u,a,e,i,o,u,a,e,i,o,u,a,n,o,a,e,i,o,u,y,A,E,I,O,U,A,E,I,O,U,Y,A,E,I,O,U,A,N,O,A,E,I,O,U") />
</cffunction>
<cffunction name="normalizeColumn" returntype="query" output="true" hint="normalize single column and add new column [column]_norm">
<cfargument name="qSource" type="query" required="true" />
<cfargument name="column" type="string" required="true" />
<cfset var normColumn = arguments.column & "_norm" />
@Macagare
Macagare / gist:6884565
Created October 8, 2013 13:23
coldfusion structAppend2, adds value to a new created key
void function structAppend2(required struct base, required string key, required any value) {
var paramStruct = {};
paramStruct[arguments.key] = arguments.value;
structAppend(arguments.base,paramStruct);
}
@Macagare
Macagare / gist:6883387
Last active December 24, 2015 23:49
cfscript version of query to map conversion made for railo
/**
* converts query to sturct map
*
* @param query source query to convert
* @param string key key for the main subkeys, when empty first column taken
* @return struct converted map
*
*/
struct function toMap( required query source, required string key, string ignore="" ) {
var map = {};
@Macagare
Macagare / gist:6883249
Created October 8, 2013 11:23
cfscript implementation convert query to structs array. created in railo
/**
* Converts a coldfusion query into a coldfusion struct
*
* @param required query source query to convert
* @return struct converted query as a array with structs
*/
array function toStruct( required query source) output="true" {
var arrResult = arraynew(1);
var cols = ListtoArray(arguments.source.columnlist);
var row = 1;
@Macagare
Macagare / gist:6854209
Created October 6, 2013 13:39
load xml via ruby Net:HTTP and write into local file
require 'net/http'
def load_file(f_url)
load_content( URI.parse(f_url) )
end
def load_content(uri)
resp = Net::HTTP.get_response(uri)
raise unless resp.code == "200"
write_file( get_filename(uri.to_s), resp.body)
@Macagare
Macagare / gist:6765315
Last active December 24, 2015 07:39
cfhttp head - Check if url is returning any response. Prevent freezing of website. like ping in coldfusion
<!---
Does a URL exist? Checks that host exists and for
404 status code.
http://www.forta.com/blog/index.cfm?mode=day&day=2&month=1&year=2006
--->
<cffunction name="urlExists" output="no" returntype="boolean">
<!--- Accepts a URL --->
<cfargument name="u" type="string" required="yes">
<!--- Attempt to retrieve the URL --->
@Macagare
Macagare / gist:6683334
Created September 24, 2013 11:20
HTML5 video tag with fallback source: http://camendesign.com/code/video_for_everybody
<video width="640" height="360" controls>
<source src="__VIDEO__.MP4" type="video/mp4" />
<source src="__VIDEO__.OGV" type="video/ogg" />
<object width="640" height="360" type="application/x-shockwave-flash" data="__FLASH__.SWF">
<param name="movie" value="__FLASH__.SWF" />
<param name="flashvars" value="controlbar=over&amp;image=__POSTER__.JPG&amp;file=__VIDEO__.MP4" />
<img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__"
title="No video playback capabilities, please download the video below" />
</object>
</video>