Skip to content

Instantly share code, notes, and snippets.

View capaj's full-sized avatar
🏠
Always working-be it from home or elsewhere

Jiri Spac capaj

🏠
Always working-be it from home or elsewhere
View GitHub Profile
@capaj
capaj / gist:5805010
Created June 18, 2013 12:39
Count css rules
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@capaj
capaj / galleries.js
Created July 5, 2013 06:32
just listing files
var listFilesIn = function (name) {
var def = when.defer();
fs.readdir(basePath+name, function (err, files) {
if (err) {
def.reject(err);
}
var onlyfiles = [];
function checkIsFile(file, callback) {
// console.log("will check file: " + file);
@capaj
capaj / phantomBridge.js
Created July 9, 2013 11:17
phantomJS method to get raw HTML from SPA
var pjson = require('../package.json');
var log4js = require('log4js');
var sLogger = log4js.getLogger('server');
var bots = [
'+https://developers.google.com/+/web/snippet/', // Google+
'facebookexternalhit',
'Googlebot'
];
@capaj
capaj / example.html
Created July 11, 2013 09:34
showcase how on-change attribute parsing can help with updating the relevant objects on scope. Looking at it now, maybe instad of parsing on-change, we could change it to ng-change to align the name with angular.
<div ng-controller="langsCtrl">
<tr ng-repeat="lang in langsList">
<td>{{$index}}</td>
<td>
<div class="ade-editable" ade-text='{"className":"inputInTable"}'
ng-model="lang.lang_code" on-change='update(lang)'>{{lang.lang_code}}</div>
</td>
<td>
<div class="ade-editable" ade-text='{"className":"inputInTable"}'
ng-model="lang.alt" on-change='update(lang)'>{{lang.alt}}</div>
@capaj
capaj / array_methods.js
Last active December 24, 2015 17:49
helpful array methods- empty and contains, and property last
Object.defineProperty(Array.prototype, 'last', {
enumerable: false,
configurable: true,
get: function() {
return this[this.length - 1];
},
set: undefined
});
/**
@capaj
capaj / include-in-scope.js
Created October 10, 2013 16:15
ng include in the same scope
// same as ng-include, but it does not create it's own scope, if element already has a scope
angular.module('ng-tools').directive('includeInScope',
['$http', '$templateCache', '$anchorScroll', '$compile',
function ($http, $templateCache, $anchorScroll, $compile) {
return {
restrict: 'ECA',
terminal: true,
compile: function (element, attr) {
var srcExp = attr.includeInScope || attr.src,
onloadExp = attr.onload || '',
@capaj
capaj / gridster jsdoc comment
Created October 12, 2013 13:02
gridster jsdoc comment
/**
* @class Gridster
* @uses Draggable
* @uses Collision
* @param {HTMLElement} el The HTMLelement that contains all the widgets.
* @param {Object} [options] An Object with all options you want to
* overwrite:
* @param {HTMLElement|String} [options.widget_selector] Define who will
* be the draggable widgets. Can be a CSS Selector String or a
* collection of HTMLElements
@capaj
capaj / mquery-stringify.js
Last active December 27, 2015 11:09
just test
var forbidden = ['mongooseCollection', '_collection'];
module.exports = function (query) {
var copy = {};
for (var prop in query) {
if (forbidden.indexOf(prop) === -1) {
copy[prop] = query[prop];
}
}
return JSON.stringify(copy);
};
@capaj
capaj / mongoose middleware showcase
Last active December 27, 2015 13:29
a little exercise showing how to use mongoose middleware
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var blogSchema = new Schema({
title: String,
author: String,
body: String,
date: { type: Date, default: Date.now }
});
@capaj
capaj / gist:8314551
Created January 8, 2014 10:11
bootstrap nested rows with offset for comments
<div class="row show-grid">
<div class="col-md-12">
Parent comment
<div class="row show-grid">
<div class="col-md-1" style="visibility: hidden;">
</div>
<div class="col-md-11">
Child comment
</div>
</div>