Skip to content

Instantly share code, notes, and snippets.

@yagopv
yagopv / gist:8557026
Created January 22, 2014 11:12
Order array Javascript
// Simple
array.sort(function(a,b){
a = new Date(a.date);
b = new Date(b.date);
return a<b?-1:a>b?1:0;
});
// Generic
(function(){
if (typeof Object.defineProperty === 'function'){
@yagopv
yagopv / gist:8470185
Last active August 12, 2022 09:28
Wordpress Snippets

###Custom Post Types

Docs

function codex_custom_init() {
  $labels = array(
    'name'               => 'Books',
    'singular_name'      => 'Book',
    'add_new'            => 'Add New',
@yagopv
yagopv / gist:8470162
Created January 17, 2014 08:35
Angular Snippets
// Modules
var shoppingModule = angular.module('ShoppingModule', ['moduleDependency1', 'moduleDependency2']);
// Controllers
shoppingModule.controller("HomeController", ["$scope", "$resource",
function($scope, $resource) {
}
]);
@yagopv
yagopv / gist:8452525
Last active January 3, 2016 10:58
JavaScript Inheritance
//**************************************************************
var Vehicle = (function(){
function Vehicle(model, year, engineSize) {
this.model = model;
this.year = year;
this.engineSize = engineSize;
var engineIsStarted = false;
this.isStarted = function () { return engineIsStarted; }
this.start = function () { engineIsStarted = true; }
this.stop = function () { engineIsStarted = false; }
@yagopv
yagopv / gist:6972385
Created October 14, 2013 08:01
Scrollbars
/* Let's get this party started */
::-webkit-scrollbar {
width: 5px;
}
WebKit
______
Set overflow : scroll; !!
@yagopv
yagopv / gist:6838774
Created October 5, 2013 09:28
Sample URL Rewrite rules
<rewrite>
<rules>
<rule name="Default" stopProcessing="true">
<match url="^(?!Content|Scripts|favicon|robots|App|api|breeze|sitemap.xml).*" />
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
@yagopv
yagopv / gist:6424994
Created September 3, 2013 14:54
Automatic textarea resizing
textarea {
resize: vertical;
overflow-y: hidden; /* prevents scroll bar flash */
padding-top: 1.1em; /* prevents text jump on Enter keypress */
}
// Automatic resizing for textareas
// auto adjust the height of
$(document).on('keyup', 'textarea', function (e) {
@yagopv
yagopv / gist:6377028
Created August 29, 2013 11:42
Ensure ellipsis
.ellipsis {
overflow: hidden;
height: 100px;
line-height: 25px;
}
.ellipsis:before {
content:"";
float: left;
width: 5px;
@yagopv
yagopv / gist:5857888
Created June 25, 2013 11:50
Deferred object
var a = $.Deferred(function(dfd) {
setTimeout(function() {
//dfd.resolve();
dfd.reject();
},5000);
}).promise();
a.then(function() {
alert("success");
}).fail(function() {
@yagopv
yagopv / gist:5715691
Created June 5, 2013 17:34
Vertical align boxes
.h-vcenter-parent {
display: table;
}
.h-vcenter-child {
display: table-cell;
vertical-align: middle;
}