This file contains hidden or 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
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" |
This file contains hidden or 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
var request = require('request'); | |
var Iconv = require('iconv').Iconv; | |
var iconv = new Iconv('GBK', 'UTF-8//TRANSLIT//IGNORE'); | |
request.get({ | |
url: 'http://foo.bar', | |
encoding: null | |
}, function(err, res, body) { | |
console.log(iconv.convert(body).toString()); | |
}); |
This file contains hidden or 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
/** | |
* An AngularJS directive for Dropzone.js, http://www.dropzonejs.com/ | |
* | |
* Usage: | |
* | |
* <div ng-app="app" ng-controller="SomeCtrl"> | |
* <button dropzone="dropzoneConfig"> | |
* Drag and drop files here or click to upload | |
* </button> | |
* </div> |
This file contains hidden or 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
/** | |
* prints the prototype chain for a constructed object. | |
* @param {Object} a constructed object. | |
* @param asArray {Boolean} if true, the chain will be returned as an array. | |
*/ | |
function printPrototypeChain(instance, asArray) { | |
var chain = [] | |
while (instance = Object.getPrototypeOf(instance)) { |
This file contains hidden or 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
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc | |
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/ | |
// author: Pawel Kozlowski | |
var myApp = angular.module('myApp', []); | |
//service style, probably the simplest one | |
myApp.service('helloWorldFromService', function() { | |
this.sayHello = function() { | |
return "Hello, World!" |
This file contains hidden or 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
<html> | |
<!-- http://snipplr.com/view/5144/getset-cursor-in-html-textarea/ --> | |
<head> | |
<title>Get/Set Caret in Textarea Example</title> | |
<script> | |
function doGetCaretPosition (ctrl) { | |
var CaretPos = 0; | |
// IE Support | |
if (document.selection) { |
This file contains hidden or 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
<html> | |
<!-- http://jsfiddle.net/timdown/vXnCM/--> | |
<head> | |
<title>Get/Set Caret in Textarea Example</title> | |
<script> | |
function test() { | |
var el = document.getElementById('editable'); | |
var range = document.createRange(); |
This file contains hidden or 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
angular.element(document) | |
.injector() | |
.invoke(['$rootScope', function($rootScope) { | |
var a = performance.now(); | |
$rootScope.$apply(); | |
return performance.now()-a; | |
}]) | |
angular.element(document) |
This file contains hidden or 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
function scopeWalker(scope, op) { | |
var _walker = (scope) => { | |
op(scope); | |
var currentChildScope = scope.$$childHead; | |
while(currentChildScope) { | |
_walker(currentChildScope); | |
currentChildScope = currentChildScope.$$nextSibling; | |
} | |
} | |
_walker(scope); |
This file contains hidden or 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
function type(obj) { | |
var toString = Object.prototype.toString; | |
var map = { | |
'[object Boolean]' : 'boolean', | |
'[object Number]' : 'number', | |
'[object String]' : 'string', | |
'[object Function]' : 'function', | |
'[object Array]' : 'array', | |
'[object Date]' : 'date', | |
'[object RegExp]' : 'regExp', |