Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle Florence kflorence

  • Solar Mosaic, Inc.
  • Austin, Texas
View GitHub Profile
@kflorence
kflorence / empx.js
Last active Dec 16, 2015
Convert from em to px and vice versa.
View empx.js
function unit( scope ) {
return parseInt( window.getComputedStyle( scope || document.body ).fontSize, 10 );
}
function pxToEm( px, scope ) {
return ( parseInt( px, 10 ) / unit( scope ) ).toFixed( 8 ) + 'em';
}
function emToPx( em, scope ) {
return Math.round( parseFloat( em ) * unit( scope ) ) + 'px';
@kflorence
kflorence / .gitconfig
Last active Apr 26, 2018
Useful config settings
View .gitconfig
[alias]
br = branch
ci = commit
cl = clone
co = checkout
cp = cherry-pick
df = diff
lg = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
mg = merge --no-ff
pl = pull --rebase
View update-config.sh
# Put this in ~/.bash_profile on your devbox
# Run it like: $ update-config
function update-config {
echo "Updating config..."
cd /usr/wikia/docroot
git pull --rebase
mkdir -p wiki.factory
ln -sf /usr/wikia/source/wiki/extensions/wikia/Development/Configs_DevBox/LocalSettings.php wiki.factory/LocalSettings.php
perl /usr/wikia/docroot/clinks.pl --source=/usr/wikia/source/wiki --docroot=/usr/wikia/docroot/wiki.factory
@kflorence
kflorence / join.js
Created Jan 1, 2013
Simple function for joining non-Array object properties
View join.js
// join( { one: "one", two: "two" } );
// => "one,two"
function join( obj, separator ) {
var k,
items = [];
if ( typeof obj.join === "function" ) {
items = obj;
} else {
@kflorence
kflorence / namespacer.js
Last active Dec 10, 2015
A simple function for namespacing things like events and class names
View namespacer.js
// namespacer( "kf", [ "one", "two" ] );
// => { one: "one.kf", two: "two.kf" }
function namespacer( namespace, items, separator, before ) {
var i, item,
l = items.length,
namespaced = {};
if ( l && namespace ) {
if ( !separator ) {
separator = ".";
@kflorence
kflorence / getType.js
Created Aug 29, 2012
Enhanced version of jQuery.type that will return class names for user generated Objects
View getType.js
var getType = (function() {
var rFunctionName = /function ([^(]+)/;
return function( object ) {
var matches,
type = $.type( object );
if ( type == "object" ) {
matches = rFunctionName.exec( object.constructor.toString() );
@kflorence
kflorence / scrollbarWidth.js
Created Jul 10, 2012
Calculate scroll bar width cross-browser
View scrollbarWidth.js
function getScrollBarWidth() {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";
var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
@kflorence
kflorence / exec.js
Created May 15, 2012
Call a function only if it is defined
View exec.js
var exec = (function(global) {
return function(name, args, context) {
var func = (context = context || global)[name];
return (typeof func != 'undefined') && func.apply(context, args);
};
})(this);
// Use like:
var timesTwo = function(x) {
return x * 2;
View clearfix.css
.clearfix {
height: 1%; /* trigger hasLayout for IE < 8 */
}
.clearfix:before, .clearfix:after {
content: " ";
display: block;
height: 0;
visibility: hidden;
}
@kflorence
kflorence / arrow.scss
Created Apr 2, 2012
@mixin arrow($color, $width)
View arrow.scss
/*
HTML: <img class="arrow" src="<?= $wg->BlankImgUrl ?>" />
SASS: .arrow { @include arrow(); }
*/
@mixin arrow($width: 4px, $color: black, $direction: 'down') {
border-color: transparent;
// Fixes the 'jagged line' problem for modern browsers
// See: http://css-tricks.com/snippets/css/css-triangle/#comment-108252
border-color: rgba($color, 0);