Skip to content

Instantly share code, notes, and snippets.

View paulakreuger's full-sized avatar

Paula Kreuger paulakreuger

  • @allihoopa
  • Stockholm
View GitHub Profile
@paulakreuger
paulakreuger / angular-filters.js
Last active October 18, 2023 19:34
Capitalize First Letter Filter - AngularJS
app.filter('capitalize', function() {
return function(input, scope) {
if (input!=null)
input = input.toLowerCase();
return input.substring(0,1).toUpperCase()+input.substring(1);
}
});
$browser-context: 16; // Default
@function em($pixels, $context: $browser-context) {
@return #{$pixels/$context}em
}
h1 {
font-size: em(21, 15); // Outputs 1.4em
}
@paulakreuger
paulakreuger / shorten-long-strings.js
Last active August 29, 2015 14:00
Shorten long strings
/*
==SHORTEN LONG STRINGS
-----------------------------------------------------*/
function truncateLongText(elem, maxwidth, sufix) {
if (elem === null) {
return '';
}
elem = String(elem);
var newElem;
if (elem.length > maxwidth) {
@paulakreuger
paulakreuger / functions.js
Created April 23, 2014 07:25
Check if is number
/*
==CHECK IF IS NUMBER
-----------------------------------------------------*/
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
@paulakreuger
paulakreuger / functions.js
Created April 22, 2014 14:21
Check if array contains variable
/* ==CHECK IF ARRAY CONTAINS VARIABLE
-----------------------------------------------------*/
function oc(a) {
var o = {};
for(var i=0;i<a.length;i++){
o[a[i]]='';
}
return o;
}
@paulakreuger
paulakreuger / get-json-data.js
Last active August 29, 2015 13:58
Get Json Data
/*
==GET JSON DATA
-----------------------------------------------------*/
function getData(url, callback, errorCallback, completeCallback) {
$.getJSON(url, function (data) {
log('success');
log(data);
callback(data);
}).error(function (data) {
log('error');
@paulakreuger
paulakreuger / functions.js
Last active August 29, 2015 13:58
Get URL Variables
/*==GET URL VARIABLES
-----------------------------------------------------*/
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m,key,value) {
vars[key] = value;
});
return vars;
}
@paulakreuger
paulakreuger / random_number.js
Last active August 29, 2015 13:57
Get a random number
/*
==GET A RANDOM NUMBER
-----------------------------------------------------*/
function randomNumber(min, max) {
return Math.ceil(Math.random() * (max - min) + min);
}
@paulakreuger
paulakreuger / esc.js
Created March 26, 2014 09:20
Escape Text
/*
==ESC
-----------------------------------------------------*/
function esc(text) {
if (typeof text !== 'string') {
text = String(text);
}
var html = text.split("&").join("&amp;").split("\"").join("&quot;").split("'").join("&#39;").split("<").join("&lt;").split(">").join("&gt;");
return html.replace(/\r?\n/g, '&#10;');
}
@paulakreuger
paulakreuger / functions.js
Last active August 29, 2015 13:57
Console Log Function
function log(msg) {
try {
if (typeof console !== 'undefined' && typeof console.log !== 'undefined') {
console.log(msg);
}
} catch (e) {}
}