Skip to content

Instantly share code, notes, and snippets.

View cherihung's full-sized avatar

Cheri Hung cherihung

View GitHub Profile
@cherihung
cherihung / sqlnotes
Last active March 13, 2017 00:55
handy SQL code snippets
//concatenante strings, column values
UPDATE table
SET column = CONCAT('text', columnname, 'text')
//lowercase values in one column
UPDATE table SET column = LOWER(column)
//update column value based on value matching to same column or different column
UPDATE table SET column = value WHERE column = value
UPDATE table SET column = value WHERE column IS NULL
@cherihung
cherihung / timelinejs_jumptime.js
Created March 15, 2013 05:02
to select by date (month, day, year) and jump to an event in TimelineJS
function jumpTime(type,value) {
var model = VMM.Timeline.DataObj.data_template_obj.timeline.date;
var x = -1; //
$(model).each(function(i,j) {
var currentDate = j.startDate.split('/');
if (currentDate[type] == value ) {
x++;
if (x == 0) {
window.location.hash = i+1 // +1 to accommodate title slide count
}
var that = this;
$(window).bind( 'hashchange', function(e) {
var new_hash_slide = location.hash.slice(1);
that.setSlide(new_hash_slide);
VMM.Timeline.Config.current_slide = new_hash_slide;
});
@cherihung
cherihung / changeParentHeight.js
Last active December 14, 2015 23:39
change parent window height as child iframe's height decreases/increases with user interaction
function() {
var content_h = $("#myframe", window.parent.document).contents().find("body").height();
$('#myframe', window.parent.document).css( "height", content_h+"px" );
}
@cherihung
cherihung / sitckyElement.js
Created March 18, 2013 20:43
make an element on page "stick" while rest of page scrolls
$(document).ready(function () {
$(window).scroll(function(e){
$element = $('#element-id');
var init_height = 250;
if ($(this).scrollTop() > init_height && $element.css('position') != 'fixed'){
$('#element-id').css({'position': 'fixed', 'top': '0px'});
} else if ($(this).scrollTop() < init_height && $element.css('position') == 'fixed'){
$('#element-id').css({'position': 'relative'});
}
});
@cherihung
cherihung / convert_engdate.php
Created March 19, 2013 16:31
convert date in english date format (YYYY-MM-DD) into another specified format
function convert_eng_date($date, $format) {
$return = date($format, strtotime($date));
return $return;
}
$newdate = convert_eng_date($olddate, "M. d, Y"); //format = Feb. 12, 2013
echo $newdate
@cherihung
cherihung / convert_date_to_obj.js
Created March 19, 2013 16:35
parse date string YYYY-MM-DD to a date object array; use to plot with amCharts
function parseDate(dateString) {
//first slice off hours and minutes; only take YYYY-MM-DD
var strip_date = dateString.slice(0,10);
var dateArray = strip_date.split("-");
// create instance year, month and day as parameters
var date = new Date(Number(dateArray[0]), Number(dateArray[1]) - 1, Number(dateArray[2]));
return date;
}
<?php
/*
* Converts CSV to JSON
* This is forked from @robflaherty's csv-to-json.php gist: https://gist.github.com/robflaherty/1185299
* Fork Modification $feed = $_GET["file"] to fetch feed url via a url variable https://gist.github.com/cherihung/5287225
*/
header('Content-type: application/json');
// Get CSV feed location in query string passed
@cherihung
cherihung / css3button.less
Last active December 15, 2015 18:38
LESS mixins to create gradient-like button in CSS3
.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;
@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;