Last active
August 29, 2015 14:10
-
-
Save dnozay/91b56b78a1af2d4015f4 to your computer and use it in GitHub Desktop.
Autoreload features (code snippets)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'], | |
}, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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