Skip to content

Instantly share code, notes, and snippets.

@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)
@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 / 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>
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;
(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(": ");
@nicolae-olariu
nicolae-olariu / Fix node path
Created November 16, 2015 09:17
Fixing /usr/bin/env: node: No such file or directory issue
sudo ln -fs /usr/bin/nodejs /usr/local/bin/node
@nicolae-olariu
nicolae-olariu / gist:e81177a945b49cae2999
Created November 19, 2015 09:44 — forked from AndreasMadsen/gist:2693051
base64 shim [atob, btoa]
// Source: http://code.google.com/p/gflot/source/browse/trunk/flot/base64.js?r=153
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
@nicolae-olariu
nicolae-olariu / gist:b948fd7d51d56ecebfc9
Created December 16, 2015 09:17
Ignore files from gitignore that were previously versioned
git rm --cached <file>
@nicolae-olariu
nicolae-olariu / _decimal.scss
Created December 22, 2015 11:09 — forked from terkel/_decimal.scss
Rounding decimals in Sass
// _decimal.scss | MIT License | gist.github.com/terkel/4373420
// Round a number to specified digits.
//
// @param {Number} $number A number to round
// @param {Number} [$digits:0] Digits to output
// @param {String} [$mode:round] (round|ceil|floor) How to round a number
// @return {Number} A rounded number
// @example
// decimal-round(0.333) => 0
@nicolae-olariu
nicolae-olariu / clipboard-copy.js
Created March 9, 2016 13:25
add read more at address clipboard
function addLink(event) {
event.preventDefault();
var pagelink = '\n\n Read more at: ' + document.location.href,
copytext = window.getSelection() + pagelink;
if (window.clipboardData) {
window.clipboardData.setData('Text', copytext);
}
}