Skip to content

Instantly share code, notes, and snippets.

View jerkovicl's full-sized avatar

Luka Jerković jerkovicl

View GitHub Profile
@jerkovicl
jerkovicl / Gulpfile.js
Last active August 29, 2015 13:56
Gulpfile to minify and concatenate the JavaScript files
// include gulp
var gulp = require('gulp');
// include plug-ins
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
//var imagemin = require('gulp-imagemin');
@jerkovicl
jerkovicl / index.html
Created February 26, 2014 08:54
paste.js demo
<!doctype html>
<html>
<head>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="paste.js"></script>
<meta charset="utf-8">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<title>paste.js</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.0/normalize.min.css" media="screen" rel="stylesheet" type="text/css" />
</head>
@jerkovicl
jerkovicl / View.html
Created February 28, 2014 08:29
JSON to HTML example
<script type="text/javascript">
$(document).ready(function () {
var sf = $.ServicesFramework(-1);
// Send an AJAX request
$.getJSON(sf.getServiceRoot('eTailer.NewProducts') + "NewProductsAPI/GetNewProducts?CategoryId=2&Top=10",
function (data) {
// On success, 'data' contains a list
$.each(data, function (key, val) {
// Format the text to display.
var pageres = require('pageres');
pageres(['todomvc.com'], ['1366x768', '1600x900'], function () {
console.log('done');
});
//via node.js command
/**
* Track JS error details in Universal Analytics
*/
function trackJavaScriptError(e) {
var errMsg = e.message;
var errSrc = e.filename + ': ' + e.lineno;
ga('send', 'event', 'JavaScript Error', errMsg, errSrc, { 'nonInteraction': 1 });
}
@jerkovicl
jerkovicl / AngularJS_snippets.md
Last active August 29, 2015 14:04
Collection of AngularJS snippets

AngularJS snippets

New feature in AngularJS 1.3.0

  • Strict DI – an option for finding places in your application that will not minify due to use of short-hand DI syntax

ng-app ng-strict-di

Angular code convention example

@jerkovicl
jerkovicl / AjaxRetryRequest.js
Last active August 29, 2015 14:05 — forked from aeurielesn/gist:2511005
Retrying a jQuery.ajax() call
$.ajax({
url: '/echo/error/',
async: true,
// retryCount and retryLimit will let you retry a determined number of times
retryCount: 0,
retryLimit: 10,
// retryTimeout limits the total time retrying (in milliseconds)
retryTimeout: 10000,
// timeout for each request
timeout: 1000,
@jerkovicl
jerkovicl / querySelector.md
Last active August 29, 2015 14:05
querySelector example
  • Syntax
element = document.querySelector(selectors);
  • Example
var select = document.querySelector;
var el = select("#id");
var el2 = select(".myclass");
@jerkovicl
jerkovicl / FunctionLogging.md
Last active August 29, 2015 14:06
Logging how long function took to run
  • Logging how long function took to run
var originalDoSomething = doSomething;
doSomething = function() {
  var startTime = new Date();
 // call the original version of the function
 var r = originalDoSomething.apply(this, arguments);
 var stopTime = new Date();
 console.log("Started at " + startTime + " and ended at " + stopTime);
@jerkovicl
jerkovicl / Object.observe.md
Created September 19, 2014 08:11
Object.observe example
// A model can be an object literal
var plainObject = {
  name: 'Counter',
  total: 0
};
 
// Define an observer method
function observer(changes){
 changes.forEach(function(change, i){