Skip to content

Instantly share code, notes, and snippets.

@dshster
dshster / after_res_hooks.js
Created January 1, 2018 18:09 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups

Styling native elements

Native HTML controls are a challenge to style. You can style any element in the web platform that uses Shadow DOM with a pseudo element ::pseudo-element or the /deep/ path selector.

video::webkit-media-controls-timeline {
  background-color: lime;
}

video /deep/ input[type=range] {
HTMLTextAreaElement.prototype.getCaretPosition = function () { //return the caret position of the textarea
return this.selectionStart;
};
HTMLTextAreaElement.prototype.setCaretPosition = function (position) { //change the caret position of the textarea
this.selectionStart = position;
this.selectionEnd = position;
this.focus();
};
HTMLTextAreaElement.prototype.hasSelection = function () { //if the textarea has selection then return true
if (this.selectionStart == this.selectionEnd) {
@dshster
dshster / grid.svg
Created December 14, 2012 05:38 — forked from pepelsbey/grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dshster
dshster / grunt.js
Created November 21, 2012 18:43 — forked from vojtajina/grunt.js
Grunt script for inlining AngularJS templates
module.exports = function(grunt) {
grunt.initConfig({
inline: {
'index.html': ['tpl/*.html']
}
});
grunt.registerMultiTask('inline', 'Inline AngularJS templates into single file.', function() {
var SCRIPT = '<script type="text/ng-template" id="<%= id %>"><%= content %></script>\n';
@dshster
dshster / gist:4126744
Created November 21, 2012 18:37 — forked from ajpiano/gist:2570733
grunt "indexcss" task
grunt.registerMultiTask("cssindex", "Create an 'index' file of css @import rules for sitewide CSS", function() {
var file = grunt.file;
var target = this.target;
var fileHandles = this.data.map(function( glob ) {
return file.expand( glob );
});
var imports;
fileHandles = fileHandles.concat.apply( [], fileHandles );
@dshster
dshster / 1.1_directory_structure.txt
Created November 21, 2012 18:32 — forked from latentflip/1.1_directory_structure.txt
In Lieu of doing this properly
./frontend
├── /coffee
│   ├── /models
│   | └── MyBaseModel.coffee
│   | └── MyModel.coffee
│   ├── /routers
│   | └── MyRouter.coffee
│   ├── /templates
| │   ├── /tmpl-dir1
@dshster
dshster / grunt-coffee.js
Created November 21, 2012 18:31 — forked from zonak/grunt-coffee.js
grunt task for compiling CoffeScript
/*
* Grunt Task File
* ---------------
*
* Task: coffee
* Description: Compile CoffeeScript files
* Dependencies: coffee-script
*
*/
@dshster
dshster / uri.js
Created September 6, 2012 07:40 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
// Originally solved by Tim Branyen in his drop file plugin
// http://dev.aboutnerd.com/jQuery.dropFile/jquery.dropFile.js
jQuery.event.props.push('dataTransfer');