Skip to content

Instantly share code, notes, and snippets.

@maheshsenni
maheshsenni / webpack-update-chunk.js
Last active May 8, 2016 23:19
Creating a module bundler with Hot Module Replacement
webpackHotUpdate(0,{
/***/ 78:
/***/ function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(79)();
// imports
// module
exports.push([module.id, "body {\n background-color: yellow;\n}", ""]);
// exports
/***/ }
})
@maheshsenni
maheshsenni / app.js
Last active May 12, 2016 02:39
Creating a module bundler with Hot Module Replacement
// require counter implementation from counter.js
var message = require('./message.js');
document.querySelector('#message').innerText = message;
@maheshsenni
maheshsenni / index.js
Last active May 9, 2016 00:18
Step 1 - Creating a module bundler with Hot Module Replacement
var mdeps = require('module-deps');
var browserPack = require('browser-pack');
var JSONStream = require('JSONStream');
var fs = require('fs');
var path = require('path');
// express - for serving our app
var express = require('express');
var app = express();
var http = require('http').Server(app);
@maheshsenni
maheshsenni / index.js
Created May 10, 2016 00:24
Step 2 - Creating a module bundler with Hot Module Replacement
// some code here
// websocket connection for notifying browser
var io = require('socket.io')(http);
// some code here
var processFiles = function(callback) {
// some code here
md.pipe(JSONStream.stringify())
@maheshsenni
maheshsenni / hmr.js
Last active May 10, 2016 00:40
Step 2b - Creating a module bundler with Hot Module Replacement
/* This file is included in the page running the app */
(function() {
// create an instance of Socket.IO for listening
// to websocket messages
var socket = io();
// listen for 'file-change' message
socket.on('file-change', function(msg) {
console.log('File changed: ' + msg.id);
// reload the browser to get the latest changes
@maheshsenni
maheshsenni / index.js
Last active May 14, 2016 16:23
Step 3 - Creating a module bundler with Hot Module Replacement
// response with a JSONP callback function which does hot module replacement
app.get('/hot-update', function(req, res){
var moduleId = req.query.id;
// wrap the module code around JSONP callback function
var hotUpdateScriptTxt = 'hotUpdate({ "' + moduleId + '":[function(require,module,exports){';
// find the updated module in moduleDepsJSON (output from module-deps)
var updatedModule = moduleDepsJSON.filter(function(dep) {
return dep.id === moduleId;
})[0];
// append source of the updated module to the hot update script
@maheshsenni
maheshsenni / hotUpdate.js
Last active May 14, 2016 16:26
Step 3a - Creating a module bundler with Hot Module Replacement
// this function will be added to the final bundle produced by
// browser-pack using 'prelude' option
this.hotUpdate = function(updatedModules) {
for (var id in updatedModules) {
if(Object.prototype.hasOwnProperty.call(updatedModules, id)) {
// clear module definition from cache
delete cache[id];
// replace existing module definition from module map
modules[id] = updatedModules[id];
// Update module - 'newRequire' is from browser-pack
@maheshsenni
maheshsenni / hmr.js
Created May 12, 2016 01:08
Step 3b - Creating a module bundler with Hot Module Replacement
/* This file is included in the page running the app */
(function() {
// create an instance of Socket.IO for listening
// to websocket messages
var socket = io();
// listen for 'file-change' message
socket.on('file-change', function(msg) {
console.log('File changed: ' + msg.id);
// download the updated module to kick start
# Enable SSH
echo 'ssh' >/tmp/1/ssh
# Configure WiFi
cat > /tmp/1/wpa_supplicant.conf << EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<TWO_LETTER_ISO_COUNTRY_CODE>
network={
nmap -sn 192.168.0.1/24