Skip to content

Instantly share code, notes, and snippets.

View nicholasdunbar's full-sized avatar

Nicholas Dunbar nicholasdunbar

View GitHub Profile
@nicholasdunbar
nicholasdunbar / action_url_edit.php
Last active August 29, 2015 13:56
For Drupal 6 change the action URL in an exposed form in a block. You can see the full article on how to use this code at http://www.actionscript-flash-guru.com/blog/47-exposed-form-in-block-change-the-action-url-drupal-6-views-hookformalter.php
function category_content_type_form_alter(&$form, $form_state, $form_id)
{
if($form_id == 'views_exposed_form') {
$form['q']['#value'] = 'taxonomy/term/19';
//if you want to change the root value you can do it with action
//$form['#action'] = '/';
}
}
@nicholasdunbar
nicholasdunbar / vhosts_example.apacheconf
Last active August 29, 2015 13:56
An example of an Apache configuration that allows you to replace www with a subdomain. For instance if you wanted to remove www and put your own word on it. The full article that explains how to do it can be found here: http://www.actionscript-flash-guru.com/blog/49-replace-www-with-a-subdomain-xampp-mac-localhost.php
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
@nicholasdunbar
nicholasdunbar / ad_module_fix.php
Last active August 29, 2015 13:56
In the Drupal 6 Ad module, Advertisements I was having the following problem user warning: Duplicate entry '32-0' for key 'PRIMARY' query: INSERT INTO ad_priority (aid, priority) VALUES(32, 0) in /data/www/flash_guru.localhost/sites/all/modules/ad/channel/ad_channel.module on line 710. See the article (http://www.actionscript-flash-guru.com/blog…
//I changed the function from the following:
function _ad_channel_save_node($node) {
// delete old channel information, then add new
db_query('DELETE FROM {ad_channel_node} WHERE nid = %d', $node->nid);
$channels = _ad_channel_get_enabled($node);
foreach ($channels as $chid) {
db_query('INSERT INTO {ad_channel_node} (chid, nid) VALUES(%d, %d)', $chid, $node->nid);
}
if (user_access('configure ad premier status')) {
@nicholasdunbar
nicholasdunbar / serialize_class_to_db.php
Last active August 29, 2015 13:56
Example of how to serialize a PHP class to a database automatically each time it is modified. For an article on how to use this class see http://www.actionscript-flash-guru.com/blog/51-automatically-save-php-class-to-database-php-object-mapping.php
<?php
/**
* Dining Room Model and Datastore layer
* @author nicholasdunbar
*
*/
define('DB_NAME', 'test');
define('DB_USER', 'root');
@nicholasdunbar
nicholasdunbar / convertHrsMinSec2HrsDec.js
Last active August 29, 2015 13:56
Script for Google Docs Spreadsheet to convert Hours:Minutes:Seconds format to a decimal in hours. It can be used to convert data imported from toggl.com. More on how to use it here: http://www.actionscript-flash-guru.com/blog/52-convert-times-to-decimal-google-scripts-spreadsheets-toggl.php
function hours_to_dec() {
//these are all the variables we are using with an indicator of each's type.
// reference to active spreadsheet object
var ss = {};
// which sheet in the spreadsheet object will we be using
@nicholasdunbar
nicholasdunbar / detectIframe.html
Last active August 29, 2015 13:56
Detect if the page is loaded in an iframe with JavaScript
//here is a simple example on how to detect your content is running in an IFRAME
<script type="text/javascript">
if(location.href != top.location.href){ alert('the content has been loaded into an IFRAME');}
</script>
@nicholasdunbar
nicholasdunbar / arrayRemoveRedundant.as
Created February 4, 2014 21:20
Remove redundant items from an array in ActionScript 3.0 AS3
var foundIndex:int;
if (theArray && theArray.length > 0){
var len:int = theArray.length;
for (var i:int; i &lt; len; i++){
if (i+1 < len){
foundIndex = theArray.indexOf(theArray[i], i+1);
} else {
foundIndex = -1;
@nicholasdunbar
nicholasdunbar / RGB.as
Created February 4, 2014 21:24
Convert uint to a 6 digit RGB hex without using tostring(16) in ActionScript 3.0 AS3. For more information visit the following article: http://www.actionscript-flash-guru.com/blog/36-uint-to-6-digit-rgb-hex-actionscript-30-as3.php
public class RGB
{
//r the red channel
public var r:uint;
//the green channel
public var g:uint;
//the blue channel
public var b:uint;
/**
@nicholasdunbar
nicholasdunbar / mixColors.as
Last active August 29, 2015 13:56
A menthod for mixing colors in ActionScript 3.0 (AS3) A function that will mix 10% of one color with another. For instance you would use this if you wanted to add white or black to a color as a way of brightening or darkening it. If you wanted to mix blue with red to get purple etc. etc.
//requires the RGB class which can be found at the following link:
//https://gist.github.com/nicholasdunbar/8812643
//layerToTint.transform.colorTransform has to initialized to some color before this will work.
function addColorToLayer(layerToTint:DisplayObject, hexVal:String):void{
var colorTransform:ColorTransform = new ColorTransform();
var newColor:uint;
var rgb:RGB = new RGB();
var rgb2:RGB = new RGB();
var rgb3:RGB = new RGB();
@nicholasdunbar
nicholasdunbar / ScrollBarLite.as
Created February 4, 2014 21:47
Scrollbar in ActionScript 3.0 AS3 without a dependency on the Flex UI libraries. For more information on how to use this class go to the following URL: http://www.actionscript-flash-guru.com/blog/38-scrollbar-in-actionscript-30-as3--light-weight-and-simple-without-flex.php
package
{
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
public class ScrollBarLite {