Skip to content

Instantly share code, notes, and snippets.

View hartzis's full-sized avatar

(Brian) Emil Hartz hartzis

View GitHub Profile
@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 / mocha.opts
Created October 7, 2014 20:26
mocha.opts in /test folder
--reporter spec
--watch
--recursive
@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 / 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',
###APIs
* http://www.programmableweb.com/
@hartzis
hartzis / React and Immutable, Top Down.markdown
Created June 25, 2015 21:30
React and Immutable, Top Down
@hartzis
hartzis / gist:ef675be7833c5aafaf6c
Last active August 29, 2015 14:24
fastclick react fix component?
// From - http://stackoverflow.com/questions/24335821/can-i-fastclick-reactjs-running-in-cordova/24345469#24345469
// or use
// https://github.com/zilverline/react-tap-event-plugin
React.initializeTouchEvents(true)
var TouchClick = React.createClass({
@hartzis
hartzis / ImageUploadComponent.jsx
Last active April 3, 2023 18:09
React Image Upload with Preview
// https://codepen.io/hartzis/pen/VvNGZP
class ImageUpload extends Component {
constructor(props) {
super(props);
this.state = {
file: '',
imagePreviewUrl: ''
};
this._handleImageChange = this._handleImageChange.bind(this);
this._handleSubmit = this._handleSubmit.bind(this);
@hartzis
hartzis / imageUploadService.js
Created July 23, 2015 01:16
Upload Image File Ajax Request
uploadImage(imageFile) {
return new Promise((resolve, reject) => {
let imageFormData = new FormData();
imageFormData.append('imageFile', imageFile);
var xhr = new XMLHttpRequest();
xhr.open('post', '/upload', true);
@hartzis
hartzis / imageServices.js
Created July 23, 2015 05:12
Handle Express Image File Upload
let multiparty = require('multiparty');
let fs = require('fs');
function saveImage(req, res) {
let form = new multiparty.Form();
form.parse(req, (err, fields, files) => {
let {path: tempPath, originalFilename} = files.imageFile[0];
let copyToPath = "./images/" + originalFilename;