1StopCoders

Code Examples and Industry News

SASS Font Face Mixin

SASS - 0 Comments - Created by Casey Martin: 2014-05-16 17:02:00

@mixin font-face($style-name, $file, $family, $category:""){
	$filepath: "/root/_fonts/" + $file;
	@font-face {
		font-family: "#{$style-name}";
		src: url($filepath + ".eot");
		src: url($filepath + ".eot?#iefix") format('embedded-opentype'), url($filepath + ".woff") format('woff'), url($filepath + ".ttf")  format('truetype'), url($filepath + ".svg#" + $style-name + "") format('svg');
	}

	%#{$style-name} {
		font: {
			@if $category != "" {
				family: "#{$style-name}", #{$category};
			}
			@else {
				family: "#{$style-name}";
				weight: normal;
			}
		}
	}
}
Example usage:
@include font-face(omnes, 'omnes-regular-webfont', 'omnes', 'serif');


SASS Gradient Background Mixin

SASS - 0 Comments - Created by Casey Martin: 2014-05-16 17:01:00

$vendors: "-moz-", "-webkit-", "-o-", "";
$msvendors: "-ms-", "";

@mixin gradient($from, $to) {
  	background-color: $to;
	background: -webkit-gradient(linear, left top, left bottom, from($from), to($to));
	@each $vendor in $vendors {
		background: #{$vendor}linear-gradient(top,  $from, $to);
	}
  	filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
}


SASS Rounded Corners Mixin

SASS - 0 Comments - Created by Casey Martin: 2014-05-16 16:59:00

$vendors: "-moz-", "-webkit-", "-o-", "";
$msvendors: "-ms-", "";

@mixin rounded($radius: 4px) {
	@each $vendor in $vendors {
 		#{$vendor}border-radius: $radius;
 	}
}


SASS Box Shadow Mixin

SASS - 0 Comments - Created by Casey Martin: 2014-05-16 16:54:00

$vendors: "-moz-", "-webkit-", "-o-", "";
$msvendors: "-ms-", "";

@mixin box-shadow($top, $left, $blur, $color, $inset: false) {
	@if $inset {
    	@each $vendor in $vendors {
			#{$vendor}box-shadow:inset $top $left $blur $color;
		}
  	} @else {
    	@each $vendor in $vendors {
			#{$vendor}box-shadow: $top $left $blur $color;
		}
  	}
	@each $vendor in $msvendors {
		#{$vendor}filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=180, Color='#000000')";
	}
}


ColdFusion Function to Generate a Random String

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:18:00

This ColdFusion function generates a random string:

   	
	
    
    
    
    
        
        
        
    
    


Return Multiple Variables in a ColdFusion Function

ColdFusion - 1 Comment - Created by Casey Martin: 2014-05-10 20:18:00

To return multiple variables, you will need to create a struct. In the example below, we have a struct named "data", which returns the variables "data.success" and "data.message".

 

    
     
     
    
    
    
     
 


Hello World in ColdFusion

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:17:00

ColdFusion uses tags, similar to HTML. We are using two tags below, cfset and cfoutput. Cfset sets a variable equal to a value. And cfoutput outputs the variable.



Hello World



#message#



Hello World in PHP

PHP - 0 Comments - Created by Casey Martin: 2014-05-10 20:17:00

To output PHP code, you start with . The keyword echo will output text or html. The contents of the echo must be wrapped in quotes and end with a semicolon.

echo "

Hello World

";


ColdFusion Captcha with CFImage and Javascript Val

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:15:00

This is the ColdFusion code that contains a textbox and captcha image. It uses the cfimage tag to generate the captcha image.



This Javascript function converts a string to hash.
hashCode = function(str){
    var hash = 0;
    if (str.length == 0) return hash;
        for (i = 0; i < str.length; i++) {
                char = str.charCodeAt(i);
                hash = ((hash<<5)-hash)+char;
                hash = hash & hash;
        }
    return hash;
}
This Javascript function validates the entered text against the text in the image.
document.getElementById('captchaHashJS').value = hashCode('#captcha#');
function verifyCaptcha() {
    var captchaHash = document.getElementById('captcha').value;
    captchaHash = captchaHash.toUpperCase();
    captchaHash = hashCode(captchaHash);
    
    var captchaHashJS = document.getElementById('captchaHashJS').value;

    if (captchaHash != captchaHashJS) {
        alert("The value you entered for the captcha is incorrect.");
        window.setTimeout(function () { 
            document.getElementById('captcha').focus(); 
        }, 0); 
        return false;
    }
}


Alternating Row Colors with ColdFusion

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:14:00

Alternating row colors in ColdFusion is easy. The magic happens with one line of code in the cfoutput of the query.


         SELECT FirstName, LastName
         FROM Users



    
FirstName LastName
#FirstName# #LastName#


Display Query Results Using PHP Function Var_Dump

PHP - 0 Comments - Created by Casey Martin: 2014-05-10 20:13:00

To display MySQL query results in PHP, you can use var_dump(). Here's an example:

$sql = mysql_query("SELECT * FROM your_table WHERE key = 'value'");
$assoc = mysql_fetch_assoc($sql);

// Dump variable containing the result of the MySQL query
var_dump($assoc);


Creating a Static Page with CakePHP

CakePHP - 0 Comments - Created by Casey Martin: 2014-05-10 20:11:00

In this example, we are going to create a sample About Us page. Write some text and save it as about_us.ctp. Static pages must be saved with a ".ctp" file extension, and rather than spaces, use underscores.

To set a page title, add the following line to your file:

$this->pageTitle = 'About Us';


To view the page, go to the following URL:
http://yourdomain.com/pages/about_us

If you would like to shorten the URL to exclude "pages", add the following line to app/config/routes.php:
Router::connect('/about_us', array('controller' => 'pages', 
'action' => 'display', 'about_us'));


Using PHP Function Strip_Tags to Remove HTML

PHP - 0 Comments - Created by Casey Martin: 2014-05-10 17:12:00

Use strip_tags() to remove html from a string.

$htmlvariable = "Is this bold?";
echo strip_tags($htmlvariable);