⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
/* | |
* Complete reworking of JS from https://gist.github.com/803410 | |
* Removes external `request` dependency | |
* Caveats: | |
* * No error checking | |
* * Largely a POC. `data` URI is accurate, but this code cannot simply be inserted into an `express` app | |
*/ | |
var URL = require('url'), | |
sURL = 'http://nodejs.org/logo.png', | |
oURL = URL.parse(sURL), |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
<title>One Graph</title> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script> | |
<script type="text/javascript" src="simple-graph.js"></script> | |
<style type="text/css"> | |
body { font: 13px sans-serif; } | |
rect { fill: #fff; } |
express = require("express") | |
request = require("request") | |
BufferList = require("bufferlist").BufferList | |
app = express.createServer(express.logger(), express.bodyParser()) | |
app.get "/", (req, res) -> | |
if req.param("url") | |
url = unescape(req.param("url")) | |
request | |
uri: url | |
encoding: 'binary' |
var child_process = require('child_process'), | |
assert = require('assert') | |
var isChild = !!(process.send), | |
isMaster = ((!isChild) && (process.argv.length > 2)), | |
isTopLevel = (!isMaster && !isChild) | |
if( isTopLevel ) { |
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
// 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 article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.
I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.
From Require.js - Why AMD:
The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"
I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.
var assert = require('assert'); | |
/** | |
* Default pattern | |
* | |
* Inherits properties added to this and prototype | |
*/ | |
// parent constructor: | |
function Parent(name) { |