Gulpfile to transpile ES6 using babel and browserify


// npm install –save-dev gulp gulp-babel babelify through2 gulp-rename gulp-load-plugins
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var through2 = require('through2');
var babelify = require('babelify');
var srcApp = './src/app.js';
var srcWatchPath = './src/**/*.js'
var distAppPath = './dist';
var distAppFile = 'app.js';
gulp.task('build', function() {
return gulp.src(srcApp)
.pipe(through2.obj(function(file, enc, next) {
browserify(file.path, {
debug: process.env.NODE_ENV === 'development'
})
.transform(babelify)
.bundle(function(err, res) {
if (err) return next(err);
file.contents = res;
next(null, file);
});
}))
.on('error', function(error) {
console.log(error.stack);
this.emit('end');
})
.pipe($.rename(distAppFile))
.pipe(gulp.dest(distAppPath));
});
gulp.task('watch', function() {
gulp.watch(srcWatchPath, ['build']);
});
gulp.task('default', ['watch']);

view raw

gulpfile.js

hosted with ❤ by GitHub

This was based off another Gist but I lost the link 😦 I would have liked to attribute and link

An Ubuntu based 3 node/machine ElasticSearch cluster using Vagrant and Virtualbox

Thought I’d share the development ElasticSearch cluster I’ve been using lately.

https://github.com/diffused/Vagrant-ElasticSearch-Cluster

Simply run “vagrant up” and it should auto-provision a 3 node ElasticSearch cluster.

Why 3 nodes on different VMs?

We wanted to make sure we had a similar setup to our production system.

Also, checking query results when using aggregations across shards because document counts are approximate. FYI: The Vagrant provisioning scripts set up 1 shard 2 replicas. You might want to change that if you want to see the shard/doc count quirk.

 

 

 

 

gulp, mocha, gulp-watch

A short gist on getting gulp and mocha watching JS and test changes.

Watches for new and deleted files.

 


var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
gulp.task('default', ['watchJs', 'watchTests']);
// make sure you do not start a path with ./
// there's some bug in gaze that causes globs with ./ to not fire
var unitTestPaths = [
'tests/**/*_tests.js'
];
var jsPaths = [
'build/app/js/**/*.js'
];
function mochaPipe() {
return $.mocha({ reporter: 'spec' });
}
gulp.task('watchJs', function() {
$.watch({
glob: jsPaths,
read: false
},
function() {
gulp.start('allUnitTests');
}
);
});
//
gulp.task('watchTests', function() {
$.watch({
glob: unitTestPaths
},
function(files) {
return files
.pipe(mochaPipe())
;
});
});
gulp.task('allUnitTests', function() {
return gulp.src(unitTestPaths, {read: false})
.pipe(mochaPipe())
;
});

view raw

gulpfile.js

hosted with ❤ by GitHub


{
"name": "gulp-mocha-watch",
"version": "0.2.0",
"dependencies": {},
"devDependencies": {
"chai": "^1.9.1",
"gulp": "^3.8.7",
"gulp-load-plugins": "^0.5.3",
"gulp-mocha": "^1.0.0",
"gulp-watch": "^0.6.9"
},
"engines": {
"node": ">=0.10.26"
}
}

view raw

package.json

hosted with ❤ by GitHub

React – a sweet new javascript ui library

Just had a short run-thru of the tutorial for the React library by Facebook/Instagram.

I’m really liking the declarative approach. It’s nice and clean.

Going thru the tutorial, things felt very straightforward, sensible and apparent.

And, the docs are great!

It claims “ultra-high performance” due to it’s virtual DOM diff implementation, which is very interesting for anyone who’s has run into performance issues when working with complex & large dataset client side applications.

Hopefully JSX syntax highlighting comes to Sublime Text soon.

I’m definitely keeping an eye on this project. It looks likely to become my preferred javascript UI framework in the near future.

React homepage or github

Nice and simple browser refreshing from within Sublime Text

Stumbled onto a Sublime Text plugin called Browser Refresh for Sublime Text.

Install it via Package Control, bind the refresh command and it’ll refresh the active window/tab in your browser(s)

eg:

ctrl+shift+r -> reloads last active firefox tab

No browser plugins. Just nice and simple.

At the time of writing this, the official github repo & package seems to be missing Linux functionality.

The issues list pointed me to this repo which seemed to work. Use at your own discretion.

I got Firefox reloading successfully from within Sublime Text 3 on Xubuntu 13.04
Chrome reloading didn’t work for me (would love more time to inspect why)

 

 

Delete all data from a Sql Server Db except the dbo._MigrationHistory table using Entity Framework.


using(var context = new PlayContext())
{
context.Database.ExecuteSqlCommand(@"
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL';
EXEC sp_MSForEachTable 'IF OBJECT_ID(''?'') NOT IN (OBJECT_ID(''[dbo].[__MigrationHistory]'')) DELETE FROM ?';
EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL';
");
}

Example Entity Framework 6 context using connection string in app.config


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="Store" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Store;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

view raw

app.config

hosted with ❤ by GitHub


public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}

view raw

Product.cs

hosted with ❤ by GitHub


public class StoreContext : DbContext
{
// base name=[ConnectionStringName]
public StoreContext() : base("name=Store") { }
public DbSet<Product> Products { get; set; }
}

view raw

StoreContext.cs

hosted with ❤ by GitHub

ruby guard not seeing changes when saving in sublime text on linux

guard with guard-rspec wasn’t seeing any changes when saving files in sublime text 3

I’m running ubuntu 12.10 (xubuntu actually) over VirtualBox from a windows host.

A bit of a discussion on guard’s issue tracker seemed to highlight this issue for others to no avail.

A bit more googling and I accidentally stumbled onto this short post talking about atomic saves.

I set atomic_save to false in sublime’s user settings and it seems to work.


{
"atomic_save": false,
}

 

At what cost I wonder?