Skip to content

Instantly share code, notes, and snippets.

View felixzapata's full-sized avatar

Félix Zapata felixzapata

View GitHub Profile
@felixzapata
felixzapata / gist:3857104
Created October 9, 2012 07:06
Media Queries for Standard Devices
/*
http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
*/
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@felixzapata
felixzapata / gist:3863904
Created October 10, 2012 07:56
CSS media query to target iPad and iPad only
/*
* http://stackoverflow.com/questions/8271493/css-media-query-to-target-ipad-and-ipad-only
*/
@media all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait) {
.ipad-portrait { color: red; } /* your css rules for ipad portrait */
}
@media all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape) {
.ipad-landscape { color: blue; } /* your css rules for ipad landscape */
}
@felixzapata
felixzapata / gist:3968336
Created October 28, 2012 11:06
How to line wrap text in legend elements, even in IE
/* http://www.456bereastreet.com/archive/201210/how_to_line_wrap_text_in_legend_elements_even_in_ie/ */
legend {
display:table; /* Enable line-wrapping in IE8+ */
white-space:normal; /* Enable line-wrapping in old versions of some other browsers */
}
@felixzapata
felixzapata / gist:3978711
Created October 30, 2012 07:02
Enables keyboard functionality for both keyboard and screen reader users in a Google Map
setTimeout(function(){
$(MapNode).find('div[title="Show street map"], div[title="Show street map
with terrain"], div[title="Show satellite imagery"], div[title="Zoom in to
show 45 degree view"], div[title="Show imagery with street names"],
div[title="Pan up"], div[title="Pan down"], div[title="Pan left"],
div[title="Pan right"], div[title="Return to the last result"],
div[title="Zoom in"], div[title="Zoom out"], img[title="Rotate map 90
degrees"]').each(function(i, o){
$(o).attr({
role: 'button',
@felixzapata
felixzapata / gist:4094723
Created November 17, 2012 10:27
use an efficient for loop as there may be a lot to cycle through
var i, len = titles.length;
for(i = len-1; i >- 1; i--){
}
@felixzapata
felixzapata / gist:4098274
Created November 17, 2012 18:01
how to empty an array in JavaScript
// http://stackoverflow.com/questions/1232040/how-to-empty-an-array-in-javascript
// related: Splicing is the worst by far: http://jsperf.com/emptying-arrays/4
matrix.splice(0,matrix.length);
@felixzapata
felixzapata / gist:4339343
Created December 19, 2012 18:53
How to determine if a number is odd in JavaScript
// http://stackoverflow.com/questions/5016313/how-to-determine-if-a-number-is-odd-in-javascript
function oddOrEven(x) {
return ( x & 1 ) ? "odd" : "even";
}
@felixzapata
felixzapata / gist:4550829
Created January 16, 2013 20:50
JavaScript tips: cadena aleatoria
// http://www.yeikos.com/2013/01/javascript-tips-cadena-aleatoria.html
Math.random().toString(36).substring(2); // 9xfq8ssn2hjjor
@felixzapata
felixzapata / gist:5106824
Created March 7, 2013 09:45
Pila de funciones
function Stack(stackLimit)
{
this.stack = new Array();
this.stackLimit = stackLimit;
}
Stack.prototype.isEmpty = function()
{
return (this.stack.length == 0);
}
@felixzapata
felixzapata / gist:5343817
Created April 9, 2013 07:57
Averiguamos el más alto de filas de n elementos
function controlHeight(elems, num){
var len = elems.length;
if(len !== 0){
for(var i = 0; i < len; i+=num) {
var divs = elems.slice(i, i+num),
height, numArray = [];
for(var j = 0; j < num; j++){
numArray.push(divs.eq(j).height());
}
height = Math.max.apply(null, numArray);