tag:blogger.com,1999:blog-59578623465145730372024-03-12T20:35:46.723-07:00CFELEMENTS - Elements of DevelopmentColdfusion · MySQL · JavaScript · RandomnessUnknownnoreply@blogger.comBlogger71125tag:blogger.com,1999:blog-5957862346514573037.post-25351204439516522352016-02-16T22:48:00.001-08:002016-02-16T22:48:29.381-08:00Grunt: sass, scss, autoprefixer, cssmin, and watch Notes with Sample Files<div dir="ltr"><div><div><div><div><div><div>Example Gruntfile.js<br><br><span style="font-family:monospace,monospace">module.exports = function(grunt) {<br> 'use strict'<br><br> var processdate = (new Date).toString();<br><br> grunt.initConfig({<br> pkg: grunt.file.readJSON('package.json'),<br><br> //Watch objects<br> //----------------------------------<br> watch: {<br> scripts: {<br> files: ['scss/**/*.scss'],<br> tasks: ['sass','autoprefixer','cssmin'],<br> options: {<br> interval: 500,<br> spawn: false<br> }<br> }<br> },<br><br> sass: {<br> options: {<br> includePaths: require('node-bourbon').includePaths,<br> outputStyle: 'nested', // Values: 'nested', 'compressed'<br> precision: 3,<br> sourceMap: true, // Without this being true the resulting map file isn't linked at the bottom of the generated .css file<br> sourceMapEmbed: false,<br> sourceComments: false<br> },<br> dist: {<br> files: {<br> 'global.css': ['scss/master.scss']<br> }<br> }<br> },<br><br> //Plugins<br> //----------------------------------<br> autoprefixer: {<br> options: {<br> browsers: ['last 2 versions'],<br> cascade: false,<br> map: {<br> prev: false,<br> inline: false,<br> annotation: false,<br> sourcesContent: false<br> }<br> },<br> multiple_files: {<br> src: 'global.css',<br> dest: 'global.css'<br> }<br> },<br><br> cssmin: {<br> add_banner: {<br> options: {<br> banner: '/* Author: **Your Name\n * Created: 2016-02-16\n * Last Updated: '+processdate+'\n */'<br> },<br> files: {<br> 'global.min.css': ['global.css']<br> }<br> }<br> }<br><br> });<br><br><br> //Load NPM Tasks<br> //----------------------------------<br> grunt.loadNpmTasks ('grunt-contrib-watch');<br> grunt.loadNpmTasks ('grunt-sass');<br> grunt.loadNpmTasks ('grunt-autoprefixer');<br> grunt.loadNpmTasks ('grunt-contrib-cssmin');<br><br><br> grunt.registerTask('default', ['sass','autoprefixer','cssmin']);<br> grunt.registerTask('c', ['sass']); // c=compile<br> grunt.registerTask('w', ['watch']);<br><br>};<br><br><br></span></div><div>Example package.json:<br></div><br><span style="font-family:monospace,monospace">{<br> "name": "grunt",<br> "version": "0.1.1",<br> "private": true,<br> "devDependencies": {<br> "grunt": "latest",<br> "grunt-autoprefixer": "latest",<br> "grunt-contrib-cssmin": "latest",<br> "grunt-contrib-watch": "latest",<br> "grunt-sass": "latest",<br> "node-bourbon": "latest"<br> }<br>}<br></span><br><span style="font-family:monospace,monospace"><br></span><div>Example master.scss:<br></div><br><span style="font-family:monospace,monospace">// Manually list all files to be included in specific order, skip .scss extensions<br>@import "./fonts";<br>@import "./variables";<br>@import "./base";<br>@import "./layout";<br>@import "./partials";<br>@import "./global";<br></span><br><br></div>And then command line:<br><br></div><span style="font-family:monospace,monospace">$ npm update<br>$ npm install<br>$ grunt<br>$ grunt w</span><br></div></div></div><div><div><div><div><div><div><div><br><br>That's it.<br></div><div><div><br></div></div></div></div></div></div></div></div></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-14770529679824996072016-02-16T21:57:00.001-08:002016-02-16T21:57:58.931-08:00Better JS functions than previous attempts at similar functionality<div dir="ltr">Some code notes for later reference:<br><br><br>A better number formatting function:<br><span style="font-family:monospace,monospace"> function toDecimal (number) { // CREDITS: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString</a><br> return number.toLocaleString("en-US",{ style: 'decimal', minimumIntegerDigits: 1, maximumFractionDigits: 2, minimumFractionDigits: 2 });<br> };</span><br><br><br>A better currency format function:<br><span style="font-family:monospace,monospace"> function toDollar (number) { // CREDITS: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString</a><br> return number.toLocaleString("en-US",{ style: 'currency', currency: 'USD' });<br> };</span><br><br><br>I've always wanted a good one of these:<br><span style="font-family:monospace,monospace"> function guid () { // CREDITS: <a href="http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript">http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript</a><br> function s4() {<br> return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);<br> }<br> return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();<br> };</span><br><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-59991839764486095272016-01-23T16:50:00.001-08:002016-02-27T11:41:07.966-08:00Native HTML5 Ternary Checkbox - With Labels!<div dir="ltr">
<div>
<b>I worked through creating a html ternary checkbox (a checkbox with a tertiary option) this morning - with labels! Woohoo!</b><br />
<br />
Now that we can create a third option we need to tell the user what it means, so we probably need labels.<br />
<br /></div>
<div>
Here are some images of the results on-screen:<br />
<br />
<a href="http://1.bp.blogspot.com/-HVeTymkOgqU/VqQfvTP9FBI/AAAAAAAAAUE/UTGjqrylGJE/s1600/image-705815.png"><img alt="" border="0" id="BLOGGER_PHOTO_ID_6243149880923853842" src="https://1.bp.blogspot.com/-HVeTymkOgqU/VqQfvTP9FBI/AAAAAAAAAUE/UTGjqrylGJE/s320/image-705815.png" /></a></div>
<div>
<a href="http://3.bp.blogspot.com/-8Xp2z5hYLA0/VqQfvuN6ZEI/AAAAAAAAAUM/HfolwdDoxXw/s1600/image-706892.png"><img alt="" border="0" id="BLOGGER_PHOTO_ID_6243149888163046466" src="https://3.bp.blogspot.com/-8Xp2z5hYLA0/VqQfvuN6ZEI/AAAAAAAAAUM/HfolwdDoxXw/s320/image-706892.png" /></a><br />
<a href="http://2.bp.blogspot.com/-14wveHqfI60/VqQfv5VUDoI/AAAAAAAAAUU/Sa1pejljJlo/s1600/image-707664.png"><img alt="" border="0" id="BLOGGER_PHOTO_ID_6243149891146878594" src="https://2.bp.blogspot.com/-14wveHqfI60/VqQfv5VUDoI/AAAAAAAAAUU/Sa1pejljJlo/s320/image-707664.png" /></a><br />
<br />
<br /></div>
<div>
Given a checkbox like this:<br />
<br />
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204 , 204 , 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
<span style="font-family: monospace , monospace;"><input id="example" name="example" type="checkbox" class="ternaryCheckbox" value="1" /></span></blockquote>
</div>
<div>
<br /></div>
<div>
We can use the default 'Yes', 'No', 'All' options with this HTML:</div>
<div>
<br />
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204 , 204 , 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
<span style="font-family: monospace , monospace;"></span><span style="font-family: monospace , monospace;"> <input id="example" name="example" type="checkbox" class="ternaryCheckbox" value="1" /></span><br />
<span style="font-family: monospace , monospace;"><span class="ternaryLabelsYesNoAll"></span></span></blockquote>
<br /></div>
<div>
<br />
OR, use custom labels:</div>
<div>
<br />
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204 , 204 , 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
<span style="font-family: monospace , monospace;"></span><span style="font-family: monospace , monospace;"> Show Archived: <input id="example" name="example" type="checkbox" class="ternaryCheckbox" value="1" /></span><br />
<span style="font-family: monospace , monospace;"><span class="ternary-option checked">Active Only</span><br /><span class="ternary-option unchecked">Archived Only</span><br /><span class="ternary-option alternate">All Records</span></span></blockquote>
<br />
<br /></div>
<div>
We add this JS to attach the handler and the function to run the ternary checkbox:<br />
<br />
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204 , 204 , 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
<span style="font-family: monospace , monospace;">$(document).ready(function(){<br /> $(":checkbox.ternaryCheckbox").on("click",ternaryCheckbox);<br />});<br /><br />function ternaryCheckbox(e){<br /> var $t = $(this),<br /> that = this,<br /> originalVal = $t.val(),<br /> checkedVal = originalVal,<br /> alternateVal = ($t.data("ternary") != undefined ? $t.data("ternary") : 2);<br /> // This should only be undefined the first time to cache the original value<br /> if ($t.data("primary") == undefined) {<br /> $t.data("primary",checkedVal);<br /> } else {<br /> checkedVal = $t.data("primary");<br /> }<br /> // if 'un-checking', and NOT in tern state, go to tern state, else normal checked or unchecked<br /> if($t.prop("checked")==false && $t.prop("indeterminate")==false && originalVal!=alternateVal) {<br /> $t.val(alternateVal);<br /> $t.prop("checked",true);<br /> $t.prop("indeterminate",true);<br /> } else {<br /> $t.val(checkedVal);<br /> $t.prop("indeterminate",false);<br /> }<br />};</span></blockquote>
</div>
<div>
<br />
<br /></div>
Here is the Raw CSS:<br />
<br />
<div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204 , 204 , 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox ~ .ternaryLabelsYesNoAll</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">inline-block</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">font-weight</span><span class="">: </span><span class="">100</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">margin-right</span><span class="">: </span><span class="">21px</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">position</span><span class="">: </span><span class="">relative</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">width</span><span class="">: </span><span class="">1px</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox ~ .ternaryLabelsYesNoAll:after</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">content</span><span class="">: </span><span class="">"No"</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">inline-block</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox:checked ~ .ternaryLabelsYesNoAll:after</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">content</span><span class="">: </span><span class="">"Yes"</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox:indeterminate ~ .ternaryLabelsYesNoAll:after</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">content</span><span class="">: </span><span class="">"All"</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}<br /><br /></span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox ~ .ternary-option</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">inline-block</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">font-weight</span><span class="">: </span><span class="">100</span><span class="">;</span></span></div>
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">min-width</span><span class="">: </span><span class="">22px</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox ~ .ternary-option.alternate, .ternaryCheckbox ~ .ternary-option.checked</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">none</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox:checked ~ .ternary-option.checked</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">inline-block</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox:indeterminate ~ .ternary-option.checked, .ternaryCheckbox:checked ~ .ternary-option.alternate, .ternaryCheckbox:checked ~ .ternary-option.unchecked</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">none</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class="">.ternaryCheckbox:indeterminate ~ .ternary-option.alternate</span> {</span></div>
<div class=" ">
<div class="">
<div class="">
<span style="font-family: monospace , monospace;"><span class=""> </span><span class="">display</span><span class="">: </span><span class="">inline-block</span><span class="">;</span></span></div>
</div>
</div>
<div class="">
<span style="font-family: monospace , monospace;">}</span></div>
</div>
</blockquote>
<br />
<br />
<br />
Here is the Sass CSS:<br />
<br />
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204 , 204 , 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
<span style="font-family: monospace , monospace;">/* Ternary Checkbox and Option Labels */</span><br />
<span style="font-family: monospace , monospace;"></span><br />
<span style="font-family: monospace , monospace;">/* Using default 'No', 'Yes', 'All' default labels:</span><br />
<span style="font-family: monospace , monospace;"> <input id="example" name="example" type="checkbox" class="ternaryCheckbox" value="1"<? if (local.example != 0)> checked</?><? if (local.example == 2)> indeterminate</?> /></span><br />
<span style="font-family: monospace , monospace;"> <span class="ternaryLabelsYesNoAll"></span></span><br />
<span style="font-family: monospace , monospace;"> // Nothing else is needed, CSS does the rest.</span><br />
<span style="font-family: monospace , monospace;">*/</span><br />
<span style="font-family: monospace , monospace;">.ternaryCheckbox {</span><br />
<span style="font-family: monospace , monospace;"> ~ .ternaryLabelsYesNoAll {</span><br />
<span style="font-family: monospace , monospace;"> display: inline-block;</span><br />
<span style="font-family: monospace , monospace;"> font-weight: 100;</span><br />
<span style="font-family: monospace , monospace;"> margin-right: 21px;</span><br />
<span style="font-family: monospace , monospace;"> position: relative;</span><br />
<span style="font-family: monospace , monospace;"> width: 1px;</span><br />
<span style="font-family: monospace , monospace;"> &:after {</span><br />
<span style="font-family: monospace , monospace;"> content: 'No';</span><br />
<span style="font-family: monospace , monospace;"> display: inline-block;</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> &:checked {</span><br />
<span style="font-family: monospace , monospace;"> ~ .ternaryLabelsYesNoAll:after {</span><br />
<span style="font-family: monospace , monospace;"> content: 'Yes';</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> &:indeterminate ~ .ternaryLabelsYesNoAll:after {</span><br />
<span style="font-family: monospace , monospace;"> content: 'All';</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;">}<br /><br /></span><br />
<span style="font-family: monospace , monospace;">/* Using custom ternary labels:</span><br />
<span style="font-family: monospace , monospace;"> <input id="example" name="example" type="checkbox" class="ternaryCheckbox" value="1"<? if (local.example != 0)> checked</?><? if (local.example == 2)> indeterminate</?> /></span><br />
<span style="font-family: monospace , monospace;"> <span class="ternary-option checked">Checked</span></span><br />
<span style="font-family: monospace , monospace;"> <span class="ternary-option unchecked">Unchecked</span></span><br />
<span style="font-family: monospace , monospace;"> <span class="ternary-option alternate">Alternate</span></span><br />
<span style="font-family: monospace , monospace;">*/</span><br />
<span style="font-family: monospace , monospace;">.ternaryCheckbox {</span><br />
<span style="font-family: monospace , monospace;"> ~ .ternary-option {</span><br />
<span style="font-family: monospace , monospace;"> display: inline-block;</span><br />
<span style="font-family: monospace , monospace;"> font-weight: 100;</span><br />
<span style="font-family: monospace , monospace;"> min-width: 22px; /* Override this if longer values are being used, inline style is fine */</span><br />
<span style="font-family: monospace , monospace;"> &.checked,</span><br />
<span style="font-family: monospace , monospace;"> &.alternate {</span><br />
<span style="font-family: monospace , monospace;"> display: none;</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> &:checked {</span><br />
<span style="font-family: monospace , monospace;"> ~ .ternary-option.checked {</span><br />
<span style="font-family: monospace , monospace;"> display: inline-block;</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> ~ .ternary-option {</span><br />
<span style="font-family: monospace , monospace;"> &.unchecked,</span><br />
<span style="font-family: monospace , monospace;"> &.alternate {</span><br />
<span style="font-family: monospace , monospace;"> display: none;</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> &:indeterminate ~ .ternary-option {</span><br />
<span style="font-family: monospace , monospace;"> &.checked {</span><br />
<span style="font-family: monospace , monospace;"> display: none;</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> &.alternate {</span><br />
<span style="font-family: monospace , monospace;"> display: inline-block;</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;"> }</span><br />
<span style="font-family: monospace , monospace;">}</span></blockquote>
<br /></div>
<div>
-GBuilt<br />
<br /></div>
<div>
[This solution is completely open source, absolutly free to use without any restriction. Please give creative to this blog post URL.</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-4216143569633076402016-01-09T09:13:00.001-08:002016-01-09T10:25:21.602-08:00Setting up a new NodeJS Server<div dir="ltr">
<div>
<div>
<span style="font-family: monospace,monospace; font-size: small;">The following is on Ubuntu, you may have slightly different default location or bash script names to edit on different Linux disros.</span><br />
<br />
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<span style="font-family: monospace,monospace; font-size: small;">Install Node Version Manager (NVM):</span><br />
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">Follow: <a href="https://github.com/creationix/nvm">https://github.com/creationix/nvm</a> and <a href="http://www.liquidweb.com/kb/how-to-install-nvm-node-version-manager-for-node-js-on-ubuntu-14-04-lts/">http://www.liquidweb.com/kb/how-to-install-nvm-node-version-manager-for-node-js-on-ubuntu-14-04-lts/</a></span><br />
<br />
<span style="font-family: monospace,monospace; font-size: small;">1. Install NVM</span><br />
<span style="font-family: monospace,monospace; font-size: small;"></span><br />
<span style="font-family: monospace,monospace; font-size: small;"></span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">First make sure the prerequisites are ready:</span><br />
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ sudo </span><span style="font-size: small;"><span style="font-family: monospace,monospace;">apt-get update</span></span><br />
<span style="font-size: small;"><span style="font-family: monospace,monospace;">$ sudo apt-get install build-essential libssl-dev</span></span><br />
<span style="font-family: monospace,monospace; font-size: small;"></span></div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"> </span></div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">Now for the actual install command:</span></div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"> </span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">$ curl -o- <a href="https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh">https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh</a> | bash</span> </span><br />
<br />
<br />
<span style="font-family: monospace,monospace; font-size: small;">Then I did some additional moving around. It automatically puts things in the users folder. I wanted them globally:</span><br />
</div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">$ sudo mkdir <b>/etc/nvm</b></span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">$ sudo mv ~/.nvm/<span style="font-family: monospace,monospace;">*</span> /etc/nvm/</span><br />
</div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">Then change the initialization so it's for all users:</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ sudo vim /etc/bash.bashrc</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">Add this to the bottom:<br />export NVM_DIR="<b>/etc/nvm</b>"<br />[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm</span></div>
</div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"></span></div>
</div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">Then remove/comment-out the old script location in your user bash:</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ vim ~/.bashrc</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">Remove or comment-out these two lines - should be at the very bottom:<br />#export NVM_DIR="/home/ubuntu/.nvm"<br />#[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm</span></div>
</div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"></span></div>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
</div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">2. Logout and log back in again, then test if it's working:</span></div>
<div style="margin-left: 80px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ nvm [enter]</span><br />
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">That should return a list of possible commands + options for using NVM, like this [truncated]:<br /><br /><br />Node Version Manager<br /><br />Note: <version> refers to any version-like string nvm understands. This includes:<br /> - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)<br /> - default (built-in) aliases: node, stable, unstable, iojs, system<br /> - custom aliases you define with `nvm alias foo`<br /><br />Usage:<br /> nvm help Show this message<br /> nvm --version Print out the latest released version of nvm<br /> nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available<br />...<br />...<br />...</version></version></version></span></div>
</div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"></span></div>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
</div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">3. Now install the latest stable version of node:</span></div>
<div style="margin-left: 80px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ nvm install stable</span></div>
<div style="margin-left: 80px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">Then check the install:</span></div>
<div style="margin-left: 80px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ nvm ls</span></div>
<div style="margin-left: 80px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">That should display something like this:</span></div>
</div>
<div style="margin-left: 80px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">-</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0<br />node -</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> stable (-</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0) (default)<br />stable -</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> 5.4 (-</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0) (default)<br />iojs -</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> N/A (default)</span></div>
</div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">4. Then set the default engine so it works forever (not sure why this isn't set my default if not set):</span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ nvm alias default stable</span></div>
</div>
<div style="margin-left: 80px;">
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<div style="margin-left: 80px;">
<span style="font-family: monospace,monospace; font-size: small;">Check it:</span></div>
<div style="margin-left: 80px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ nvm ls</span><br />
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">That should display something like this:</span></div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">-</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0<br /><b>default -</b></span><span style="font-family: monospace,monospace; font-size: small;"><b><span style="font-family: monospace,monospace; font-size: small;">></span> stable (-</b></span><span style="font-family: monospace,monospace; font-size: small;"><b><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0)</b><br />node -</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> stable (-</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0) (default)<br />stable -</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> 5.4 (-</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> v5.4.0) (default)<br />iojs -</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> N/A (default)</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
</div>
</div>
<span style="font-family: monospace,monospace; font-size: small;"></span><br />
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"></span></div>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<span style="font-family: monospace,monospace; font-size: small;">Install Git:</span><br />
<br />
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">1. Command line with apt-get:</span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ sudo apt-get install git</span></div>
</div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">2. Now make the command prompt show the current branch name whenever you are in a git repo directory:</span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ sudo vim /etc/profile</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">Then add the following to the end of the file:<br /><br />#Show the Current GIT Branch -- if GIT is initialized<br />function parse_git_branch {<br /> git branch --no-color 2</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'<br />}<br />function proml {<br /> local BLUE="\[\033[0;34m\]"<br /> local RED="\[\033[0;31m\]"<br /> local LIGHT_RED="\[\033[1;31m\]"<br /> local GREEN="\[\033[0;32m\]"<br /> local LIGHT_GREEN="\[\033[1;32m\]"<br /> local WHITE="\[\033[1;37m\]"<br /> local LIGHT_GRAY="\[\033[0;37m\]"<br /><br /> PS1="\u@\h \$(date +%b%d@%I:%M:%S%p) \w$RED\$(parse_git_branch)$GREEN\$ "<br /> PS2='</span><span style="font-family: monospace,monospace; font-size: small;"><span style="font-family: monospace,monospace; font-size: small;">></span> '<br /> PS4='+ '<br />}<br />proml<br /><br />mesg n</span></div>
</div>
<div>
<div>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<div>
<span style="font-family: monospace,monospace; font-size: small;">Set up your nodejs website:</span><br />
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">1. Make the /var/www/ web directory with proper owners and permissions</span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ cd /var</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">$ sudo mkdir www</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">$ sudo chown -R [your-username]:[your-username] www</span></div>
</div>
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">2. Create a folder for each website:</span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ mkdir [website-name]</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">$ cd [website-name]</span></div>
</div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
</div>
<div style="margin-left: 40px;">
<span style="font-family: monospace,monospace; font-size: small;">3. Clone your git repo into the current directory (don't forget the period at the end)</span></div>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;">
<br />
<span style="font-family: monospace,monospace; font-size: small;">$ git clone <repo> <b>.</b></repo></span></div>
</div>
</div>
<div>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span>
<span style="font-family: monospace,monospace; font-size: small;"><br /></span></div>
<div>
<span style="font-family: monospace,monospace; font-size: small;">That's it!</span></div>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-80700353638379158912015-01-30T15:42:00.001-08:002015-01-30T15:42:54.406-08:00I love Lucee!<div dir="ltr"><div><div>Small revolutions happen now again, changing our overlapping worlds in small but significant ways. I was surprised, then worried, then trilled, as I read the first news and kept reading on what it all meant and what all had happened with the leadership of Railo -> now Lucee.<br><br></div>I have been in the CFML community for 15 years and great things are still happening. I love it. I love being a part of it.<br><br><br></div><div>I think even Jeremy Allaire would be proud. Hey, Jer?<br><br><br></div><div>I have already upgraded by development servers from Railo to Lucee. Things are looking good! Productions servers coming soon.<br><br></div><div>Cheers to Lucee and Team!<br><br><br><a href="http://lucee.org/">http://lucee.org/</a><br></div></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-36089843667365306792014-11-04T11:34:00.001-08:002014-11-04T11:34:30.086-08:00Cool MySQL for an update conditional upon a previous update within the same query block.<div dir="ltr"><div><div><div>I was writing an update script where I needed to do a second update only if the first update actually affected the target row.<br><br></div>I added additional filters in the first update where clause so that it would only update on certain consitions, then I capture the ROW_COUNT() and add that to filter the where clause on the second update. <br><br>This works great so that I don't have to run additional select queries and conditionals, or more complicated SQL statements, to get my desired results.<br><br></div>A mock situation is outlined below. I set additional variables only to capture the state of the row_count at various places during the rest.<br><br></div>Keep in mind that row_count does not accumulate on multiple update statements.<br><div><div><div><div><div><br><br><div style="margin-left:40px"><span style="font-family:verdana,sans-serif">set @rc = 0;<br>set @rc1 = 0;<br>set @rc2 = 0;<br>set @rc3 = 0;<br>set @rcx = 0;<br><br>drop table if exists testpeople;<br>create table testpeople (contactid INT(3) not null default 0, firstname varchar(100)) ENGINE=InnoDB;<br>insert into testpeople (contactid, firstname) values (234, 'Joe');<br><br>update testpeople set firstname = 'Joe99' where contactid = 234; ## no effect<br>update testpeople set firstname = 'Joe1' where contactid = 234;<br>set @rc = ROW_COUNT(); ## = 1<br>set @rc1 = @rc; ## = 1<br>#set @rc = ROW_COUNT(); #### If we called this again here it would clear it and prevent the next update from completing<br>set @rcx = @rc; ## = 1 or -1 if the line above is commented out<br><br>update testpeople set firstname = 'Joe2' where contactid = 234 <u><b>and @rc = 1</b></u>; #### Could be @rc > 0 or whatever you expected from previous update<br>set @rc = ROW_COUNT();<br>set @rc2 = @rc;<br><br>select @rc as rc, @rc1 as rc1, @rc2 as rc2, @rcx as rcx, (select firstname from testpeople where contactid = 234) as endname;<br><br>drop table if exists testpeople;</span><br><br></div><br></div><div>That's a wrap!<br></div></div></div></div></div></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-48972713660524451902014-10-29T01:49:00.001-07:002014-10-30T00:26:12.435-07:00Fullcalendar Upgrade to process Google Calendar API V3 JSON<div dir="ltr">
<div>
<div>
<div>
I posted this in the Google Code issue tracker for FullCalendar. But that thing it overloaded! This may never be seen.<br />
<br /></div>
I hope people who need this find it. This is my best stab at implementing GCal API V3 in Fullcalendar's gcal.js. The implementation I am using on my site is slightly different than this. I have removed the old 'gcal' references and I have a custom url in the events.push function in place of the the actual entry.htmlLink value so that the edit link points back to my server. I also have my fullcalendar sources pointing to my server and my server handles all the google oauth v3 authentication and google calendar API v3 calls for events list/create/update/delete for secure communications. Because my implementation is slightly different, I have not tested this exact code below in a production environment, but the processing logic for the GCal API V3 JSON is the same. In this sample code you will also see that I tried to retain backward compatibility with GCal API V1 (even though Gcal API V1 is being deprecated in one month). In searching for upgrading my own system, all my googling finds only request for V3 implenentation. This is really needed! <br />
<br />
Thank you Adam Shaw for the amazing FullCalendar app! I hope I can give back a little by contributing this.<br />
<br /></div>
I have to give a little bit of credit to this guy's gist for just the right hint to help me figure out how gcal.js was completing the events list processing into the format FullCalendar.je uses. I stumbled on this during my research. Thanks hong-jen kao!<br />
<a href="https://gist.github.com/cades/d194af6d2be7398cad75">https://gist.github.com/cades/d194af6d2be7398cad75</a><br />
No explanation or comments in that gist, but looking at it and the json coming back from Google Calendar V3 API - I got it. I didn't use his .map for processing, maybe it's better/faster. I don't know. <br />
<br /></div>
I hope whoever needs this is able to modify it to fit their needs.<br />
<div>
<div>
<br /></div>
<div>
This is a sample gcal.js replacement - again, not fully tested as my implementation was much more customized, this is my best guess at intended functionality.<br />
<br />
Best of luck!</div>
<div>
<br />
<div style="margin-left: 40px;">
<span style="font-family: verdana,sans-serif;">/*!</span><br />
<span style="font-family: verdana,sans-serif;"> * FullCalendar v2.1.1 Google Calendar Plugin</span><br />
<span style="font-family: verdana,sans-serif;"> * Docs & License: <a href="http://arshaw.com/fullcalendar/">http://arshaw.com/fullcalendar/</a></span><br />
<span style="font-family: verdana,sans-serif;"> * (c) 2013 Adam Shaw</span><br />
<span style="font-family: verdana,sans-serif;"> * Modified by G. Bach 2014-10-28</span><br />
<span style="font-family: verdana,sans-serif;"> * Changed to process GCal API V3</span> JSON Events list<br />
<span style="font-family: verdana,sans-serif;"> */</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;">(function(factory) {</span><br />
<span style="font-family: verdana,sans-serif;"> if (typeof define === 'function' && define.amd) {</span><br />
<span style="font-family: verdana,sans-serif;"> define([ 'jquery' ], factory);</span><br />
<span style="font-family: verdana,sans-serif;"> } else {</span><br />
<span style="font-family: verdana,sans-serif;"> factory(jQuery);</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;">})(function($) {</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> var fc = $.fullCalendar;</span><br />
<span style="font-family: verdana,sans-serif;"> var applyAll = fc.applyAll;</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> fc.sourceNormalizers.push(function(sourceOptions) {</span><br />
<span style="font-family: verdana,sans-serif;"> if (sourceOptions.dataType == 'gcal'</span><br />
<span style="font-family: verdana,sans-serif;"> || (sourceOptions.dataType === undefined</span><br />
<span style="font-family: verdana,sans-serif;"> && (sourceOptions.url || '').match(/^(http|https):\/\/<a href="http://www.google.com/">www.google.com</a>\/calendar\/feeds\//))) {</span><br />
<span style="font-family: verdana,sans-serif;"> sourceOptions.dataType = 'gcal';</span><br />
<span style="font-family: verdana,sans-serif;"> if (sourceOptions.editable === undefined) {</span><br />
<span style="font-family: verdana,sans-serif;"> sourceOptions.editable = false;</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> } else if (sourceOptions.dataType == 'gcalv3'</span><br />
<span style="font-family: verdana,sans-serif;"> || (sourceOptions.dataType === undefined</span><br />
<span style="font-family: verdana,sans-serif;"> && (sourceOptions.url || '').match(/^(http|https):\/\/<a href="http://www.googleapis.com/">www.googleapis.com</a>\/calendar\/v3\/calendars\//))) {</span><br />
<span style="font-family: verdana,sans-serif;"> sourceOptions.dataType = 'gcalv3';</span><br />
<span style="font-family: verdana,sans-serif;"> if (sourceOptions.editable === undefined) {</span><br />
<span style="font-family: verdana,sans-serif;"> sourceOptions.editable = false;</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> fc.sourceFetchers.push(function(sourceOptions, start, end, timezone) {</span><br />
<span style="font-family: verdana,sans-serif;"> if (sourceOptions.dataType == 'gcal') {</span><br />
<span style="font-family: verdana,sans-serif;"> return transformOptions(sourceOptions, start, end, timezone);</span><br />
<span style="font-family: verdana,sans-serif;"> } else if (sourceOptions.dataType == 'gcalv3') {</span><br />
<span style="font-family: verdana,sans-serif;"> return transformOptionsV3(sourceOptions, start, end, timezone);</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> function transformOptions(sourceOptions, start, end, timezone) {</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> var success = sourceOptions.success;</span><br />
<span style="font-family: verdana,sans-serif;"> var data = $.extend({}, sourceOptions.data || {}, {</span><br />
<span style="font-family: verdana,sans-serif;"> singleevents: true,</span><br />
<span style="font-family: verdana,sans-serif;"> 'max-results': 9999</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> return $.extend({}, sourceOptions, {</span><br />
<span style="font-family: verdana,sans-serif;"> url: sourceOptions.url.replace(/\/basic$/, '/full') + '?alt=json-in-script&callback=?',</span><br />
<span style="font-family: verdana,sans-serif;"> dataType: 'jsonp',</span><br />
<span style="font-family: verdana,sans-serif;"> data: data,</span><br />
<span style="font-family: verdana,sans-serif;"> timezoneParam: 'ctz',</span><br />
<span style="font-family: verdana,sans-serif;"> startParam: 'start-min',</span><br />
<span style="font-family: verdana,sans-serif;"> endParam: 'start-max',</span><br />
<span style="font-family: verdana,sans-serif;"> success: function(data) {</span><br />
<span style="font-family: verdana,sans-serif;"> var events = [];</span><br />
<span style="font-family: verdana,sans-serif;"> if (data.feed.entry) {</span><br />
<span style="font-family: verdana,sans-serif;"> $.each(data.feed.entry, function(i, entry) {</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> var url;</span><br />
<span style="font-family: verdana,sans-serif;"> $.each(entry.link, function(i, link) {</span><br />
<span style="font-family: verdana,sans-serif;"> if (link.type == 'text/html') {</span><br />
<span style="font-family: verdana,sans-serif;"> url = link.href;</span><br />
<span style="font-family: verdana,sans-serif;"> if (timezone && timezone != 'local') {</span><br />
<span style="font-family: verdana,sans-serif;"> url += (url.indexOf('?') == -1 ? '?' : '&') + 'ctz=' + encodeURIComponent(timezone);</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> events.push({</span><br />
<span style="font-family: verdana,sans-serif;"> id: entry.gCal$uid.value,</span><br />
<span style="font-family: verdana,sans-serif;"> title: entry.title.$t,</span><br />
<span style="font-family: verdana,sans-serif;"> start: <a href="http://entry.gd/">entry.gd</a>$when[0].startTime,</span><br />
<span style="font-family: verdana,sans-serif;"> end: <a href="http://entry.gd/">entry.gd</a>$when[0].endTime,</span><br />
<span style="font-family: verdana,sans-serif;"> url: url,</span><br />
<span style="font-family: verdana,sans-serif;"> location: <a href="http://entry.gd/">entry.gd</a>$where[0].valueString,</span><br />
<span style="font-family: verdana,sans-serif;"> description: entry.content.$t</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> var args = [events].concat(Array.prototype.slice.call(arguments, 1));</span><br />
<span style="font-family: verdana,sans-serif;"> var res = applyAll(success, this, args);</span><br />
<span style="font-family: verdana,sans-serif;"> if ($.isArray(res)) {</span><br />
<span style="font-family: verdana,sans-serif;"> return res;</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> return events;</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> function transformOptionsV3(sourceOptions, start, end, timezone) {</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> var success = sourceOptions.success;</span><br />
<span style="font-family: verdana,sans-serif;"> var data = $.extend({}, sourceOptions.data || {}, {</span><br />
<span style="font-family: verdana,sans-serif;"> singleevents: true,</span><br />
<span style="font-family: verdana,sans-serif;"> 'max-results': 9999</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> return $.extend({}, sourceOptions, {</span><br />
<span style="font-family: verdana,sans-serif;"> url: sourceOptions.url,</span><br />
<span style="font-family: verdana,sans-serif;"> dataType: 'json',</span><br />
<span style="font-family: verdana,sans-serif;"> data: data,</span><br />
<span style="font-family: verdana,sans-serif;"> startParam: 'start-min',</span><br />
<span style="font-family: verdana,sans-serif;"> endParam: 'start-max',</span><br />
<span style="font-family: verdana,sans-serif;"> success: function(data) {</span><br />
<span style="font-family: verdana,sans-serif;"> var events = [];</span><br />
<span style="font-family: verdana,sans-serif;"> if (data.feed.entry) {</span><br />
<span style="font-family: verdana,sans-serif;"> $.each(data.feed.entry, function(i, entry) {</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> events.push({</span><br />
<span style="font-family: verdana,sans-serif;"> id: entry.id,</span><br />
<span style="font-family: verdana,sans-serif;"> title: entry.summary || '', // must allow default to blank, if it's not set it doesn't exist in the json and will error here</span><br />
<span style="font-family: verdana,sans-serif;"> start: entry.start.dateTime || entry.start.date,</span><br />
<span style="font-family: verdana,sans-serif;"> end: entry.end.dateTime || entry.start.date, // because end.date may be the next day, cause a '2-all-day' event, we use start.date here.</span><br />
<span style="font-family: verdana,sans-serif;"> url: entry.htmlLink,</span><br />
<span style="font-family: verdana,sans-serif;"> location: entry.location || '', // must allow default to blank, if it's not set it doesn't exist in the json and will error here</span><br />
<span style="font-family: verdana,sans-serif;"> description: entry.description || '' // must allow default to blank, if it's not set it doesn't exist in the json and will error here</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> var args = [events].concat(Array.prototype.slice.call(arguments, 1));</span><br />
<span style="font-family: verdana,sans-serif;"> var res = applyAll(success, this, args);</span><br />
<span style="font-family: verdana,sans-serif;"> if ($.isArray(res)) {</span><br />
<span style="font-family: verdana,sans-serif;"> return res;</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> return events;</span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"> });</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> }</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"> // legacy</span><br />
<span style="font-family: verdana,sans-serif;"> fc.gcalFeed = function(url, sourceOptions) {</span><br />
<span style="font-family: verdana,sans-serif;"> return $.extend({}, sourceOptions, { url: url, dataType: 'gcal' });</span><br />
<span style="font-family: verdana,sans-serif;"> };</span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;"></span><br />
<span style="font-family: verdana,sans-serif;">});</span></div>
<br /></div>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-8998852243835007752014-05-20T21:13:00.001-07:002014-05-20T21:13:50.173-07:00[SOLVED] Darwin CalendarServer Install ./bin/develop silently fails<div dir="ltr"><div><div><div><div>Follow the readme's.<br><br></div>But it's detect_python_version() function isn't looking in the right places for python on Ubuntu.<br></div><div>This causes the CalendarServer/trunk/bin/develop to fail silently and frustratingly.<br> </div><div><br></div>vim CalendarServer/trunk/bin/_py.sh<br><br>in vim do '/detect_python_version' to find the function.<br><br></div>Add these two bold lines at the top of the function:<br><div style="margin-left:40px"> detect_python_version () {<br><b> echo "/usr/bin/python2.7"; ## or wherever yours is actually located<br> return 0;</b><br> ...<br>}<br></div></div><div><div><div><div><div><div><br></div><div>Then run CalendarServer/trunk/bin/develop again and it should work.<br> </div><div><br><br></div> </div></div></div></div></div></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-8333668997512814612014-03-07T15:58:00.001-08:002014-03-07T15:58:01.306-08:00Javascript & Hash-Less Page Navigation<div dir="ltr">When adding a new row to a form I was dealing with the "Add" button being at the top of the form and the new row being added to the bottom. After the user has added a lot of new rows I wanted to user location.hash in the javascript adding the new row html to make sure the new row is in view.<div><br>However, I didn't want the hash #newrow to be left in the URL bar.</div><div><br>If you try to use location.hash = "newrow"; followed by location.hash = ""; you still have the "#" sign in there AND it scrolls the page position back to the top. Not good.<br></div><br>I found some javascript which resets the url history state without the hash:<br><br><div style="margin-left:40px">history.pushState("", document.title, window.location.pathname + window.location.search);<br> </div><div><br></div><div>Using this immediately after setting the hash works perfectly for Hash-Less page navigation:<br><br><div style="margin-left:40px">location.hash = "newrow";<br>history.pushState("", document.title, window.location.pathname + window.location.search);<br> </div></div><div><br></div>This works in both FF and Chrome.<div><br><br></div> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-76869972384535867472013-10-08T09:46:00.001-07:002013-10-08T09:46:05.326-07:00Railo CFML - Get Query Data by full ROW<div dir="ltr"><div><div>Methods previously described for obtaining query data by column name and row number (variables.myquery["columnName"][rowNumber]) are correct, but not convenient for getting a full row of query data.<br> <br>I'm running Railo 4.1. And this is a cool solution. Too bad this can't be done the way we would want outright to get a full row of data, but the following method allows us to get what we want through a few hoops.<br> <br>When you serializeJSON(variables.myquery) it changes the query to a JSON formatted cfml struct object with two items, "Columns" and "Data". Both of these are arrays of data. The "data" array is a two-dimensional array for rows and then columnar data.<br> <br>The issue is that now we have an unusable string. Then if we re-serialize it it's NOT a query but rather usable regular struct in the format described above.<br><br><br>Assume we already have a query variable named 'variables.myquery'. Then look at the following code:<br> <br><div style="margin-left:40px"><cfset variables.myqueryobj = deserializeJSON(serializeJSON(variables.myquery)) /><br></div><br>Now you get the two dimensional array by getting this:<br><div style="margin-left:40px"> <cfset variables.allrowsarray = variables.myqueryobj.data /><br></div><br>And you get one query row array by getting this:<br><div style="margin-left:40px"><cfset variables.allrowsarray = variables.myqueryobj.data[1] /><br> </div>OR the last row this way:<br><div style="margin-left:40px"><cfset variables.allrowsarray = variables.myqueryobj.data[variables.myquery.recordCount] /><br></div><br>And you can get individual column values by column order number iteration:<br> <div style="margin-left:40px"><cfset variables.allrowsarray = variables.myqueryobj.data[1][1] /><br></div><br><br></div>Now this might be slow and possibly unwise with large query results, but this is a cool solution nonetheless.<br> <br></div>I haven't tested this in older version of railo or Adobe CFML. Let me know if this works for you.<br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-53740478175308114642013-09-05T15:30:00.001-07:002013-09-05T15:30:30.948-07:00Javascript Object Literal - get the number of key/value pairs<div dir="ltr"><pre>This was tricky but a friend finally figured it out, I needed to know if the object passed into a function had anything in it.<br></pre><pre>This was the solution:<br></pre><pre style="margin-left:40px"> var x = {t1:1,t2:2,t3:3};<br>console.log(Object.keys(x).length);</pre><div>This outputs '3'.<br></div><div><br>Thanks buddy!<br></div> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-90705561159423536262013-08-09T20:11:00.001-07:002013-08-09T20:11:32.202-07:00Custom CFML BOOL() function<div dir="ltr"><div><div><div>I needed a convenient way to get a trusted Boolean value and didn't want to be doing inline conditions repeatedly, so I write a little function called BOOL to do this:<br><br><div style="margin-left:40px"> <br><b><cffunction name="bool" access="public" returntype="boolean"><br></b><div style="margin-left:40px"><b><cfargument name="in" required="No" type="any" default="" /><br> <cftry><br></b></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><b><cfreturn (<a href="http://arguments.in">arguments.in</a> EQ "" OR <a href="http://arguments.in">arguments.in</a> EQ false ? false : true) /><br> <cfcatch type="any"><br></b></div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><b><cfreturn false /><br></b></div> </div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><b></cfcatch><br></b></div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><b></cftry><br> </b></div><b></cffunction></b><br></div><br></div><div>I'm surprised Railo and Adobe don't have this as a native function. There is the old YesNoFormat() function but that throws errors on strings or anything complex. No good at all.<br> <br>With Javascript, and other true scripting languages I assume, you can take nearly anything and put two exclamation marks in front if it and it's boolean: var x = 'a'; return !!x; I love the bang-bang. I use that often as well.<br> <br></div><br>Also, on the above function, If you need a guaranteed 1 or 0 result you can run VAL(BOOL(variables.whatever)) and that forces true/false into 1/0.<br><br></div>I have a component with functions like this which I re-use on most projects, and I put it in the server scope, or application scope depending on the environment, so I can call server.bool().<br> <br><br></div>That's it. Short and sweet.<br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-49696449998865975642013-06-12T10:43:00.001-07:002013-06-16T10:54:11.845-07:00Java Sass Compass (SCSS) - [SOLVED!]<div dir="ltr"><div><div>After hours of research, trial, frustration, and disappointment, I am very happy to say I have the matter solved.<br><br></div></div>I need to publish this solution to Java Compass Sass (SCSS). From my source links at the bottom it appears people have done this exact thing before, but I haven't seen it blogged about, hence this post. (I don't like re-posting existing knowledge, I don't need to be the source if it's easily available elsewhere.) There appears to already be a <a href="https://github.com/eduardolundgren/jazz">jazz.jar</a> on github which is this exact thing, but I couldn't get it to work. I'll post this on my github account later as well.<br><br>UPDATED: I have posted here on <a href="https://github.com/gbuilt/jcompass">Github: JCompass</a><br><br><br>In the end it was simple and elegant without the mess.<br><br><ol><li>Download the latest copy of <a href="http://www.jruby.org/download">JRuby</a> (At the time of this posting it's version 1.7.4)<br>(<a href="http://www.jruby.org/download">http://www.jruby.org/download</a> Find the "Complete Jar", second link from the bottom in the top group of links for the latest version)<br> <br>(The rest is command line)<br><br></li><li># Make a copy of <span class="">jruby</span>-complete-1.7.4.jar for the new singleton combined jar file<br> cp <span class="">jruby</span>-complete-1.7.4.jar <span class="">jruby</span>-complete.jar<br><br></li><li># Now install these 3 gems locally:<br><br># Without this I got errors.<br>java -jar <span class="">jruby</span>-complete.jar -S gem install -i ./compass-gems shared --no-rdoc --no-ri<br> <br># I flagged "--pre" to get the latest pre-release version, skip that if you want.<br>java -jar <span class="">jruby</span>-complete.jar -S gem install -i ./compass-gems sass --pre --no-rdoc --no-ri<br><br># Again, I flagged "--pre" here. Also, I had heard this includes the sass gem as a dependency, but I installed it separately to be safe.<br> java -jar <span class="">jruby</span>-complete.jar -S gem install -i ./compass-gems compass --pre --no-rdoc --no-ri<br><br></li><li># Now rename the <span class="">jruby</span> complete jar to the name for the new jar app, or we lose the original and have to go download it again<br> mv <span class="">jruby</span>-complete.jar jcompass.jar<br><br></li><li># Now compile together<br> jar uf jcompass.jar -C compass-gems . # including the space and period at the end<br><br></li><li># test it out:<br>java -jar jcompass.jar -S compass compile --help<br>java -jar jcompass.jar -S compass compile --sass-dir [relative or abs path to your .scss files] --css-dir [relative or asb path to destination .css files] --force<br> </li></ol><p><br></p><p>That's it. </p><p>You can download my version of <a href="http://www.gbuilt.com/public/jcompass.jar">jcompass.jar here</a>.<br></p><p><br></p><p><br></p><p>Sources that helped me compile this, and many thanks to them:<br> </p><p><a href="http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar/">http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar/</a><br><a href="http://stackoverflow.com/questions/16188626/how-to-use-compass-through-jruby-for-embedding-in-my-soft">http://stackoverflow.com/questions/16188626/how-to-use-compass-through-jruby-for-embedding-in-my-soft</a><br> <a href="http://stackoverflow.com/questions/15549617/cleanest-way-to-run-susy-compass-and-sass-within-jruby-complete">http://stackoverflow.com/questions/15549617/cleanest-way-to-run-susy-compass-and-sass-within-jruby-complete</a><br> <br></p></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-37350331098913744112013-04-23T13:38:00.001-07:002013-04-23T13:38:11.205-07:00Coldfusion inline cfquery (cfset like cfscript)<div dir="ltr"><div><div><div><div><div>I'm a spotty blogger at best. I like to blog about fun discoveries, time-saving finds, success stories, solutions, or things that I don't find already being discussed in the Coldfusion railo community.<br> <br></div>I had a fun find today. I don't code in CFSCRIPT. But I think it's fascinating. I prefer scripting languages but cfscript was so far behind the times for so long that I never thought it would be possible to write an entire application in cfscript. ...and I really dislike alternating between tag-coding and script-code in the same project. That is why I never embraced it. So I do a lot of short-hand one-off script-like things inside <cfset ... /> tags.<br> <br></div>So I;ll share this one. Today I wanted a one-line statement to get a single value from the database, I have changed this code be able to hit mysql but not require any schema.<br><br></div>This is an inline query getting a single column. for some reason I really liked this.<br> <br><div style="margin-left:40px"><span class=""><span><b><cfset variables.yearid = variables.qryRes = new Query().setSQL("select YEAR(NOW()) as yid").setDatasource(request.mydb).execute().getResult().yid /></b><br> </span></span></div><b><br></b></div>Now, that's a long one-liner, but it did exactly what I was hoping to do in a single line. This is not possible with tag-coding. and it wouldn't be as practical with a complex query, but for a single value it skips all the multiple variables otherwise required for the query and the result and the new variable for the single value from the query column desired. This gets right down to business when the target is solo. And that simplicity won my heart. <br> <br></div>I love one-liners!!!<br><div><br></div><div>Back to monotony of the daily grind.<br><br></div><div>See ya. <br></div><div><br><br></div><div>NOTE: the above code sample was run on Railo 4 with MySQL database.<br> </div><div><div><div><div><span class=""><span></span></span></div></div></div></div></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-87291378440590444592012-08-17T15:01:00.001-07:002012-08-17T15:01:15.562-07:00Git Rocks the House! (Again)I just did the coolest modification with Git ever.<br><br>I had previously complete and committed a complex update affecting multiple files. Call this commit #1.<br>Then I did some house cleaning deleting a couple unused files and making a duplicate of one old report for comparison purposes. Committed those changes. Call this commit #2. <br> Then I found another change that needed to be made which really belonged in commit #1.<br><br>A quick google search brought me here: See Answer #3. <a href="http://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit" target="_blank">http://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit</a><br clear="all"> <br>I had already saved my file changes but not committed - hoping for a way to go back in time. I opened the file and kept it open in my editor. Then in command line, repeating those instructions, I did the following:<br> <ol><li>git reset --hard<br><br> This erases my changes (which I'll add back in a second)<br><br></li><li>git rebase 0ek7sffd1z^ --interactive<br><br> This shows me the commits between HEAD and the commit I want to add to<br> <br> I edited the beginning of the line from 'pick' to 'edit' for the commit I want.<br> Then 'CTRL+x', then 'Y'<br> Now I'm in branch ((no branch))<br> <br> Then in my editor I save the file I had open with my changes.<br> <br></li> <li>git status<br><br> This shows my edited file unstaged<br><br></li><li>git add myeditfile.ext<br><br></li><li>git status<br><br> This shows my edited file staged<br><br></li><li>git commit --amend<br><br></li><li> git rebase --continue<br><br> Now I'm back on my active branch having completed time travel.<br> I laugh out loud as disbelief fades because that really just happened!<br> Git rises to immortal hero status in my mind.<br> </li></ol><br><br>Git saves the world one more time. The world barely noticed, but Git is my hero once again!<br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-17371901163186866372012-05-08T20:47:00.001-07:002012-05-08T20:47:31.961-07:00Updated Coldfusion/Railo AWS S3 JAVA API - Now Full FeaturesI have published my updates to my Java S3 API to Github.<br><br><div style="margin-left:40px"><a href="https://github.com/gbuilt/railo-s3-java-api">https://github.com/gbuilt/railo-s3-java-api</a><br></div><br>It already had methods for 'Upload' and 'GetLink'. Now I've added 'Copy' and 'Delete'. I also added an additional 'Proxy' method for direct linking - it gets the link (authenticated with timeout, if required) and forwards directly to the URL using a <cfheader statuscode="302" statustext="Moved Temporarily" /> followed by a <cfheader name="Location" value="#application.s3api.getlink(arguments.s3path,arguments.expires)#" />. <br> <br>Check it out. It's working great!<br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-7632539492296714982012-04-17T23:49:00.001-07:002012-04-17T23:49:57.958-07:00Coldfusion (Railo) to AWS S3 using Amazon's JAVA APIIssue: Railo's native cffile to S3 gives every file the metadata content-type of 'application'.<br><br>Solution: Use the AWS Java API (until Railo implements a fix).<br><br><div style="margin-left:40px"><b><cfset variables.t1 = "#getTickCount()#" /></b><br> <br><b><!--- Uploading a file from the server to S3 ---></b><br><b><!--- The file to be uploaded ---></b><br><b><cfset variables.filepath = "#expandPath('/')tmp/sample.txt" /></b><br><b><cfset variables.filename = ListLast(variables.testfile,"/") /></b><br> <b><cfsst variables.s3path = "tmp/sd1/sd2/#variables.filename#" /></b><br><br><b><!--- Read the file for sending to S3 ---></b><br><b><cfset variables.javafileobj = createObject("java", "java.io.File").init(variables.filepath) /></b><br> <br><b><!--- Create the PutObject with the intended location (path) and on S3 ---></b><br><b><cfset variables.s3put = createObject("java","com.amazonaws.services.s3.model.PutObjectRequest").init("#this.s3.bucket#", "#variables.s3path#", variables.javafileobj) /></b><br> <br><b><!--- Set the metedata fields for Content Type and Content Disposition ---></b><br><b><cfset variables.s3meta = createObject("java","com.amazonaws.services.s3.model.ObjectMetadata") /></b><br> <b><cfset variables.s3meta.setContentType("#getPageContext().getServletContext().getMimeType(variables.filepath)#") /><!--- Is this the best way? ---></b><br><b><cfset variables.s3meta.setContentDisposition("inline; filename=#variables.filename#") /><!--- suggest filename for download else name becomes full path with '_'s ---></b><br> <b><cfset variables.s3put.setMetadata(variables.s3meta) /></b><br><br><b><!--- Set the ACL (Access Control List) ---></b><br><b><cfset variables.s3acl = createObject("java","com.amazonaws.services.s3.model.CannedAccessControlList").Private /><!--- Use: .Private or .PublicRead ---></b><br> <b><cfset variables.s3put.setCannedAcl(variables.s3acl) /></b><br><br><b><!--- Create the java connector objects for S3 ---></b><br><b><cfset variables.awscreds = createObject("java","com.amazonaws.auth.BasicAWSCredentials").init(this.s3.accessKeyId,this.s3.awsSecretKey) /></b><br> <b><cfset variables.s3client = createObject("java","com.amazonaws.services.s3.AmazonS3Client").init(variables.awscreds) /></b><br><br><b><!--- The actual upload to s3 -- very simple ---></b><br> <b><cfset variables.s3obj = variables.s3client.putObject(variables.s3put) /></b><br><br><b><cfset variables.t2 = "#getTickCount()#" /></b><br><b>Processing Time: <cfoutput>#variables.t2-variables.t1#</cfoutput>ms</b><br> <b><br /></b><br><br><br><b><!--- Generating a download link ---></b><br><b><!--- If ACL is Private - Get authenticated link and test the download and prompted file name ---></b><br><b><cfif (variables.s3acl.toString() IS "private")></b><br> <div style="margin-left:40px"><b><cfset variables.s3url = variables.s3client.generatePresignedUrl("#this.s3.bucket#", "#variables.s3path#", dateAdd("m",10,request.now)).toString() /></b><br> </div><div style="margin-left:40px"><b><cfoutput><a href="#variables.s3url#">#variables.s3url#</a></cfoutput></b><br></div><b><cfelse></b><br><div style="margin-left:40px"><b><cfset variables.s3url = "https://#this.s3.bucket#.<a href="http://s3.amazonaws.com/#variables.s3path%23" target="_blank">s3.amazonaws.com/#variables.s3path#</a>" /></b><br> </div><div style="margin-left:40px"><b><cfoutput><a href="#variables.s3url#">#variables.s3url#</a></cfoutput></b><br></div><b></cfif></b><br></div><br><br>Note #1: On Content Disposition - The JAVA API does not require you to pre-create the directories for the target desination of your file upload. Directories on S3 are a funny thing. '/' slashes in the target file path are not actual directories (and if they exist they are essentially ignored) to Amazon. So you don't have to create them before uploading your file when using any of Amazon's own APIs. You just upload your file to your bucket as "subdir1/subdir2/subdir3/sample.txt" and to Amazon it's part of the file name. When you go to download your file you will be given the prompt to download "subdir1_subdir2_subdir3_sample.txt". That's no fun. That's not what I want my users to see or download, and that's not what I want my file to me named. This causes a new problem that's no better than other problem of Railo's native S3 interface uploading all files with content type 'application' (which is solved by setting the metadata attribute with 'setContentType()'). Amazon refers to the slashes in your target path as 'prefixes' and it's in reference to 'versioning' from what I had read, but I don't understand the methodology. I want to understand their versioning because I'd like to take advantage of it but not at the expense of a subdirectory schema. To resolve this we have to rely on setting the metadata attribute with 'setContentDisposition()'. This tells the browser download prompt what the download file should be named. Now that is solved too. <br> <br>Note #2: On Content Disposition - I setting it to "attachment; filename=#variables.filename#". Specifying 'attachment' forces a download prompt even for types that can be viewed in the browser, such as images and plain text. You could conditionally use 'inline' which prompts the browser to attempt to open all files in the browser window.<br> <br>Note #3: On setting the ACL, this was tricky figuring out. In the end it was really easy. I'd strongly recommend only using "Private" or "PublicRead". I'm not sure of the full uses of "authenticated-read" and how it differs from authenticating a download link for temporary read access and shown here. Maybe it provides authenticated read without an expiration date?<br> <br>Some day I would love to dig into Railo's source code and see how they are creating and managing S3 directories and files within a directory without specifically setting the content type meta data. I have seen methods inline for creating empty directories (<a href="https://forums.aws.amazon.com/thread.jspa?threadID=48740" target="_blank">https://forums.aws.amazon.com/thread.jspa?threadID=48740</a>) but I tested creating the directories with Railo's native S3 first and them uploading the file with the JAVA API (minus the metadata setting) but the download filename still had the full path with '_'s in place of '/'s.<br> <br>Anyone know?<br><br><br><br><b>Update:</b> I've turned this into a cleaned-up CFC. I've never made a public repo on Github. Lets try this out.<br><br><div style="margin-left:40px"><b><a href="https://github.com/gbuilt/railo-s3-java-api">https://github.com/gbuilt/railo-s3-java-api</a></b><br> </div><br>Please add to it if you get the chance before I do. Thanks!<br><br> Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-5957862346514573037.post-49345721568784383092012-04-17T19:16:00.001-07:002012-04-17T19:16:33.793-07:00Railo on Resin 4 and More! (Full Tutorial)I *finally* have railo running on Resin 4. It's actually been over a month but I really wanted to post this tutorial.<br><br>No one seems to be able to get this going because of one major change in the settings files. Not just are some files settings/config files named differently, like 'resin.conf' of Resin 3.x is now 'resin.xml' in Resin 4, but the biggest kicker is that 'app-default.xml' is no longer used. In fact if you try to use it the server fails. i couldn't get the server to start under any circumstances with app-default.xml being included in the resin.xml. That's where all the Railo Servlet setting were added under Resin 3.x. So forget that 'app-default.xml' even exists and start looking at 'cluster-default.xml' for the location of the CFML Servlet configuration.<br> <br><br>I believe this is the full list of steps I took to get my installation running. I needed the regex available for virtual hosts and Apache and Tomcat can't handle it or I would have stuck with the traditional installers. So I'm using Nginx and Resin 4 both of which do regex virtual hosts. :)<br> <br>I'm, on AWS Micro instance running 64bit Ubuntu 11.10 (ami-2af9741a) for development:<br><br>I'm skipping the front end server set-up. You're probably using Apache anyway. I'm using Nginx as I already stated. I'll explain my Nginx setup after.<br> This is for *nix machines only. If you're a windows person, I hope you can find and to the equivalents of these commands.<br><br><br>Here we go: Installing and setting up Resin 4 with Railo Jars. 10 simple steps:<br> <ol><li>#Following instructions from here: <a href="http://www.caucho.com/resin-4.0/admin/starting-resin-install.xtp#InstallingResinusingthedebpackageonUbuntuandDebian" target="_blank">http://www.caucho.com/resin-4.0/admin/starting-resin-install.xtp#InstallingResinusingthedebpackageonUbuntuandDebian</a><br> <b>sudo vim /etc/apt/sources.list</b><br><div style="margin-left:40px"><b>#ADD THE FOLLOWING TO THE BOTTOM TO ALLOW APT-GET INSTALL OF RESIN<br>deb <a href="http://caucho.com/download/debian">http://caucho.com/download/debian</a> unstable multiverse</b><br> </div><br></li><li><b>sudo apt-get update</b> #this will catalog the new source so the next command will work<br><br></li><li><b>sudo apt-get install resin</b><br>#Note 1: You will see the following output above the package list:<br> <div style="margin-left:40px">...<br>Note, selecting 'resin-pro' instead of 'resin'<br>... [package list] ...<br>Do you want to continue [Y/n]? Y<br>WARNING: The following packages cannot be authenticated!<br> resin-pro<br>Install these packages without verification [y/N]? Y<br></div>#I'm assuming that resin-pro without any license is the same as free resin. <i>**If you know otherwise please let me know.**</i><br> <br>#Note 2: This installs the resin config files in /etc/resin/ and the resin engine in /usr/local/share/resin-pro-4.0.27/<br>#Optionally, it's convenient/helpful to make a symbolic link from a more traditional location in /opt.<br> <div style="margin-left:40px">sudo updatedb<br>sudo locate /resin-pro #just to make sure of the source directory<br> sudo ln -s /usr/local/share/resin-pro-4.0.27 /opt/resin<br></div> <br>#Note 3: this will also install all the required Java-6-jre for you - very nice!<br> <div style="margin-left:40px">#If you want to use Java 7, install it manually. Otherwise skip to Step 4.<br> sudo apt-get install openjdk-7-jdk<br>sudo updatedb<br>locate /jre/bin/java<br>#for me that output "/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java" as the home for Java 7<br>#Now, Resin only knows about java-6 so we have to tell it to use java-7.<br> #Resin uses a symbolic link for it's JAVA variable. Make sure it's set by opening:<br>sudo vim /opt/resin/bin/resinctl #Look at near the top, it should have the following variables.<br><div style="margin-left:40px"> JAVA="/usr/bin/java"<br>RESIN_HOME="/usr/local/share/resin"<br>resin_root="/var/www"<br>resin_conf="/etc/resin"<br>resin_log="/var/log/resin"<br></div> #The first variable there, "JAVA" is using "/usr/bin/java" which is a symbolic link.<br>#Follow the trail so we know where to update the system to use Java-7 rather then Java-6<br>ls -al /usr/bin/java #outputs: /usr/bin/java -> /etc/alternatives/java<br> ls -al /etc/alternatives/java #outputs: /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/java<br>#That's the real location, so if we update that link then we're set.<br>sudo rm /etc/alternatives/java #Remove the old link<br> sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /etc/alternatives/java #set it to the path we got from "sudo locate /jre/bin/java"<br> #DONE! now resin (and anything else that uses that traditional Linux java path) will be using Java-7.<br>#You can do "ls -al /etc/alternatives/java" again just to make sure it's pointing to the right place<br> <br></div></li><li>#Resin may have been started as part of the install process. Make sure we stop it before adding our settings:<br><b>sudo service resin stop</b><br><br></li><li>#Now for the resin config and Railo CFML Servlet in cluster-default.xml<br> #Remember the old instructions for 'app-default.xml' don't apply to Resin 4...<br> <b>sudo vim /etc/resin/cluster-default.xml</b><br><br><ol><li>#find the <class-loader> right near the top of the file<br>#add <br><div style="margin-left:40px"><b><tree-loader path="${resin.home}/lib"/></b><br> <b><tree-loader path="${resin.root}/lib"/></b><br></div> <br>#Now the whole class-loader section looks like this:<br><class-loader><br><div style="margin-left:40px"><tree-loader path="${resin.root}/ext-lib"/><br><tree-loader path="${resin.root}/resin-inf"/><br> <b><tree-loader path="${resin.home}/lib"/></b><br><b><tree-loader path="${resin.root}/lib"/></b><br><tree-loader path="cloud:/resin-inf"/><br></div></class-loader><br> <br>#The reason for this is that later our Railo Jars will go into ${resin.root}/lib<br> <br></li><li>#Now go down about 50% the way down in the file and look for the <web-app-default> section.<br>#Got to the bottom of the <web-app-default> section, just above the closing </web-app-default> tag<br> #After the closing </session-config> tag and above the closing </web-app-default> tag - add the following.<br> #This is similar to instructions on the Railo site: <a href="http://www.getrailo.org/index.cfm/documentation/installation/railo-resin-apache/" target="_blank">http://www.getrailo.org/index.cfm/documentation/installation/railo-resin-apache/</a><br> #Because the Resin 4 architecture is slightly different we need a few extra things above the 'CFMLServlet' section<br><br><b><!-- RAILO CFML SERVLET CONFIG --><br><class-loader><br></b><div style="margin-left:40px"> <b><compiling-loader path="WEB-INF/classes"/><br><library-loader path="WEB-INF/lib"/><br></b></div><b></class-loader><br><br><servlet servlet-name="resin-file" servlet-class="com.caucho.servlets.FileServlet"/><br> <br><servlet servlet-name="CFMLServlet" servlet-class="railo.loader.servlet.CFMLServlet"><br></b><div style="margin-left:40px"><b><init-param><br></b><div style="margin-left:40px"><b><param-name>railo-web-directory</param-name><br> <param-value>{web-root-directory}/WEB-INF/railo/</param-value><br><description>Railo Web Directory directory</description><br></b></div><b></init-param><br><load-on-startup>1</load-on-startup><br> </b></div><b></servlet><br><servlet servlet-name="AMFServlet" servlet-class="railo.loader.servlet.AMFServlet"><br></b><div style="margin-left:40px"><b><load-on-startup>2</load-on-startup><br> </b></div><b></servlet><br><br><servlet-mapping url-pattern="*.cfm" servlet-name="CFMLServlet"/><br><servlet-mapping url-pattern="*.cfml" servlet-name="CFMLServlet"/><br> <servlet-mapping url-pattern="*.cfc" servlet-name="CFMLServlet"/><br><br><welcome-file-list><br></b><div style="margin-left:40px"><b><welcome-file>index.cfm</welcome-file><br><welcome-file>index.cfml</welcome-file><br> <welcome-file>index.htm</welcome-file><br><welcome-file>index.html</welcome-file><br></b></div><b></welcome-file-list></b><br> <br></li><li>#Done. Save and close cluster-default.xml<br><br><br></li></ol> </li><li>#Now we can set up the resin.xml file with our virtual hosts.<br><b>sudo vim /etc/resin/resin.xml</b><br><br><ol><li>#Find the <cluster id="app"> section near the bottom of the file.<br>#I left <cluster id="web"> and <cluster id="memcached"> in there but I'm not sure they are needed.<br> #Inside <cluster id="app"> be sure to comment out the entire default <host id="" root-directory="."> ... </host> section and everything inside it.<br>#Add your own virtual hosts below it but above the closing </cluster> tag.<br> <br><div style="margin-left:40px"> <b><host id="<a href="http://mysite.com" target="_blank">mysite.com</a>" root-directory="/var/www/</b><b>mysite"><br></b><div style="margin-left:40px"><b> <host-alias-regexp>.*\.mysite\.com</</b><b>host-alias><br><web-app id="/" /><br> </b></div> <b></host></b><br></div><br>#Done. Save and close resin.xml<br></li></ol><br></li><li>#Other resin settings are set in "/etc/resin/resin.properties" such as the post that resin is listening on - default is port 8080.<br> #Change this to post 80 if you don't have any other front-end web server.<br>#If you do have a front-end web server then keep the post as 8080 and proxy coldfusion files to this port. (Not described in this tutorial.)<br> <br></li><li>#Now we get the Railo jars and install them - I do all this as root<br><b>sudo -s<br>cd /opt/resin<br>wget <a href="http://www.getrailo.org/down.cfm?item=/railo/remote/download/3.3.1.000/custom/all/railo-3.3.1.000-jars.zip">http://www.getrailo.org/down.cfm?item=/railo/remote/download/3.3.1.000/custom/all/railo-3.3.1.000-jars.zip</a></b><br> <b>ls -al </b>#To see the downloaded file<br>#Sometimes this saves the zip file name as "down.cfm?item-/railo/......." long string<br>#If so, do: <b>mv dow[tab] railo-3.3.1.000-jars.zip<br> unzip </b><b>railo-3.3.1.000-jars.zip</b><br>#If you don't have unzip installed, type: <b>apt-get install unzip</b> then retry <b>unzip </b><b>railo-3.3.1.000-jars.zip</b><br>#this creates a new directory "/opt/resin/railo-3.3.1.000-jars" with the jar files inside<br> <b>ls -al </b><b>./railo-3.3.1.000-jars</b><br> <b>mv ./railo-3.3.1.000-jars/* ./lib/</b><br><b>ls -al </b><b>./railo-3.3.1.000-jars</b> #To see that everything was moved type "ls -al ./railo-3.3.1.000-jars" again and "ls -al ./lib"<br> <b>rm -R </b><b>./railo-3.3.1.000-jars</b> #This removes the not-needed, empty directory from the upzip<br> <b>exit </b>#Don't forget to get out of root<br><br></li><li>#The web directory... I had issues with this part.<br>#It seems picky on permissions and generating the WEB-INF directory because it's running as the user "www-data".<br> <br>#If you create your own directory in "/var/www/mysite" then it has trouble generating it's own WEB-INF.<br> #You can try making the required directories for "WEB-INF" and "log" and assigning the ownership:<br><div style="margin-left:40px">cd /var/www/mysite<br>sudo chown -R www-data:www-data ./log ./WEB-INF<br> </div><br>#If you *don't* create your site directory in /var/www then it will create one and generate the mysite directory and WEB-INF and log subdirectories.<br>#If it does this automatically then you will need change the owner of the mysite directory to yourself:<br> <div style="margin-left:40px">cd /var/www/mysite<br> sudo chown [myname]:[mygroup] . #Don't do -R on this one it also changes ownership of WEB-INF and log<br># Don't forget the period meaning the current directory, you know.<br>#If you don't know your name, type "whoami" and set that as both myname and mygroup<br> </div><br>#If you don't want to deal with these permission issues you can set resin to run as root by editing<br><b>vim /etc/resin/resin.properties</b><br>#and change these lines, removing the 'www-data' user and gorup:<br> <div style="margin-left:40px">setuid_user : www-data<br>setuid_group : www-data<br></div>#to be blank, like this<br><div style="margin-left:40px">setuid_user :<br>setuid_group :<br></div><br>#Note: But be careful, if you ever forget to do 'sudo' when starting resin it will start under your user permissions and not run properly!<br> <br><br>#Then you can go create your own /var/www/mysite directory<br><b>cd /var/www<br>mkdir mysite</b><br><br>#Create your Application.cfc<br><b>touch Application.cfc</b><br><br>#Create your index.cfm with something in it so we can see if CFML is being processed<br> <b>vim index.cfm</b><br><div style="margin-left:40px">Hello World!<br><br /><br><br /><br>The time is" <cfoutput>#NOW()#</cfoutput><br></div><br></li><li>#All done! Yes, really! Fire it all up and see what's broken. I hope I didn't forget any steps! :)<br> #Now if you don't have a real domain pointing to your server or if this is local or a virtualbox,<br>#Then you can set up a /etc/hosts alias on your local machine direct a fake domain for testing<br> <b># On your local maching:<br></b><div style="margin-left:40px"><b>sudo vim /etc/hosts</b><br></div><div style="margin-left:40px"><b>192.168.0.7 mysite.local</b><br></div> #Then add a matching to your resin.xml virtual hosts settings.<br><div style="margin-left:40px"><b>sudo vim /etc/resin/resin.xml</b><br><b><host-alias-regexp>(\w+\.)?mysite\.local</</b><b>host-alias></b></div> <b><br>sudo service resin start</b> #cross fingers...<br><br>#Point your browser to <a href="http://mysite.local">http://mysite.local</a> or whatever your set as your domain and see it things are working.<br> <br><br>#Debugging issues - somewhere to start:<br><br>#If your getting errors like this below then your resin.xml hosts is not catching your domain.<br><div style="margin-left:40px">"404 Not Found / was not found on this server."<br> </div><br>#If your CFML source code is showing on screen then the CFMLServlet in cluster-default.xml isn't working.<br><br><br></li></ol>Railo on Resin 4 tutorial is complete.<br>Comments are invited. Let me know how things worked for you.<br> <br><br>============================<br><br><br>Now, I also wanted to outline my Nginx configuration in front of Resin 4.<br> <br>I'm building a SAAS application where every client upon signup will select their own subdomain. Now, I'm cheap and I don't want to pay for second server and so I'm breaking the cardinal rule and I'm developing on my temporary production server. Once things start going I'll keep this as a sol development server and build a larger production server. but for now I need one server with <a href="http://subdomains.mysite.com">subdomains.mysite.com</a> going to one virtual host, the production site for now, and <a href="http://dev.subdomains.mysite.com">dev.subdomains.mysite.com</a> going to the dev site. This way I can run separate code bases and do GIT deployments at regular intervals so I'm not interrupting the demo live site.<br> <br>Apache can almost do the front end web serving the way I need, but not quite, and not as easily as I'd like. I've never used Nginx, but I think I've successfully make the jump. I was really comfortable with Apache. I didn't realize just how similar the two servers setups are and how easy it was to switch over.<br> <br>Here is my Nginx "/etc/nginx/sites-enabled/mysite" virtual hosts condiguration<br><br><div style="margin-left:40px">#### DEV<br>server {<br><div style="margin-left:40px">root /var/www/mysite_dev;<br>index index.cfm index.html;<br> server_name ~^dev\.[\w-]+\.mysite\.com$;<br>location / {<br></div><div style="margin-left:80px"># First attempt to serve request as file, then<br># as directory, then fall back to index.html<br>try_files $uri $uri/ /index.cfm /index.html;<br> </div><div style="margin-left:40px">}<br>location ~ \.cf[cm]$ {<br><div style="margin-left:40px">proxy_pass <a href="http://dev.mysite.local:8080">http://dev.mysite.local:8080</a>;<br>proxy_set_header X-Real-IP $remote_addr;<br> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>proxy_set_header Host $http_host;<br></div>}<br></div>}<br><br>#### LIVE<br>server {<br><div style="margin-left:40px">root /var/www/mysite;<br> index index.cfm index.html;<br>server_name ~^[\w-]+\.mysite\.com$;<br>location / {<br><div style="margin-left:40px"># First attempt to serve request as file, then<br># as directory, then fall back to index.html<br>try_files $uri $uri/ /index.cfm /index.html;<br> </div>}<br>location ~ \.cf[cm]$ {<br></div><div style="margin-left:80px">proxy_pass <a href="http://prod.mysite.local:8080">http://prod.mysite.local:8080</a>;<br>proxy_set_header X-Real-IP $remote_addr;<br> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>proxy_set_header Host $http_host;<br></div><div style="margin-left:40px">}<br></div> }<br></div><br>Note the proxy_pass line in each vhost pointing to "dev.mysite.local" and "prod.mysite.local" and not to "localhost". I was proud of this little invention of mine to allow resin to catch separate domains being proxied over to it.<br> <br>I added following to my "/etc/hosts" to make this possible:<br><div style="margin-left:40px">127.0.0.1 prod.mysite.local<br>127.0.0.1 dev.mysite.local<br><br>#I think this can be done on one line following localhost:<br> 127.0.0.1 localhost prod.mysite.local dev.mysite.local</div><br>Then I have my resin.xml virtual hosts configured like this:<br><div style="margin-left:40px"> <!-- Live Site --><br> <host id="prod.mysite.local" root-directory="/var/www/mysite"><br><div style="margin-left:40px"> <host-alias-regexp>^[\w-]+\.mysite\.\w+$</host-alias-regexp><br><web-app id="/" /><br></div> </host><br> <!-- Dev Site --><br> <host id="dev.mysite.local" root-directory="/var/www/mysite_dev"><br><div style="margin-left:40px"> <host-alias-regexp>^dev\.[\w-]+\.mysite\.\w+$</host-alias-regexp><br><web-app id="/" /><br></div> </host><br></div> <br>This would also work if I dropped nginx and used Resin as the front-end web server as well. I like that as I think Resin 4 can do clustering and HTTPS SSL without subscribing for a license. But I'm not certain on that point. But I also like what I read/hear about Nginx's robustness on the front-end.<br> <br>That's all I got. That was a lot. Enjoy.<br><br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-88835024045556125592012-01-09T14:22:00.001-08:002012-01-09T14:22:05.536-08:00Killing a Runaway MySQL Query the Right WayIt happens. Your testing a query and you forget a join in the where clause and you know it's going to run for minutes and pull thousands of records because you hit 'Return' too soon.<br><br>Solution:<br><br>Run 'show processlist;' to get the current running queries with active connections (note the active connections).<br> You will see your runaway query and probably some other connections with a 'Sleep' status under the 'Command' column.<br>Get the 'id' (ex. 12345) for your runaway.<br><br>Run 'kill <b>query</b> 12345;'<br> <br>I used to always run 'kill 12345;' (without the 'query' specification) but when I was refreshing my memory today on these commands from the mysql docs I found that that command doesn't kill the query itself, but rather by default it only kills the CONNECTION to the query. This is really bad.<br> <br>The query may still be running in the background hurting performance without any visible process/connection associated with it. If you kill the connection (which is default if neither connection/query is specified) then you have to connection by which to view or kill the actual query. No fixing that performance hit if it was noticeable without restarting the MySQL service or waiting until it completed the result.<br> <br>Additionally, many web servers keep connections open and 'sleeping'. Killing the connection makes the web server start a new connection. Not really all that bad, but that will add milliseconds to the next query request on top of the still-running query explained above.<br> <br><br><i>Lesson for the day:</i> Specify the optional 'query' command when killing mysql processes.<br><br><br><br><br>FROM THE MYSQL DOCS: <a href="http://dev.mysql.com/doc/refman/5.1/en/kill.html">http://dev.mysql.com/doc/refman/5.1/en/kill.html</a><h4 class="title"> <code class="literal">KILL</code> Syntax</h4> <a class="indexterm" name="id1030885"></a><a class="indexterm" name="id1030894"></a><pre class="programlisting">KILL [CONNECTION | QUERY] <em class="replaceable"><code>thread_id</code></em> </pre> <p> Each connection to <a href="http://dev.mysql.com/doc/refman/5.1/en/mysqld.html" title="4.3.1. mysqld — The MySQL Server"><span><strong class="command">mysqld</strong></span></a> runs in a separate thread. You can see which threads are running with the <a href="http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html" title="12.7.5.31. SHOW PROCESSLIST Syntax"><code class="literal">SHOW PROCESSLIST</code></a> statement and kill a thread with the <code class="literal">KILL <em class="replaceable"><code>thread_id</code></em></code> statement. </p> <p> <a href="http://dev.mysql.com/doc/refman/5.1/en/kill.html" title="12.7.6.4. KILL Syntax"><code class="literal">KILL</code></a> permits an optional <code class="literal">CONNECTION</code> or <code class="literal">QUERY</code> modifier: </p> <div class="itemizedlist"><ul><li><p> <a style="background-color:rgb(255,255,102)" href="http://dev.mysql.com/doc/refman/5.1/en/kill.html" title="12.7.6.4. KILL Syntax"><code class="literal">KILL CONNECTION</code></a><span style="background-color:rgb(255,255,102)"> is the same as </span><a style="background-color:rgb(255,255,102)" href="http://dev.mysql.com/doc/refman/5.1/en/kill.html" title="12.7.6.4. KILL Syntax"><code class="literal">KILL</code></a><span style="background-color:rgb(255,255,102)"> with no modifier</span>: It terminates the connection associated with the given <em class="replaceable"><code>thread_id</code></em>. </p></li><li><p> <a href="http://dev.mysql.com/doc/refman/5.1/en/kill.html" title="12.7.6.4. KILL Syntax"><code class="literal">KILL QUERY</code></a> terminates the statement that the connection is currently executing, but leaves the connection itself intact. </p></li></ul></div><br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-57751076776081206882011-12-30T12:13:00.001-08:002011-12-30T12:13:45.606-08:00Duplicate CFArgument Gotcha!Today I was debugging a component which returned a query for a paginated display.<br><br>This component has the page number and limit passed in, but also has default values set in the CFArgument tags.<br><br>At some point during development (probably while copy-pasting a bunch of cfargument tags for quick editing of names and default values) one of the arguments was left twice.<br> <br>At appeared something like this:<br><br><div style="margin-left:40px;color:rgb(51,51,255)"><cfcomponent ...><br><div style="margin-left:40px"><cffunction name="queryrecs" access="public" output="No" returntype="query"><br> </div></div><div style="margin-left:120px;color:rgb(51,51,255)"> <cfargument name="someid" type="numeric" required="No" default="0"><br><cfargument name="something" type="string" required="No" default=""><br> <cfargument name="somethingelse" type="string" required="No" default=""><br> <cfargument name="anotherthing" type="string" required="No" default=""><br> <cfargument name="page" type="numeric" required="No" default="1"><br> <b><cfargument name="limit" type="numeric" required="No" default="10"><br> <cfargument name="limit" type="numeric" required="No" default="10"></b><br><cfset var pagerecs = ""><br><cfquery name="pagerecs"><br><div style="margin-left:40px"> select ...<br></div><div style="margin-left:40px">from ...<br>where ...<br>LIMIT #arguments.limit# OFFSET #(arguments.page-1)*arguments.limit#<br></div></cfquery><br><cfreturn pagerecs /><br></div><div style="margin-left:40px"> <div style="margin-left:40px"><span style="color:rgb(51,51,255)"></cffunction></span><br><span style="color:rgb(51,51,255)"></span></div><span style="color:rgb(51,51,255)"></cfcomponent><br><br></span></div><br> Notice the two limit arguments. This is really bad. When the method is called and the "limit" parameter passed in the first cfargument tag catches the passed in "limit" parameter and the second "limit" cfargument tag overwrites the passed in set value in the ARGUMENTS scope to the default value.<br> <br>It's just something to be mindful of when things aren't working as expected.<br><br>That's a wrap!<br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-29846694877432651362011-12-17T21:14:00.001-08:002011-12-17T21:14:53.769-08:00Focus Text Input at the End of the Value [SOLVED CROSS BROWSER]I just saved the world! It didn't notice, so I have to blog about it.<br><br>I discovered a super simple, fully cross-browser compatible, solution to focusing a text input at the end of the current value.<br><br>I needed to do this as part of the application I am currently working on. The html block, including the search input field, are returned form an ajax call and replace the existing HTML within the specified block. After the ajax call returns and replaces the content it needs to focus the input field at the end of the input value.<br> <br>Moving the cursor, cross-browser friendly, is always messy. I had been dealing with character codes to clear the field on escape and to submit on the enter key, so I get this idea, 'Why not append the 'character' from the key code for the "END" key onto the input value after focusing it?' If that worked, someone would have done it before. In theory this would be done by appending <b><span style="color:rgb(51,51,255)">String.fromCharCode(35)</span></b> to the current value. Would that move the cursor to the end? I try it, it doesn't work.<br> <br>My next idea was to just set the value as the "END" key. My thought was that it's not a visible character, so maybe it's a more of an <i>instruction</i> key, so-to-speak, and won't mess things up. I try it, it blanks out the value - not what I wanted, but it was worth a try.<br> <br>So then I try saving the original value in a variable, then set the value to "END" key (clearing the input as before), then re-set the value to the original value. <i>'This is nuts</i>!' I'm thinking to myself, <i>'Why am I even trying this?'</i> but I try it anyway. It worked, wait, what??? Yes, it worked!!! I couldn't believe it. I had to test it a hundred times. It's working solid. Unbelievable. I even put the cursor in the middle of the word and hit enter (triggering the ajax) and it replaces the content block, focuses the input, and the cursor appears at the end right where I want it. This is too cool. I'm in Firefox, I re-test it in Chrome, Safari, both work. <i>This is crazy-good news!</i> I'm thinking, but it's sure to fail in IE, everything cool always fails in IE. I'm on my macbook pro, so I load up my Virtualbox with multiple IE's installed on an old Windows XP instance and I test my code. Low and behold, it works in IE7 and in IE8. I'm astonished! Litterally, my jaw dropped, followed by that irresistible smile of success.<br> <br>I'm still not entire sure *why* it's actually working. The 'END' key must be sticky in some manner so that when the value is replaced it's inserted in front of the cursor. It doesn't make perfect sense that the cursor would stay at the end of the string following the value being reset by javascript while the input is in focus. There's a lot going on there. But something about it being sticky to the end, and not at a specific character position, is my only guess as to 'why' this works. I'm just flipping happy that it does - and fully cross-browser compatible to boot!<br> <br>Here's my code sample:<br><br><div style="margin-left:40px"><b><span style="color:rgb(51,51,255)">var $t = $("#myinput")</span></b><span style="color:rgb(51,51,255)"> //cache the target so we're not parsing for it multiple times</span><b><span style="color:rgb(51,51,255)"><br> v</span></b><b><span style="color:rgb(51,51,255)">ar oldv = $t.val();</span></b><b><span style="color:rgb(51,51,255)"></span></b><span style="color:rgb(51,51,255)"> // remember the original value</span><b><span style="color:rgb(51,51,255)"></span><br style="color:rgb(51,51,255)"> <span style="color:rgb(51,51,255)">$t.focus().val(String.fromCharCode(35)).val(oldv);</span></b><b><span style="color:rgb(51,51,255)"></span></b><span style="color:rgb(51,51,255)"> // focus it, set as 'END' key, reset to original<br> </span></div><br>That's it. A simply awesome solution.<br> Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-5957862346514573037.post-5446537209130669252011-12-09T20:12:00.001-08:002011-12-09T23:42:42.718-08:00Prevent Railo's Default FLEX Integration From Generating WEB-INF Directories in Every Web SubdirectoryI recently upgraded to a new AWS server and started from scratch with Apache + Tomcat + Railo 3.3. This comes with a short vertical learning curve in regards to learning Tomcat set-up woes and new railo server.xml default settings. The last of which was the biggest surprise and confusingly new issue until I learned how easy it was to resolve.<br /><br />New Railo installs, by default, are set up to integrate with FLEX. This should either be an option during installation, or... it should be an option during installation. I had never used the new railo-...-installer.run program, I really liked it a lot, but I really wish it had asked me if I wanted FLEX integration in the process. It's a small thing, but it's always the smallest things that make the biggest difference. It's okay, I'm still a [Railo] believer.<br /><br />So, to fix this issue, go to the bottom of <b><span style="color: rgb(51, 51, 255);">/opt/railo/lib/railo-server/context/railo-server.xml</span></b> (or where ever you have your Railo engine installed)<br /><br />Change:<br /> <dd><b style="color: rgb(51, 51, 255);"><flex configuration="xml"/></b></dd><br />To:<br /> <dd><b style="color: rgb(51, 51, 255);"><flex configuration="<u>manual</u>"/></b></dd><br />Then you cango to your website root directory and run:<br /> <dd><b style="color: rgb(51, 51, 255);">$ ls -alR | grep 'WEB-INF'</b></dd><br /><br />That will show all of the 'WEB-INF' directories that you don't need (in your /images, /css, /js, ...) that you should delete with following command:<br /> <dd><b style="color: rgb(51, 51, 255);">$ sudo rm -RIf ./css/WEB-INF</b><br /> <b style="color: rgb(51, 51, 255);">$ sudo rm -RIf ./images/WEB-INF</b><br /> <b style="color: rgb(51, 51, 255);">$ sudo rm -RIf ./js/WEB-INF</b><br /> ... etc., etc.</dd><br /><br />Notes on the above: the 'R' = recursive, the 'I' (capital i, not lowercase L) ignores errors, and the 'f'' means 'force' to ignore 'are you sure' confirmation questions.<br /><br />Then you can go into the Railo SERVER admin and Restart the server there, or recycle Tomcat and that will regenerate the one and only required 'WEB-INF' in the web root directory.<br /><br /><br /><span style="font-weight: bold;"> - UPDATE - </span><br />It turns out the above was not the only issue, as it was not completely resolved. After a lot more testing I found that I had also incorrectly set up my Tomcat Virtual Hosts. On this Ubuntu Railo-Tomcat server the Tomcat server.xml is located in /opt/railo/tomcat/conf/server.xml. My site's host xml was not set up correctly - missing the attribute 'autoDeploy' in conjunction with having an unwanted 'appBase' attribute. (See the first and second wrong ways below.)<br /><br />My first WRING way:<span style="color: rgb(51, 51, 255);"><br /> <dd><host name="www.website1.com" appbase="/var/www/website1"><br /> <context path="" docbase=""><br /> ...<br /> </host></dd></span><br /><br />My Second WRONG way:<span style="color: rgb(51, 51, 255);"><br /> <dd><host name="www.website1.com" appbase="<b>/var/www</b>" <b>autoDeploy="false"</b>><br /> <context path="" docbase="<b>website1</b>"><br /> ...<br /> </host></dd></span><br /> // this actually worked, but we don't need appBase at all for CFM. the reason the first attempt above was screwing things up is that not setting 'autoDeploy' at all defaulted to 'true'. Setting it to false fixed the WEB-INF in the sub-directories, but it's still not right.<br /><br />Here is the RIGHT way:<span style="color: rgb(51, 51, 255);"><br /> <dd><host name="www.website1.com"><br /> <context path="" docbase="<b>/var/www/website1</b>"><br /> ...<br /> </host></dd></span><br /><br /><br />That's today's lesson learned.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-62456529343764356722011-12-09T11:52:00.001-08:002011-12-09T11:52:32.021-08:00Flexible Width Text Link as Buttons with Background Image (SOLVED)<p class="mobile-photo"><a href="http://2.bp.blogspot.com/-hiOUvzVxRmI/TuJnAIrR6JI/AAAAAAAAAGI/5N4YktgxiSE/s1600/trainmod-start-blank-wide-sprite-752022.png"><img src="http://2.bp.blogspot.com/-hiOUvzVxRmI/TuJnAIrR6JI/AAAAAAAAAGI/5N4YktgxiSE/s320/trainmod-start-blank-wide-sprite-752022.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5684218931721660562" /></a></p>The important part to note in the CSS below is the right margin on the <a> link tag - it's -20px. That beings in the right side so the :hover's work correctly. <br><br>When that is done another way the mouse over on one of the ends doesn't work and you get the background image shifting correctly on the end but not under the text. This way makes the link tag cover the entire span tag so both are always triggered on the native :hover state.<br> <br><br>THE HTML:<br> <br> <div style="margin-left: 40px;"><div class="button-container"><br> <span class="button-wrapper"><br> <a href="/fr/snapdragon-mobile-processor">Start</a><br> </span><br> </div><br> </div> <br><br>THE CSS:<br> <br> <div style="margin-left: 40px;">#block-views-training-module-listing-block-2 .views-field-nid .field-content {<br> background: url("images/trainmod-start-blank-wide-sprite.png") no-repeat scroll 0 0 transparent;<br> display: block;<br> float: left;<br> height: 30px;<br> position: relative;<br> /*width: 82px;*/<br> }<br> #block-views-training-module-listing-block-2 .views-field-nid a {<br> background: url("images/trainmod-start-blank-wide-sprite.png") no-repeat scroll 100% 0 transparent;<br> color: #666666;<br> display: block;<br> font-size: 14px;<br> font-weight: 600;<br> height: 30px;<br> line-height: 30px;<br> margin: 0 -20px 0 0;<br> padding: 0 30px 0 15px;<br> position: relative;<br> text-decoration: none;<br> /*width: 82px;*/<br> }<br> #block-views-training-module-listing-block-2 .views-field-nid .field-content:hover {<br> background-position: 0 100%;<br> }<br> #block-views-training-module-listing-block-2 .views-field-nid a:hover {<br> background-position: 100% 100%;<br> }<br></div><br><br>THE BACKGROUND IMAGE:<br><br><div style="margin-left: 40px;"><a href="http://1.bp.blogspot.com/-8fnyQhQOLgk/TuJnAepHhXI/AAAAAAAAAGQ/10NVUbxgDmA/s1600/trainmod-start-blank-wide-sprite-753104.png"><img src="http://1.bp.blogspot.com/-8fnyQhQOLgk/TuJnAepHhXI/AAAAAAAAAGQ/10NVUbxgDmA/s320/trainmod-start-blank-wide-sprite-753104.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5684218937618171250" /></a><br></div><br><br> <br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-25337822238161874682011-12-08T22:57:00.001-08:002011-12-09T09:07:27.736-08:00Update to Ubuntu Set Timezone PostJust another reminder on how to quickly set the local timezone on Ubuntu Server.<br /><br />I had blogged about this <a href="http://www.cfelements.com/2010/11/railo-java-timezone-issue.html">previously</a>, but I didn't make it simple enough even for myself, so this is a do-over.<br /><br /><br />Find your timezone specific file in <span style=""><span style="background-color: rgb(51, 51, 255);"><span style="background-color: rgb(255, 255, 255);"><span style="color:#3333ff;"><b>/usr/share/zoneinfo/America/</b></span></span></span></span>.<br /><br />Then run the following three commands:<br /><br /><div style="margin-left: 40px;"><span style=""><span style="background-color: rgb(51, 51, 255);"><span style="background-color: rgb(255, 255, 255);"><span style="color:#3333ff;"><b>$ cd /etc<br />$ mv localtime localtime_orig<br />$ ln -s /usr/share/zoneinfo/America/tzfilename localtime</b> </span></span></span></span></div><span style=""><span style="background-color: rgb(51, 51, 255);"><span style="background-color: rgb(255, 255, 255);"><span style="color:#3333ff;"><span style=""><span style="background-color: rgb(255, 255, 255);"><span style="color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);"><br />Reboot and you're set. Now java defaults to this timezone.<br /><br /></span></span></span></span></span></span></span></span><span style=""><span style="background-color: rgb(51, 51, 255);"><span style="background-color: rgb(255, 255, 255);"><span style="color:#3333ff;"><span style=""><span style="background-color: rgb(255, 255, 255);"></span></span></span></span></span></span><div style="margin-left: 40px;"> <span style=""><span style="background-color: rgb(51, 51, 255);"><span style="background-color: rgb(255, 255, 255);"></span></span></span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5957862346514573037.post-34308718676857029432011-11-29T14:12:00.001-08:002011-11-29T14:12:21.160-08:00Virtualbox - Mac Host - Ubuntu Guest - NetworkingMessing with this half the day... It's so simple I overlooked it and went down strange Google paths.<br clear="all"><br>This is the simple, straightforward answer to setting up networking for the Guest OS.<br><br>You set up two of the 4 possible network adapters <i>before</i> booting up the system. You can change the network settings while it's running and then run "sudo ifdown-a" and "sudo ifup-a", but that doesn't let you add a second adapter.<br> <br>Set "Adapter 1" as "NAT" - this <i>only</i> gives the GUEST OS outside internet access through the HOST. <br><br>Set "Adapter 2" as "Host-only Adapter" - this <i>only</i> gives the HOST access to the<br> <br>Together, we have what we want, we don't need anything fancy or custom, no bridgets, no scripts. But there is one tiny config setting that needs to be set to use the second adapter...<br><br><br>After you boot up the Ubuntu Linux server and log in you have to set up the second adapter in the interfaces config file because, by default, it only has one.<br> <br>It will look like this:<br><br><div style="margin-left: 40px;"># The loopback network interface<br>auto lo<br>iface lo inet loopback<br><br># The primary network interface<br>auto eth0<br>iface eth0 inet dhcp<br></div> <br><br>Now add this to the bottom:<br><br><div style="margin-left: 40px;"> # The primary network interface<br> auto eth1<br> iface eth1 inet dhcp<br></div><br>Now reboot.<br><br>Now when you run "ifconfig" you should see an ip address under "eth1". That is the IP address you can SSH to from the HOST machine.<br><br>YES! IT'S REALLY THAT SIMPLE!<br> <br><br> Unknownnoreply@blogger.com0