Skip to content

Instantly share code, notes, and snippets.

View scodx's full-sized avatar
🏠
Working from home

Oscar Sánchez scodx

🏠
Working from home
View GitHub Profile
@scodx
scodx / trim.js
Created March 23, 2012 22:55
trim in JavaScript
/**
* Set of funcitons that trims a string in Javascipt :)
**/
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
return stringToTrim.replace(/^\s+/,"");
}
@scodx
scodx / _mem.php
Created April 3, 2012 23:55
memoria usada en un request de php :)
<?php
function _mem($val = null)
{
$val = ($val) ? $val : memory_get_peak_usage(true)
$unit=array('B','KB','MB','GB','TB','PB');
return @round($val/pow(1024,($i=floor(log($val,1024)))),2).' '.$unit[$i];
}
echo _mem();
@scodx
scodx / eval-alternatives
Created August 16, 2012 20:09
EVAL() IS EVIL!!!!!!
Most times you can get a reference to an object using document.getElementById("myID"). However, there are certain situations where an alternate method is required. For example, if there is no ID because the object you are trying to retrieve isn't an HTML element and perhaps the name of the object isn't known until run-time.
If the object name is known at design-time, you can easily refer to the object using dot notation. Dot notation is a way to traverse the Document Object Model (DOM) to find the object you're looking for. For example:
CODE
document.formName.fieldName.value
What you may not be aware of is that you can also refer to objects like you would with an associative array:
CODE
document.formName["fieldName"].value
Or:
@scodx
scodx / gist:5921785
Created July 3, 2013 19:09
Limpia cadenas de caracteres en js
var normalize = (function() {
var from = "ÃÀÁÄÂÈÉËÊÌÍÏÎÒÓÖÔÙÚÜÛãàáäâèéëêìíïîòóöôùúüûÑñÇç",
to = "AAAAAEEEEIIIIOOOOUUUUaaaaaeeeeiiiioooouuuunncc",
mapping = {};
for(var i = 0, j = from.length; i < j; i++ )
mapping[ from.charAt( i ) ] = to.charAt( i );
return function( str ) {
var ret = [];
// en jquery...
var newObj = jQuery.extend(true, {}, oldObj),
// en js...
http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
@scodx
scodx / git tips.sh
Last active December 20, 2015 16:49
Git TIPS
# Mensajes de los commits entre fechas por usuario :)
git log --pretty=format:'%s' --author='oscar' --since "JUL 29 2010" --until="JUL 10 2013" ;
# Reset a commit (con remote repo incluido :))
git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit
@scodx
scodx / gist:6530312
Created September 11, 2013 21:56
PATH de php en OSX
The OSX PHP is located in /usr/bin/php and /usr/bin is in PATH variable by default.
One way to make OSX use MAMP PHP is to add /Applications/MAMP/bin/php/php5.x.x/bin/ to your PATH variable (before /usr/bin):
Simply edit ~/.profile (ie. open Terminal.app, type vim ~/.profile) and add the following line to end of the file:
export PATH=/Applications/MAMP/bin/php/php5.x.x/bin/:$PATH
Note that you should replace xs in php5.x.x with the MAMP Pro PHP version
@scodx
scodx / browser.detect.js
Last active December 23, 2015 10:49
Browser detect JS
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
@scodx
scodx / horizontal_scroll.js
Created September 19, 2013 14:50
detect horizontal scroll in js
var lastScrollLeft = 0;
$(window).scroll(function() {
var documentScrollLeft = $(document).scrollLeft();
if (lastScrollLeft != documentScrollLeft) {
console.log('scroll x');
lastScrollLeft = documentScrollLeft;
}
});

Mac web developer apps

This gist's comment stream is a collection of webdev apps for OS X. Feel free to add links to apps you like, just make sure you add some context to what it does — either from the creator's website or your own thoughts.

— Erik