Skip to content

Instantly share code, notes, and snippets.

@phantom42
phantom42 / let's deal
Last active December 13, 2015 23:39
indexed arrays - putting it all together
//here's our players array from exercise 1
var players = [];
players[0] = {'name': 'Robert', hand: []};
players[1] = {'name': 'Joe', hand: []};
//here's our code to create the deck
var suits = ['clubs','diamonds','hearts','spades'];
var ranks = [2,3,4,5,6,7,8,9,10,'J','Q','K','A'];
var deck = [];
for (var i=0;i<suits.length;i++) {
@phantom42
phantom42 / reset form.js
Last active December 11, 2015 19:49
jquery to reset form
$("#clear").click(function(e){
$('#contactForm')[0].reset();
});
@phantom42
phantom42 / __static sidebar.txt
Last active December 11, 2015 19:48
static sidebar nav menu using bootstrap credit to Andres Ilich http://stackoverflow.com/a/9351158/1147918
this creates a static sidebar with regularly scrolling content on the left side - no frames
<cfscript>
randssn = '';
seed = timeformat(now(),'hhmmssl');
Randomize(seed);
randssn = randrange(1,9) ; // make it so the first digit is never a 0. in case it is going into a spreadsheet.
for (i = 1; i LTE 8 ; i++){
randssn = randssn & randrange(0,9) ;
}
</cfscript>
<cfscript>
param name='arguments.length' default=10 ;
pool = 'abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ;
newTicket = '' ;
for (i=1 ; i lte arguments.length; i=i+1) {
newTicket &= mid(pool, randRange(1, len(pool)),1);
}
</cfscript>
@phantom42
phantom42 / css thumbnail
Last active December 10, 2015 14:19
css thumbnail class set to maintain aspect ratio
img.resize{height:80px;width:auto;}
img.resize{height:auto;width:80px;}
@phantom42
phantom42 / basic photoswipe
Created January 3, 2013 20:59
basic implementation of gallery displaying all jpgs in a folder
<cfscript>
currentDir = getDirectoryFromPath(getTemplatePath()) ;
currentfile = lcase(getFileFromPath(getTemplatePath()));
fileList = directoryList(currentDir,false,'query','*.jpg','asc') ;
</cfscript>
<!DOCTYPE html>
<html>
<head>
<title>PhotoSwipe</title>
@phantom42
phantom42 / oracle updatedby trigger issue
Created January 2, 2013 20:23
template code to deal with the following discovered behavior -table rows were being updated without explicitly setting the updatedby value -:NEW reads the existing value of background_inv.updatedby and uses that to insert into the history table -this would create history logs associated with the incorrect user
CREATE OR REPLACE TRIGGER TIUD_BACKGROUND_INV
AFTER DELETE OR INSERT OR UPDATE
ON BACKGROUND_INV REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_new_updated_by := background_inv.updatedby%type ;
BEGIN
IF updating THEN
@phantom42
phantom42 / update_select
Created December 13, 2012 16:27
oracle update column with select from other table. http://www.sqlfiddle.com/#!4/ee7da/2306
UPDATE destTable d
SET d.column = (select column from sourceTable where id = [id])
WHERE [id] = 1
;
@phantom42
phantom42 / cfscript qoq
Created December 12, 2012 14:22
the basic setup of a cfscript version of a query of queries.
// cfscript method of a query of queries
// there seems to be no supported way to create a qoq using the more common queryNew() cfscript
local.qoqObj = new Query(dbtype='query', sql="select * from qrySource where [sql conditional] ") ; // qrySource is an attribute set below
local.qoqObj.setAttributes(qrySource=local.actualSourceQuery) ; //
local.qryQoqResults = local.qoqObj.execute().getResult() ;