Skip to content

Instantly share code, notes, and snippets.

@dnozay
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnozay/91b56b78a1af2d4015f4 to your computer and use it in GitHub Desktop.
Save dnozay/91b56b78a1af2d4015f4 to your computer and use it in GitHub Desktop.
Autoreload features (code snippets)
# code snippet from django.utils.autoreload (BSD license)
# https://github.com/django/django/blob/master/django/utils/autoreload.py
def code_changed():
global _mtimes, _win
for filename in gen_filenames():
stat = os.stat(filename)
mtime = stat.st_mtime
if _win:
mtime -= stat.st_ctime
if filename not in _mtimes:
_mtimes[filename] = mtime
continue
if mtime != _mtimes[filename]:
_mtimes = {}
try:
del _error_files[_error_files.index(filename)]
except ValueError:
pass
return I18N_MODIFIED if filename.endswith('.mo') else FILE_MODIFIED
return False
// trimmed down example from gaze documentation
// https://github.com/shama/gaze
var gaze = require('gaze');
// Watch all .js files/dirs in process.cwd()
gaze('**/*.js', function(err, watcher) {
// Files have all started watching
// watcher === this
// Get all watched files
this.watched(function(err, watched) {
console.log(watched);
});
// On file deleted
this.on('deleted', function(filepath) {
console.log(filepath + ' was deleted');
});
});
// example from the grunt-contrib-watch documentation.
// https://github.com/gruntjs/grunt-contrib-watch
grunt.initConfig({
watch: {
options: {
livereload: true,
},
css: {
files: ['public/scss/*.scss'],
tasks: ['compass'],
},
},
});
// example from the gulp api documentation.
// https://github.com/gulpjs/gulp
var watcher = gulp.watch('js/**/*.js', ['uglify','reload']);
watcher.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment