Saturday, October 7, 2017

Vue.js, Gulp, Browserify, Vueify - Getting it running...

The state of javascript UI frameworks and setup is abysmall, but I'll save that for another post.

I like the idea of Vue, and I want to use it. I've tried getting a "flow" together a few times, but even when I was able to shake the right voodoo rattle, I hadn't been able to get a flow that worked consistently and didn't make me want to bash my computer and try making money as a basket weaver. Until now. Hopefully it'll last for more than a few weeks...

The Requirements

WARNING: I'm sure this setup will only work for specific versions of any of these packages. Installing the latest of each of these gives tons of warnings about deprecated packages, etc, which makes me afraid of deploying it in a production environment. Again, a topic for a different post.

Package.json

I've gone through a TON of tutorials trying to get this to work. With these specific versions of each package, I have this working on my machine. Because client side bundling, transpilation, etc is soo darn fragile, I can't guarantee that this will work on your machine.

//NOTE: Dependencies marked with // * might not be needed
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "browserify": "^14.4.0",
    "fs": "0.0.1-security",
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.1", // *
    "gulp-cssmin": "^0.2.0", // *
    "gulp-sourcemaps": "^2.6.1", // *
    "gulp-uglify": "^3.0.0", // *
    "gulp-webserver": "^0.9.1", // *
    "pug": "^2.0.0-rc.4",
    "vue": "^2.4.4",
    "vueify": "^9.4.1",
    "vueify-insert-css": "^1.0.0" // *
  },

Folder Structure

I know this isn't a typical folder layout, but bear with me. I'm keeping it simple to help eliminate issues relating to path. Because most modules have extremely crappy error handling. Tracking down issues here is hit or miss.

/dist
/src
   app.js
   app.vue
.babelrc
gulpfile.js
index.html
package.json

Gulp File

var gulp = require("gulp");
var fs = require("fs");
var vueify = require("vueify");
var browserify = require("browserify");

gulp.task("vueify", function(){
    return browserify('./src/app.js')
    .transform(vueify)
    .bundle()
    .pipe(fs.createWriteStream("./dist/bundle.js"))
});

app.js

var Vue = require('vue');
var App = require('./app.vue');

new Vue({
  el: '#app',
  render: function(h){
      return h(App);
  }  
});

app.vue

I added text that would be easily found in the bundle.js file.

<template lang="pug">
  .app
    h1 Test Template persimmon
    p {{title}}
</template>

<script>
export default {
    name: "app",
    data() {
        return {
            title: "Pug View Page " + new Date().toTimeString()
        }
    }
};
</script>

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue Gulp Tests</title>
</head>
<body>
    <p>App should be between here</p>
    <div id="app"></div>
    <p>And here</p>
    <script src="dist/bundle.js"></script>
</body>
</html>

Wednesday, August 19, 2015

Highlight Row by Cell Value in Google Sheets

I'm a big fan of Google sheets. That said, sometimes the features can be a bit confusing. I needed to highlight a row depending on the value in one of the columns. Figured out how to do it finally...


Set your range. Since we'll be using rows, specify the row you want to start with (excluding headers) and the row you want to end with.

Set the Format cells if... to "Custom Formula is"

Specify the rule. Since we're highlighting by row, you MUST use $ before the column definition. The row you specify must be the same row that you're starting with, in my case, 2.

And that's it!

Thursday, July 30, 2015

Google Sheets Banker's Rounding

I needed to have a formula for Banker's Rounding and use it in Google Doc's Sheets app. This seems to work well. This only rounds to whole numbers, but could be modified to do currency pretty easily.

=if(mod(B2,0.5)>=0,IF(ISEVEN(B2),ROUNDDOWN(B2,0),ROUNDUP(B2,0)),round(B2,0))


Tuesday, July 14, 2015

Address Regex

Needed to do some loose validation on mailing addresses. Here's what I did.

Physical Address Format

^[\d]+ [\w\.,\- ]+([\d]{5}(-[\d]{4})?)( .+)?$


Mailing Address Format

^[\w\.,\- ]+(\d{5}(-\d{4})?)( .+)?$


PO Box Format (used to exclude PO Boxes, taken from http://forums.asp.net/t/1551081.aspx?regular+expression+for+P+O+Box+validation

[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]


NOTE: Since I'm using \w, underscores will get through this filter. I didn't think it was a big deal, but if you need to exclude underscores, it's easy to fix. The post office would apparently remove underscores if detected, as it does with all special characters other than hyphens between meaningful numbers.

I also didn't validate state, as we're feeding state through a dropdown. Regex validation would need to include every state and territory permutation (CA, Calif, California, etc...).


The last bit allows any character to be used after the zip code.

To see how the Post Office parses addresses, you can look here...

http://pe.usps.gov/cpim/ftp/pubs/Pub28/pub28.pdf

Thursday, May 21, 2015

Async in .Net - Console App

I wanted to play around with Async in a console app, but most of the examples are in either winforms or mvc.

I found this article that showed exactly how to do it! Posting it to get it more coverage and so that I can get back to it if needed.


Thursday, April 23, 2015

Add / Get Query Value from Uri Extension Method

Needed to pull some code from an older project that had an interesting utility. It had extension methods for adding and retrieving values from a Uri query string.

 I thought that was neat so I wrote my own version.


Wednesday, April 15, 2015

Angular Html Literal Directive

Yes, this is not the way you're supposed to use Angular. There might be a better workaround out there.

I needed a way to generate image elements through Angular with custom attributes, including classes and styles. I'm working in a legacy system that makes this difficult. Can't use curly braces because we need to keep using the dead jQuery Tmpl, hasn't been phased out yet. I couldn't make the angular bindHtml directive to work. It kept on removing my style and class attributes.

So I came up with this...