Skip to content

Instantly share code, notes, and snippets.

(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
Object.defineProperty(Function.prototype, '$inject', {
configurable: true,
get: function() {
return this.$injectHooked;
},
set: function (arr) {
if (arr.length && arr[0].length < 3) {
console.error('missing @ngInject:', this);
}
return this.$injectHooked = arr;
@nicolae-olariu
nicolae-olariu / iterate-n-items-angular
Created March 13, 2015 13:56
AngularJS iterate a finite number of times (10 times in this sample)
<div ng-app>
<div ng-repeat="n in [].constructor(10)">{{$index}}</div>
</div>
@nicolae-olariu
nicolae-olariu / dynamic-dropdown
Last active August 29, 2015 14:17
Dynamic dropdown rendered using AngularJS and select2 jquery plugin
<select
id="sampleId"
class="select2"
data-allow-clear="true"
data-placeholder="placeholderHere"
ng-model="sampleModel"
ng-options="entity.modelHere as entity.modelHere for entity in entities"
ng-selected="sampleModel == entity.modelHere">
</select>
@nicolae-olariu
nicolae-olariu / gist:421105b47c044d41df8e
Last active December 24, 2015 23:29
Detect mobile phone with javascript
// Assuming that a phone has a maximum (real) width of 480px or a maximum (real) height of 480px;
// http://stackoverflow.com/questions/14325577/iphone-5-screen-size-vs-css-media-query
var isMobileDevice = screen.width < 480 || screen.height < 480;
// Or use this solution
(function (a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)