Getting started with oauth2 for Google

Github Project:

For CommandBox: forgebox install oauth2-Examples

I'm going to focus on how to set up the oauth2 project to work with Google. It's a confusing process if you've never done it before.

If you are new to oauth2, I would first read through the docs on Google.

Let's get started!

Our first step is to create a project using the Google Developers Console.


Intermittent Thread Issue

Update 02/23/2013 - Possible bug with server monitor.
This is now an open unverified bug with the server monitor.
Bug ID: 3498550
Just be aware that threads can behave unexpectedly when all server monitoring is turned on.

I ran into a cfthread issue last weekend, and maybe someone can tell me what is going on. The code listed below usually produces the following output:


HELLO Hello World!

Intermittently I will get the following output:

[empty string]

In the application.log, I get an error "tE65ACFC2-5056-9852-3BC66FCFAEE291C51: null"

I have only been able to recreate the problem with the server monitor turned on. I'm wondering if there is a problem with my code.

view plain print about
2Tested with the following
3CF Version: 9,0,1,274733
4Update Level: hf901-00008.jar --->

6<cfset threads = arrayNew(1)>
7<cfset threadPrefix = createUUID()>
9<cffunction name="addThreadName" returntype="string" access="private" output="false">
10    <cfset var threadName = "t" & variables.threadPrefix & arrayLenn(variables.threads) + 1)>
12    <cfset arrayAppend(variables.threads, threadName)>
13    <cfreturn threadName>
16<cfset variables.mystruct = "">
18<cfthread name="#addThreadName()#" action="run">
19    <cfthread action="sleep" duration="100" />
20    <cfset variables.mystruct = structNew()>
21    <cfset variables.mystruct.hello = "Hello World!">
24<cfthread name="#addThreadName()#" action="run">
27<cfthread name="#addThreadName()#" action="run">
30<cfthread name="#addThreadName()#" action="run">
33<cfloop array="#variables.threads#" index="i">
34    <cfoutput>#i#</cfoutput><br />
35 <cfthread action="join" name="#trim(i)#" timeout="2000" / >
38<cfdump var="#mystruct#" >

Mapping an RGB color to the nearest palette color in ColdFusion

RGB colors in 3d space graph

I ran into a need to map an RGB value to a palette color the last time I worked with the Google calendar API. I kept getting errors back when creating new calendars, and realized that I needed to pass a hex color that was in a defined palette. This left me with fewer options for the end-user, as I would now have to present them with a list of valid colors. I could avoid some type of palette chooser by mapping a given RGB value to the nearest Google color. In my situation an exact color match was not necessary.

Last week I posted an article with a function that would return the 17 CSS 2.1 colors. The code for the function was simple, but I needed it for this article. I actually thought about being cruel and writing the function to return the web safe color palette.

Mapping an RGB value to a palette color is a problem of finding the palette color that is the nearest in distance to a given RGB value. We can visualize this as shown on the left by plotting each palette color in 3d space using each color component as an axis.

We can get the Euclidean distance between two points by using the formula shown below that returns the distance between points P and Q.

$$ d(p,q) = \sqrt{(p_r - q_r)^2 + (p_g - q_g)^2 + (p_b - q_b)^2} $$


Is it finally time to embrace cfscript?

william eatman contemplating change

I feel like I've been a long hold out for not moving to cfscript. Sure I've used it, but I've always been a fan of the tag markup. My rationale has been that the tag language could do things that cfscript could not. I've never bought into the argument that cfscript would save me time, as time programming is usually spent problem solving and not actually typing the code.

Over the past week I have been looking at new open source CF projects and can see that many have embraced cfscript, so much so that my guess is that CF 9 will age much faster than CF 8 did. CF 10 does a good job filling in the holes cfscript had as well as adding advanced features like closures. In fact, it looks like I can now do more with cfscript than the tag markup. Maybe cfscript has grown up?

CSS 2.1 color palette function for ColdFusion

Yesterday I wrote a simple function for an upcoming post on working with defined color palettes. The palette of CSS 2.1 colors is small and useful for examples and could also be useful for form validation of a color field.

The following table was easily generated using GetCSS21Colors and HexToRGB from my previous post.

Name Color Hex RGB
#0000FF (0, 0, 255)
#FFFFFF (255, 255, 255)
#FF00FF (255, 0, 255)
#800000 (128, 0, 0)
#008000 (0, 128, 0)
#00FFFF (0, 255, 255)
#808000 (128, 128, 0)
#000080 (0, 0, 128)
#C0C0C0 (192, 192, 192)
#FFFF00 (255, 255, 0)
#000000 (0, 0, 0)
#00FF00 (0, 255, 0)
#FFA500 (255, 165, 0)
#800080 (128, 0, 128)
#FF0000 (255, 0, 0)
#808080 (128, 128, 128)
view plain print about
1<cfset qColors = getCSS21Colors(resultType: 'query')>
3 <thead>
4 <th>Name</th>
5 <th>Color</th>
6 <th>Hex</th>
7 <th>RGB</th>
8 </thead>
9 <cfoutput query="qColors">
10 <cfset myrgb = HexToRGB(color)>
11 <tr>
12 <td>#name#</td>
13 <td><div style="background: #color#; height: 20px; width: 100px;"></div></td>
14 <td>#color#</td>
15 <td>
16 (#myrgb.r#,#myrgb.g#,#myrgb.b#)</td>
17 </tr>
18 </cfoutput>


Fast Hex to RGB function for ColdFusion

Over Christmas I started working on a ColdFusion image library and wrote a nice hex to RGB function. I used a few tricks to make it as fast as possible. I'll write more about some of the optimizations in the coming week. Let me know if you can identify a way to make it even faster.

view plain print about
view plain print about
view plain print about
1c<ffucnfcftuioncctfifounn cntaimone =nn anamem=e="HexToRGB" "aHcecxeTsoRsG=B""p uablic" outp"HuextcTc=oe"RsfGsaBl"s ea" crc=ee"tspusru=n"btplypei="cs"turbulcitc"" hint="h eox utto sptruutc=t" fra,lgs,e"b ,ar"e>t
2u    orntype="struct" hint="hex to struct r,g,b,a">

2    <<cfacrfargguummeuentnt pt unta=m"fe=a"lhseenxa"m et=y"phee=x""string" required="true" hint="3 or 6 digit hex value (valid examp tlyepse=:" s#t#riFnFgF", Fr"FF ,r e#t#uFrFneFtqFyuFpiFer,e= d"F=sF"tFtrFruFucFte)""" hint="hex to st >r
3hu icntt =r ",3g ,obr ,6a ">
2    ig <
4i t c hfe<axr vcfseta lue va(gr uvmraeelntitVd aln eam=x ea=mstructNew"phl(ee)xs>"
5: # t #yFp<FeF=cfset", s vtaFFrF , i# #=F F0F>F
6F F , FF<FFFF)"

4 <cfset var retcfsetV alv ar= structNewo (= )>

7r i <cfset var offset = n0g>
9r    eq<ui!r-e-d-= "cthreuaper in tie" hinmte= "t3o o rlo o6k dfoir gai tle ahdeinx gv a'l#u'e (avnad lsied te xaanm p ol efsf:<s ecfset#t # vFtaFhFr, a inF F=bF ,u 0r#n>
#6aF FcFaFlFlF t,o FFFFFF)">
4 < cfset var< cfsetr evtaVra lo == s0tr>
7u c t Ne<wcfset( )va>
5r o f fs et< cfset= 0va>r
9     i =< !0->-
6- c he<apcfsete rv airn ot i=m e0 t>
7o l o ok< fcfseto rv aar l eoafdfisnegt '=# '0 >a
n9d     s<e!t- -a-n cohfeafpseert itnh atni mbeu rtno lao ock aflolr tao lreeam orveemCohvaers --->
10    <cfif mid(arguments.hex, 1, 1) EQ chr(35)>
11     <cfset offset = 1>

12 <C/hcdfiinfg>
13 '
14'     an<d! -s-e-t Raenm oovfef sneotn -thheaxn valauress .- - - b>
u10r    n <a ccaflilf tmoi dr(eamrogvuemCehnatrss. h-e-x-,>
101    , <1) cEQf icfh rm(i3d(5a)r>
g11 u me n t    s.<hecfsetx ,o f1f,s e1t) =E Q1 >
12h r( 3 5 )>t
11h< e f/oclflio fw >i
    13n g< i cfset
14s      off<af!sst-e-et-r = R te1hma>o
12vn e r negoenx< ---h-/ecx>

f15 i f v

13a     l < u
14e    csf<l.!o- o-p - ftRrehommeo=v" e#f 1n oo+n l-olhfefoxs wevtia#l"nu gets o.=i " s#tl heefn (faoasrlgtluoemwerinn tgts h.ahiensx )fr#a"es tigenedre xxt= h"ai-n"- -r>

e15 x - -     -    <>
15< c f    clofoi<pf ffcirfnoldmo(=om"
pi# d1f( ra+or mgo=uf"m#ef1n st+s e.ohftefx#s,e" ti #"t+ oto,o= =1"")#,#l le'en0n(1(a2ar3r4gg5uu6m7mee8nnt9tsAs.B.hCheDexEx)F)#a#"b" ciidnneddfe'ex)x= "=Ei"Q"i>

" >
17      <     c<f16 icfsetf findar ( g midu m(    en<atrsg.ucmfhieefn txs find.(=h mideremoveChars(x(, araigr ugm+u emnoet, nst.1sh.)ehx,e ,'x 0,i1 2i+ 3 +4 5o6,7 819)A>B
18CDEFoabc d e f '
,)     E1Q)< ,cfset0 > '
17o0 =12 3o 4 5 -6 7 18 9>
19A B C     D     <cfset< arg/ucmfeintfs>
20h e x = r<emo/vceEfCFlhoaaorbps>
22a r g u me<nts.chfeixf, lein (+a rog, u1m)e>n
18t s . h e x ) E    Q (<3 +ccfsetd eooff 'f)= EQo s e-0t

17)1 >
19          <<<cfset/cfset acrrfegiutfV>a
20 l . r m=e <nItns/p.cuhfteBxa s=e Nrl(eommoiopd>v
22e aC rh gaurm<senctfsi(.fh elaexrng(,ua rm1g eu+n mtoesfn.fthssee.xth,, e xi1 )) + &E oQm , (i1d3 )(>+
a18 r o g fu f m s ee n    tt)s<>
23.cfset h e xo , <1=cfset +r eoot fVfas-le .t,r 1= )InputBaseN, (mid1(16>a
19)r >

24 g u      m e <n ts</.ccfset fherext,Va li1. f>+
20g o f= f s<eItn/, cp1f)lu o& otmp>Bi
22d a( as re<gNu(mcmiefdin(aftr sgl.uehmnee(xna,tr sg1.u hm+ee nxot,f fss2.e +h toe,fx f)s 1eEQt) ,( ,31 )+ &1o fm6fisd)(ea>tr

23 u m e n t s . h <excfset , r<2 ecfset +t roVeftfasVelatl, ..1gr ) ,= = 1InputBaseNInputBaseN(6(mid)(mid>
25a( ra g r u mgeunmtesn.hex t,s .hex1 , <cfset + roe ftfV2s aelt+., bo 1f=f) s&eInputBaseN t(mid,mid ((1ara)gr ug& muemnmidetn(,mx e,1n t+ s3 .of+h fesoxef,tf ,s 2e 1t,)+ ,1 of)1 f&6 se)mid>t
24(, a 1r )g ,u m1e6<n)cfsett>
25s r .e h te V xa ,l .<3g cfset += r eoInputBaseNtf(Vfasmidle(.ta,b r g1=u m)eInputBaseN,n( tmids1.(6hae)r>xg , u m 2
26e n+ t osf.<fhseecxtf,, e 3l1 s)+ e &> o m f if d s (e at
27r, g 1u m) e& n tm<si.cfsetd (hreaexrt,g Vua2m le.n+ tr so.f= fhseInputBaseNex(t, ,mid 3(1 a)+r g, oufm1fes6net)ts>
25,. h 1 e) x, , 1 16 <)>cfset + r
26oe ft Vf as<le.t,b c f2=e l)sInputBaseN,e( >
m1 i6 d) >
28 a
27 r g u m e n <tcfset<s cfset. rhreeextt,V Vaal3l ..+gr o==f fInputBaseNsInputBaseNe((tmid,mid ((1aar)r g&gu ummidemne(tnast.rsg.huemhxee,n xt,1 s .3+ he+ox ffosfef,ts ,e 3t 2, +) 2,o )f1f,s6 e)1t>
28,6 )1 >

29) , 1 6< )cfset> r< e
cfset26t V ar le.<tVg acl=f .eInputBaseNlb (semid=> ( Ia n r pg u u
t27m Be an ts s e .N h(e<mxcfseti, d(3 a+r goufmfesnetts, .2rhe)etx, V, a1l56. )r+>
29 =o f I fn s pet<u,cfset t 2Bre)atVs, ael1.N6b ()>m
30 i d (a<rgu/cmefnitf>s
31 . h
32e x , 1 <+cfset = orInputBaseNfe(ftsVmidea(tla,. rag2 um)=e n,2t s5.15h>6
33e    )
28 5 +< o fc ffs<recfsetet t, urr2en)t V,r ael1t.V6ag )l>>
35 I <n<p/u/cctfffiBfu>a
31n s c et
32i N o ( nm>