Skip to content

Instantly share code, notes, and snippets.

View andyshora's full-sized avatar

Andy Shora andyshora

View GitHub Profile
@andyshora
andyshora / backgroundImage.js
Created July 20, 2013 15:01
AngularJS directive to add a custom background image to an element when the app has initialized. For example: <div background-image="{{imagePath}}"></div>
'use strict';
app.directive('backgroundImage', function(){
return function(scope, element, attrs){
restrict: 'A',
attrs.$observe('backgroundImage', function(value) {
element.css({
'background-image': 'url(' + value +')'
});
});
@andyshora
andyshora / Login.aspx
Created October 11, 2013 14:03
Password protect a website on Windows Azure
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void Login_OnClick(object sender, EventArgs args)
{
if (FormsAuthentication.Authenticate(UsernameTextbox.Text, PasswordTextbox.Text))
FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked);
@andyshora
andyshora / Gruntfile.js
Created February 4, 2014 11:44
Node + Grunt
'use strict';
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
$(document).ready(function() {
// enable on mouseover
$('.twitter-share-button-placeholder').bind('mouseover', function() {
enableShareButton($(this));
});
// auto enable for mobile
if (Modernizr.touch) {
enableShareButton($('.twitter-share-button-placeholder'));
@andyshora
andyshora / sublime-merge-tool.sh
Created April 9, 2014 13:39
Set Sublime Text 2 as the default Git merge tool to resolve conflicts
ln -s "/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
git config --global mergetool.sublime.cmd "sublime -w \$MERGED"
git config --global mergetool.sublime.trustExitCode false
git config --global merge.tool sublime
@andyshora
andyshora / iframe-problems.md
Last active August 29, 2015 14:02
Reasons not to serve responsive web apps within iframes

Reasons not to serve responsive web apps within iframes

Chrome has a weird fixed scrollbar bug - it doesn't appear to move when you scroll.

  • The only solution is for every window resize event (you can debounce it with caution), send a message from the child to the parent frame asking for a window resize to the height of the content (passed as a param).
  • This means for Chrome (if you're just sniffing for window.chrome) the iframe will potentially be thousands of pixels high, and the scrollbar works because it's actually scrolling the parent page and not the child. A reprocussion of this is that no scroll events get fired ont he child page, so avoid relying on scroll events all together.
  • If you debounce the resizing be careful, as some supressed resize events may be significant ones, which may cause double scrollbars and a rare phenomenon what I like to call 'iframe dancing'. This is where the client sends a resize request, the parent resisizes (but adds an extra scrollbar temporarily), then due t
@andyshora
andyshora / index.html
Last active August 29, 2015 14:02
JSBin AngularJS Started Template
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Test</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="MainController">
@andyshora
andyshora / angular-ng-focus.js
Created June 24, 2014 08:57
Input focus dynamically as an AngularJS directive
angular.module('ng').directive('ngFocus', function($timeout) {
return {
link: function ( scope, element, attrs ) {
scope.$watch( attrs.ngFocus, function ( val ) {
if ( angular.isDefined( val ) && val ) {
$timeout( function () { element[0].focus(); } );
}
}, true);
element.bind('blur', function () {
@andyshora
andyshora / backend-avatar.js
Last active August 29, 2015 14:06
Sample backend route for angular-image-crop
exports.changeProfilePic = function(req, res) {
var id = req.params.id;
// check user is logged in
if (!req.session.userId){
res.send(401);
return;
}
@andyshora
andyshora / app.coffee
Last active August 29, 2015 14:18
app.coffee
axis = require 'axis'
js_pipeline = require 'js-pipeline'
css_pipeline = require 'css-pipeline'
roots_config = require 'roots-config'
Q = require 'q'
readdirp = require 'readdirp'
siteFiles = []
# generate files for sitemap