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
<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
// 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
/** | |
* 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
/** | |
* 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
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
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
http://stackoverflow.com/questions/5736398/how-to-calculate-the-svg-path-for-an-arc-of-a-circle | |
function polarToCartesian(centerX, centerY, radius, angleInDegrees) { | |
var angleInRadians = angleInDegrees * Math.PI / 180.0; | |
var x = centerX + radius * Math.cos(angleInRadians); | |
var y = centerY + radius * Math.sin(angleInRadians); | |
return [x,y]; | |
} |
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 partial(f) { | |
var args = Array.prototype.slice.call(arguments, 1) | |
return function() { | |
var remainingArgs = Array.prototype.slice.call(arguments) | |
return f.apply(null, args.concat(remainingArgs)) | |
} | |
} |
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 crypto = require('crypto'); | |
var request = require('request'); | |
var setCors = function (MY_ACCOUNT_URL, MY_ACCOUNT_NAME, accountKey) { | |
var MY_CORS_XML = | |
'<?xml version="1.0" encoding="utf-8"?>'+ | |
'<StorageServiceProperties>'+ | |
'<Cors>'+ | |
'<CorsRule>'+ |