Skip to content

Instantly share code, notes, and snippets.

View cherihung's full-sized avatar

Cheri Hung cherihung

View GitHub Profile
@cherihung
cherihung / css3button-centered.scss
Created May 29, 2013 18:51
another css3 button version. separated out top-bottom and left-right padding values. a width is actually defined in the mixin. and button is centered relative to its parent element.
@mixin mybutton ($bgdcolor, $fontcolor: #ffffff, $font-size: 12px, $corner: 5px, $padding-tb: 5px , $padding-lr: 10px, $width: 100px) {
display: inline-block;
*display: inline;
color: $fontcolor;
font-size: $font-size;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
background-color: $bgdcolor;
background-image: url('http://d.cyhung.net/images/btn-overlay.png');
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
@cherihung
cherihung / stateArry.php
Last active December 16, 2015 20:19
simple array to generate a state dropdown.
<?php
// state options value
$statesarr = array(
"AL" => "Alabama",
"AK" => "Alaska",
"AZ" => "Arizona",
"AR" => "Arkansas",
"CA" => "California",
"CO" => "Colorado",
"CT" => "Connecticut",
@cherihung
cherihung / CalSumR.js
Created April 29, 2013 22:21
Google app script to use with google spreadsheets. Function calculating the occurance/count in a doc based 1 core (required) parameter and 3 optional parameters.
// CalSum Function with One Core Parameter and Three Optional Parameters
function calSumR(dR1,dP1,dR2,dP2,dR3,dP3,dR4,dP4) {
var count=dR1.length;
var t1= new RegExp(dP1);
var t2= new RegExp(dP2);
var t3= new RegExp(dP3);
var t4= new RegExp(dP4);
var s=0;
for (i=0;i<count;++i){
var v1=dR1[i][0];
@cherihung
cherihung / CalSumC.js
Last active December 16, 2015 19:29
Google app script to use with google spreadsheets. Function calculating the occurance/count in a doc based on 3 optional parameters.
// CalSum Function with Three Optional Parameters
function calSumC(dR1,dP1,dR2,dP2,dR3,dP3) {
var count=dR1.length;
var t1= new RegExp(dP1);
var t2= new RegExp(dP2);
var t3= new RegExp(dP3);
var s=0;
for (i=0;i<count;++i){
var v1=dR1[i][0];
var v2=dR2[i][0];
@cherihung
cherihung / scrollSwitch.js
Last active December 16, 2015 19:09
Sample code for adding/removing css class names according to a user's scrolling position on the page. example result is to change the background color of navigational items. $j for use with jQuery.noConflict();
$j(window).scroll(function(){
$navp = $j('#mm-nav');
$nav = $j('#mm-nav li a');
$navp = $j('#mm-nav');
$nav = $j('#mm-nav li a');
for(var i=1; i<8; i++) {
var os = i === 7 ? 190 : 90;
@cherihung
cherihung / smoothscroll.js
Last active December 16, 2015 19:09
$j for use with jQuery.noConflict(); smooth scrolling with anchor tags. reference http://css-tricks.com/snippets/jquery/smooth-scrolling/
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
$j('body a[href*=#]').each(function() {
var thisPath = filterPath(this.pathname) || locationPath;
@cherihung
cherihung / css3button.scss
Created April 5, 2013 18:03
SASS mixins to create gradient-like button in CSS3
@mixin mybutton ($bgdcolor, $fontcolor: #ffffff, $font-size: 12px, $corner: 5px, $padding: 5px 10px) {
display: inline-block;
*display: inline;
color: $fontcolor;
font-size: $font-size;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
padding: $padding;
background-color: $bgdcolor;
.fix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.fix
{
display: inline-table;
@cherihung
cherihung / css3arrows.less
Last active December 15, 2015 18:38
LESS mixins to draw left or right arrows in CSS3.
.rightArrow(@color, @alpha, @size) {
left: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: hsla(hue(@color), saturation(@color), lightness(@color), @alpha);
border-left-color: @color;