Skip to content

Instantly share code, notes, and snippets.

View kmaida's full-sized avatar

Kim Maida kmaida

View GitHub Profile
@kmaida
kmaida / expireCookie.js
Created February 26, 2014 16:10
This function finds the user's local date/time converted from EDT at a set time in the future. Useful for expiring cookies on a regular basis. By default, expires cookie once-per-day at 12:01 AM EDT the next day, every day. Modify offsets accordingly.
function findLocalExpTime() {
var curTime = new Date(),
expTime = new Date(),
baseZoneOffset = 4, // Base timezone offset from UTC (4 in this example for EDT, change as appropriate)
tmpYear = curTime.getUTCFullYear(),
tmpMonth = curTime.getUTCMonth(),
tmpDate = curTime.getUTCDate(),
tmpHrs = curTime.getUTCHours(),
tmpMin = curTime.getUTCMinutes(),
localTime;
@kmaida
kmaida / matchmediacheck.js
Last active August 29, 2015 13:57
Function to check if matchMedia is supported; if so, use it, otherwise, use JS window width calculation (fixes issues with -webkit browsers returning incorrect window widths due to scrollbars)
function getviewport() {
var win = window,
matchMediaSupported = (win.matchMedia || win.msMatchMedia),
viewport;
if (matchMediaSupported) {
if (win.matchMedia('screen and (min-width: 641px)').matches) {
viewport = 'large';
} else {
viewport = 'small';
@kmaida
kmaida / resourceUrlWhitelist.js
Last active August 29, 2015 14:11
AngularJS 1.2+ - Config to whitelist subdomains on the same root domain
var urlDomain = window.location.hostname.replace('www.', '');
app.config('$sceDelegateProvider', function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://*.' + urlDomain + '/**'
]);
});
// Define a class like this
function Person(name, gender) {
// Add object properties like this
this.name = name;
this.gender = gender;
}
// Add methods like this. All Person objects will be able to invoke this
Person.prototype.speak = function() {
alert('Howdy, my name is ' + this.name);
@kmaida
kmaida / grunt-beep.js
Created December 12, 2014 19:40
Grunt - register 'beep!' task
grunt.registerTask('beep', 'beep!', function() { grunt.log.writeln('\x07').ok(); }); // beep!
// Define an object with init function and add methods
var Person = {
init: function(name, gender) {
this.name = name;
this.gender = gender;
},
speak: function() {
alert('Howdy, my name is ' + this.name);
}
};
@kmaida
kmaida / sortByValue.js
Created February 6, 2015 21:34
AngularJS - sort by value
$scope.orderByValue = function(value) {
return value;
}
// usage: ng-repeat="item in items | orderBy:orderByValue"
@kmaida
kmaida / noWidowsFilter.js
Created February 23, 2015 03:44
AngularJS - filter to fix widows in content that has been bound as HTML (will not work inside {{ }}). Usage: ng-bind-html="content | noWidows | trustAsHTML"
myApp.filter('noWidows',function(){
return function(input){
var wordArray = input.split(' ');
if (wordArray.length > 1) {
wordArray[wordArray.length - 2] += ' ' + wordArray[wordArray.length - 1];
wordArray.pop();
return wordArray.join(' ');
} else {
@kmaida
kmaida / scrollPosition.js
Last active August 29, 2015 14:16
Get the current position of the scrollbar with JavaScript
// Firefox uses HTML, Webkit uses body, iOS uses pageYOffset, therefore check for any:
var scrollPosition = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
@kmaida
kmaida / _mq.scss
Created April 3, 2015 16:28
Sass media query mixin that accepts media query string as argument
/*-- Media query variables --*/
$mq-small: 'media and (max-width: 767px)';
$mq-large: 'media and (min-width: 768px)';
/*-- Media query mixin --*/
@mixin mq($mqString) {
@media #{$mqString} {
@content;