Skip to content

Instantly share code, notes, and snippets.

View hartzis's full-sized avatar

(Brian) Emil Hartz hartzis

View GitHub Profile
@hartzis
hartzis / React and Immutable, Top Down.markdown
Created June 25, 2015 21:30
React and Immutable, Top Down
###APIs
* http://www.programmableweb.com/
@hartzis
hartzis / Login Angular Directive
Last active August 29, 2015 14:08
Login Angular Directive
angular.module('loginApp', [])
.directive("loginForm", [
function () {
return {
restrict: 'E',
scope: {},
template: '<div class="row"> <div class="col-xs-12"> <form name="loginForm"> <div class="form-group"> <label for="username">Username</label> <input type="text" name="username" ng-model="username" required="required" class="form-control"/> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" name="password" ng-model="password" required="required" class="form-control"/> </div> <button type="submit" ng-disabled="!loginForm.$valid" ng-class="{\'btn-default\':!loginForm.$valid,\'btn-success\':loginForm.$valid}" ng-click="login()" class="btn login">Login</button> <span ng-show="loginError && !loginForm.$valid" class="label label-danger"> <b>Error With Login</b> Please try again. </span></form> </div> </div>',
replace: 'true',
controller: ['$scope', '$http', '$window',
@hartzis
hartzis / gist:83b51a916fcd10f1908d
Created October 25, 2014 19:55
iframe download file angular without jquery
.directive('fileDownload', function ($compile) {
var fd = {
restrict: 'A',
link: function (scope, iElement, iAttrs) {
scope.$on("downloadFile", function (e, url) {
// console.log('dl url-', url);
var iFrame = iElement.find("iframe");
if (!(iFrame && iFrame.length > 0)) {
iFrame = angular.element("<iframe style='position:fixed;display:none;top:-1px;left:-1px;'/>");
iElement.append(iFrame);
@hartzis
hartzis / mocha.opts
Created October 7, 2014 20:26
mocha.opts in /test folder
--reporter spec
--watch
--recursive
@hartzis
hartzis / gist:0034817feb4dda37147c
Created September 11, 2014 18:42
window scroll event best practice
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: window scroll event
* Description: avoid attaching handlers to the window scroll event
@hartzis
hartzis / gist:fc40bfeff24ef7a13c21
Created September 11, 2014 04:21
create github social link
(function(){
'use strict';
$(document).on('ready', function(){
var getGitHubSocialInfo = function(githubURLJSON, githubURL, containerEl) {
$.ajax({
url: githubURLJSON,
dataType: "jsonp",
success: function(data) {
var theCount = data.data.watchers_count;
@hartzis
hartzis / jquery password validation
Created September 5, 2014 15:53
Beautiful password validation from stackexchange, 8 chars, 1 upper, 1 lower, 1 special
// Hold functions related to client side password validation
var password = function () {
var minPasswordLength = 8;
var _hasLowerCase = /[a-z]/;
var _hasUpperCase = /[A-Z]/;
var _hasDigit = /\d/;
var _hasNonWord = /(_|[^\w\d])/;
var password = [];
@hartzis
hartzis / _.md
Created July 7, 2014 15:39
Hello World
@hartzis
hartzis / gist:c6014b6289fab5e32d06
Created June 25, 2014 18:36
ngEnter - Watch for enter keypress
var ngEnterDirectives = angular.module('ngEnterDirectives', []);
/*
This directive allows us to pass a function in on an enter key to do what we want.
*/
ngEnterDirectives.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);