Skip to content

Instantly share code, notes, and snippets.

View millermedeiros's full-sized avatar

Miller Medeiros millermedeiros

View GitHub Profile
@mahonnaise
mahonnaise / sprintf.js
Created June 8, 2011 04:38
sprintf utility function
var sprintf = function (text) {
var i = 1, args = arguments;
return text.replace(/%(0)?(\d*)?\.?(\d*)?(s|f)/g, function (pattern) {
var a = arguments,
precision = +a[3],
value = args[i++],
padSize = +a[2] - (~~value).toString().length,
padding = padSize > 0 ? (new Array(padSize + 1).join(a[1] || ' ')) : '';
return padding + (a[4] === 'f' && a[3] ? value.toFixed(+precision) : value);
});
define({
/*
* Simplified prototypal inheritance, see http://javascript.crockford.com/prototypal.html
*/
create: function (obj){
function F() {}
F.prototype = obj;
return new F();
},
@ryanflorence
ryanflorence / hasProperty.js
Created November 13, 2011 00:42
See if an object has a property
var has = function (obj, property) {
var tree = obj,
split = property.split('.'),
last = split.pop();
while (next = split.shift()) {
tree = tree[next];
if (tree === undefined) return false;
}
@nzakas
nzakas / namespace.js
Created December 6, 2011 19:14
A single global with a namespace method
//BSD Licensed
var YourGlobal = {
namespace: function(ns){
var parts = ns.split("."),
object = this,
i, len;
for (i=0, len=parts.length; i < len; i++) {
if (!object[parts[i]]) {
@nathansmith
nathansmith / file_input_example.css
Created December 9, 2011 14:56
Markup to Hide a File Input
.fake_file_input {
background: url(../images/fake_file_input.png) no-repeat;
cursor: pointer;
width: 150px;
height: 30px;
overflow: hidden;
position: relative;
display: inline-block;
*display: inline;
*zoom: 1;
@briancavalier
briancavalier / promisify.js
Created February 24, 2012 13:03
Turn callback-based functions into promise-based functions
var when = require('../when');
// A test callback-based function
function callbackBased(value, callback, errback) {
setTimeout(function() {
(value ? callback : errback)(value);
}, 100);
}
function log(val) {
@bga
bga / [fun] various forms of ternary operator in JavaScript.js
Created March 7, 2012 15:10
[fun] various forms of ternary operator in JavaScript
// add your variants of
a ? b : c
// in comments :)
// a is boolean
// b and c - any type
// lazy evaluation isnt important
@sjl
sjl / ffind.md
Created September 19, 2012 21:52
friendly-find

friendly-find

Brainstorming a friendlier find(1).

Usage

Goals:

@roboshoes
roboshoes / _cover-background.scss
Last active December 13, 2015 22:09
This let's you set a background image with background-size set to cover and have it working down to IE8 (I believe also IE7?!). It's based on SCSS and uses Compass (http://compass-style.org/). There is one little flaw: while the `url()` is reltive to the css file the filter is relative to the HTML document. The whole "../../" is not really clean…
@mixin cover-background( $path ) {
background-image: url( "../../" + $path );
@include background-size( cover );
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + $path + "', sizingMethod='scale')";
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="", sizingMethod="scale");
}
/*****************************************************************************
* __ __ _ _ ___ _
* \ \/ _\ /\/\ (_)_ __ | |_ _ _ / __\ __ ___ ___| |__
* \ \ \ / \| | '_ \| __| | | | / _\| '__/ _ \/ __| '_ \
* /\_/ /\ \ / /\/\ \ | | | | |_| |_| | / / | | | __/\__ \ | | |
* \___/\__/ \/ \/_|_| |_|\__|\__, | \/ |_| \___||___/_| |_|
* |___/
*
* Identifying and Eliminating Code Smells
*