Promises are a popular pattern for asynchronous operations in JavaScript, existing in some form in every client-side framework in widespread use today. We'll give a conceptual and practical intro to promises in general, before moving on to talking about how they fit into Angular. If you've ever wondered what exactly $q was about, this is the place to learn!
Avoiding callback hell in Node js using promisesAnkit Agarwal
This document discusses using promises in Node.js to avoid callback hell. It explains that Node.js is event-based and non-blocking, allowing it to handle multiple requests simultaneously. However, nested callbacks can result in unwieldy callback pyramids or "callback hell". Promises provide a way to write asynchronous code in a more linear way using method chaining. Key benefits include separation of concerns between wrapping asynchronous functions and controlling flow, as well as more readable code. The document provides examples of chaining, nesting, combining, and creating promises using deferred objects in the Q promise library.
Promise patterns provide an asynchronous programming model for JavaScript using promises. Promises allow separating business logic from asynchronous API providers by defining a standard asynchronous API. Common patterns are callbacks, events, and promises. Promises improve on callbacks and events by allowing parallel asynchronous operations, error handling, and progress tracking in a standardized way.
This document provides an overview of Node.js and how to use it for web development. It covers installing Node.js, the basic syntax and features of Node.js like modules, asynchronous programming. It also discusses using the NPM package manager and popular Node packages. Finally, it demonstrates how to build a basic web server and framework like Express along with integrating a database like MySQL.
Async/await is a new language feature that will ship with Swift 5.5 this year. There’s no doubt it will have a significant impact on how we write asynchronous code.
In this talk, we’re going to look at some use cases for async/await, how we can call existing Swift APIs using this new feature, and why your decision to write your SDK in Objective-C might turn out to have been a very clever move.
We’ll also have a look at the refactoring support Apple is adding to Xcode and how it will help you migrate your existing code base.
This document discusses callbacks, promises, and generators for handling asynchronous code in JavaScript. It begins by explaining callbacks and the issues they can cause like "callback hell". It then introduces promises as an alternative using libraries like Q that allow chaining asynchronous operations together. Generators are also covered as a way to write asynchronous code that looks synchronous when combined with promises through libraries like CO. Overall, it recommends using an asynchronous pattern supported by a library to manage complex asynchronous code.
Flash over the years, has been used to prop up the regular browser like a sad old man drinking alone in a pub.
Today browsers come shipped with technology designed to rival flash and aim to shut it squarely out of the game.
Are browser ready to rock without Flash?
Promises provide a consistent way to write asynchronous code in JavaScript by abstracting callbacks into objects. Some key benefits of promises include: handling errors through rejection instead of nested callbacks, ability to chain operations together through promise methods like .then(), and restoring synchronous-like control flow. The document discusses how promises improve on traditional callback-based patterns and provides examples of converting common asynchronous patterns to use promises.
Asynchronous programming done right - Node.jsPiotr Pelczar
This document discusses asynchronous programming and avoiding race conditions. It covers how asynchronous actions allow the main program flow to continue processing without blocking on I/O. It also discusses how asynchronous programming works with callbacks and promises rather than sequential execution. It provides examples of using libraries like Async to control asynchronous flows and common pitfalls to avoid like double callbacks and unexpected asynchronous behavior.
With more and more sites falling victim to data theft, you've probably read the list of things (not) to do to write secure code. But what else should you do to make sure your code and the rest of your web stack is secure ? In this tutorial we'll go through the basic and more advanced techniques of securing your web and database servers, securing your backend PHP code and your frontend javascript code. We'll also look at how you can build code that detects and blocks intrusion attempts and a bunch of other tips and tricks to make sure your customer data stays secure.
HTML5 is all the rage with the cool kids, and although there's a lot of focus on the new language, there's lots of interesting new JavaScript APIs both in the HTML5 spec and separated out. This presentation will take you through demos and code behind the new JavaScript APIs, and explore where these features can be used
The document discusses JavaScript promises and how they can be used to handle asynchronous operations. Promises allow asynchronous functions to return values asynchronously by attaching callbacks to the promise object. This avoids callback hell and makes asynchronous code easier to read and maintain. The document covers how promises can be chained together, executed in parallel, cached, and passed around between functions. It also discusses promise implementations in different frameworks like jQuery, Angular, and how promises can interact across frameworks.
This document discusses asynchronous PHP processing and libraries. It begins with an overview of synchronous vs asynchronous processing and blocking vs non-blocking I/O. It then reviews several approaches for asynchronous PHP including Pthreads, pcntl_fork, popen, curl_multi, and event loops with libraries like ReactPHP. ReactPHP is discussed in depth as an event-driven non-blocking I/O library that uses promises and streams for asynchronous operations. Examples are provided for asynchronous HTTP requests, DNS lookups, and a pub/sub application using ZeroMQ. Key points emphasized are that asynchronous code does not necessarily run faster and execution order is not guaranteed.
The document discusses techniques for enabling communication between JavaScript and Objective-C in iOS applications, including setting global variables accessible to both, making Objective-C selectors and properties available to JavaScript, and handling callbacks from JavaScript to Objective-C such as when the web view location changes or a form is submitted. Code snippets provide examples of implementing these techniques.
It's difficult to find any app that doesn't connect to the network to get data. If you have used NSURLConnection you know that fetching data is easy, but can be fraught with a messy implementation. AFNetworking is delightful networking library for iOS and Mac that can simplify the process of getting JSON data, XML, or even images.
Node.js is an exciting new platform for building web applications in JavaScript. With its unique I/O model, it excels at the sort of scalable and real-time situations we are increasingly demanding of our servers. And the ability to use JavaScript for both the client and server opens up many possibilities for code sharing, expertise reuse, and rapid development.
This class is intended for those with some basic knowledge of JavaScript, interested in an introduction to the Node.js ecosystem and development platform. We'll discuss how to get started with Node, and why you would want to. We'll then explore Node's module and package system, demonstrating several of the more popular and impressive packages that exemplify the type of tasks Node excels at. These include low-level HTTP streaming with the http module, high-level bidirectional websocket communication with socket.io, and server-browser code sharing with browserify, jsdom, and node-canvas.
Node.js is an asynchronous event-driven JavaScript runtime that aims to provide an easy way to build scalable network programs. It uses an event loop model that keeps slow operations from blocking other operations by executing callbacks asynchronously. This allows Node.js programs to handle multiple connections concurrently without creating new threads. Common uses of Node.js include building web servers, real-time applications, crawlers, and process monitoring tools. The document provides examples of using modules like HTTP, TCP, DNS, and file system modules to demonstrate Node.js's asynchronous and non-blocking I/O model.
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
The document discusses the goals and design of Zepto.js, a JavaScript framework for mobile web applications. It aims to have a very small codebase that is easy to use, extends native browser APIs, and avoids non-essential browser implementations. It provides a jQuery-like API but takes advantage of mobile features for better performance on small screens and devices with limited bandwidth.
Tornado is a Python web framework and asynchronous networking library. It is a scalable, non-blocking web server that allows applications to handle multiple requests simultaneously using a single thread. Some key features include lightweight and fast templates, asynchronous request handlers, and integrations with databases, caches and other services. Tornado is best suited for building real-time web services and can be used alongside other front-end web servers.
Mathilde Lemée & Romain Maton
La théorie, c’est bien, la pratique … aussi !
Venez nous rejoindre pour découvrir les profondeurs de Node.js !
Nous nous servirons d’un exemple pratique pour vous permettre d’avoir une premiere experience complete autour de Node.js et de vous permettre de vous forger un avis sur ce serveur Javascript qui fait parler de lui !
http://soft-shake.ch/2011/conference/sessions/incubator/2011/09/01/hands-on-nodejs.html
Tornado is a Python web framework and asynchronous networking library. It is non-blocking and scalable, using epoll and other low-level I/O modules. Tornado includes modules for HTTP handling, templates, authentication, and more. It was originally developed at FriendFeed and later open sourced by Facebook. Example usages include a simple "Hello World" app, handling requests and responses, using cookies and secure cookies, internationalization, and asynchronous database requests.
Node.js is an asynchronous event-driven JavaScript runtime that allows JavaScript to be used on the server-side. It uses a non-blocking I/O model that makes it suitable for real-time web applications. WebSockets provide a standardized way for the browser and server to establish two-way communication. However, not all browsers support WebSockets yet. Socket.io addresses this by providing a WebSocket-like experience across all browsers through fallbacks like long-polling. It allows real-time applications to be developed more easily.
This document outlines an agenda for discussing JavaScript at the backend using Node.js. The agenda includes explaining what Node.js is, installing Node.js, writing a simple "Hello World" program, running Node.js applications, exploring core Node.js modules like the file system and HTTP modules, and handling HTTP requests. Key points are installing Node.js from its website, using the file system and HTTP modules to interact with files and create an HTTP server, and using a request handler to return different responses based on the URL. The presenter is introduced as an author who works with JavaScript, Node.js, and related technologies.
The document discusses how JavaScript frameworks like MooTools can be leveraged in Joomla sites to provide features like DOM manipulation, classes, event listeners, and effects. It describes how MooTools is the default framework used by Joomla and provides examples of its key capabilities. Additionally, it offers suggestions for optimizing framework usage, such as implementing the Google Loader API to decrease page load times.
This document provides an introduction to jQuery, including what jQuery is, why it's useful, how to include it, and some common jQuery syntax and methods. Key points:
- jQuery is a JavaScript framework that makes interacting with HTML, CSS, and browser functionality simpler. It provides methods for DOM manipulation, AJAX requests, and event handling.
- jQuery uses CSS selector syntax to select elements and chainable methods to manipulate them. Common methods include show(), hide(), addClass(), removeClass(), and more.
- Events like click and change can have callback functions attached via jQuery. AJAX requests allow asynchronous data retrieval without page reloads.
- jQuery handles cross-browser compatibility and provides a consistent
Express is a web application framework for Node.js that provides a robust set of features for building web applications and APIs. It is designed for building scalable and fast web applications and services. Some key features include being built on Node.js for asynchronous and event-driven capabilities, a simple routing system and middleware support, and support for template engines and plugins.
The document discusses the Dojo JavaScript toolkit. It provides an overview of what Dojo is, including that it is a lightweight JavaScript toolkit with modular components for tasks like charts, calendars, file uploads and more. It also discusses Dojo's build system for concatenating and minifying files, its module loading system, and patterns used like ambiguous constructors, chaining and deferreds. The document promotes Dojo's large developer community and active development.
Node.js is an environment for developing high-performance web services using JavaScript on the server-side. It uses Google's V8 JavaScript engine and an event-driven, non-blocking I/O model that makes it lightweight and efficient, especially for real-time web applications with many concurrent connections. Common programming techniques in Node.js include asynchronous I/O with callbacks, event-driven programming, and a common module system for building reusable components.
This document discusses techniques for improving frontend performance. It recommends making fewer HTTP requests, using a content delivery network, adding expiration headers, gzipping components, optimizing stylesheet and script placement, avoiding redirects and duplicate scripts, and more. It also covers techniques for loading scripts asynchronously without blocking page rendering, such as using script elements, XHR, and iframes. Faster page loads can improve user experience and increase revenue.
The document discusses the basics of AJAX including introductions to AJAX concepts, AJAX toolkits, transport protocols, AJAX techniques like search forms, tables, hidden DIVs, logins, and slideshows. It also covers common AJAX pitfalls and alternatives to AJAX like Flex, Lazslo, and WPF. Resources for further learning about AJAX are provided.
HTML5 introduces new semantic elements like article, header, nav, and section that divide the content into meaningful regions. It also defines new multimedia elements such as video, audio, and canvas. New form input types and attributes are added for validation. The Canvas API allows dynamic drawing via scripting. The Drag and Drop API supports dragging and dropping elements. Other HTML5 APIs include Geolocation, Web Storage, and Web Workers. Overall, HTML5 provides a powerful set of features for building robust, dynamic web applications.
The first of its kind Web Technology Conference on Open Source Technology, WebOSS '07 was organised in Kolkata on Sat, 13th Oct 07 and I spoke at the event as one of the participants on "Building Applications using AJAX". Here I will share my presentation.
Vert.x is a tool for building reactive applications on the JVM. It is polyglot, allowing applications to be written in Java, Groovy, JavaScript and other languages. It uses an asynchronous and non-blocking model with shared-nothing communication between components. Modules communicate through publish/subscribe messaging on an event bus or directly through request-response patterns. Vert.x provides horizontal scaling and allows efficient use of server resources. It can also integrate with SockJS to provide WebSocket-like capabilities in browsers that do not support WebSockets.
This document provides an overview of building a content management system (CMS) using Apache Sling. It discusses how Sling uses OSGi and the Java Content Repository to provide a RESTful framework. Example uses of Sling include content CRUD operations via the Sling Post Servlet and resource resolution. The document then demonstrates how to set up a Sling development environment and build sample pages that include a WYSIWYG editor and image uploads using Sling and technologies like JavaScript, jQuery, Bootstrap and Groovy.
The document provides an overview of Node.js, a JavaScript runtime environment for building scalable network applications. Some key points covered include:
- Node.js is built on Google's V8 JavaScript engine and is event-driven and non-blocking.
- It is well-suited for data-intensive real-time applications due to its lightweight and efficient nature.
- Node.js differs from other scripting languages by being non-blocking, single-threaded, and having an event-based approach built-in.
An opinionated intro to Node.js - devrupt hospitality hackathonLuciano Mammino
A talk presenting an opinionated introduction to Node.js, proving a simple introduction to the async model, some common async patterns and some other interesting Node.js tricks.
This document summarizes best practices for optimizing JavaScript performance. It discusses loading JavaScript asynchronously or lazily to avoid blocking page loads. It also recommends minimizing DOM manipulation, batching style changes, and caching references to reduce reflows and repaints. The document emphasizes measuring performance through tools like Benchmark.js and jsperf.com to avoid premature optimization. It cautions against unnecessary shims and polyfills and stresses optimizing for mobile environments.
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
This document summarizes key considerations for choosing a task queue system. It discusses task properties like idempotency and reentrancy. It covers performance factors like latency and throughput as well as consistency models. Common task queue systems like Celery, RQ, and MRQ are evaluated based on factors like performance, complexity, community support, and future plans. The document emphasizes thinking carefully about specific needs before choosing a system and being grateful for open source software.
This document discusses ranking web pages using Apache Spark. It begins by introducing the speaker and their background. It then provides an overview of how search engines traditionally work, including crawling, indexing, and ranking pages. It discusses using static features like URL depth and dynamic features like click-through rates to calculate page scores. The document proposes using Spark to perform learning to rank by training models on features and user data to improve results. It also demonstrates calculating PageRank on the Common Crawl dataset using GraphFrames in SparkSQL. Finally, it provides links to learn more about the Common Search open source project.
The original vision of Nutch, 14 years later: Building an open source search ...Sylvain Zimmer
The document discusses the original vision of the Nutch project to provide an open source alternative to private search services and increase transparency. It describes how Nutch has been adopted by smaller organizations rather than operating a large public index. The presentation then outlines the technical components of building an open source search engine like Nutch, including the crawler, indexer, database, and searcher/frontend. It also discusses challenges around funding, spam, relevance, and outreach, as well as opportunities for decentralization, research, and making the web a better place.
PyCon FR 2016 - Et si on recodait Google en Python ?Sylvain Zimmer
This document discusses recoding Google in Python. It summarizes Google's early use of Python for its crawler before switching to C++ for performance reasons. It then outlines the major components of a web search engine (crawler, parser, index, searcher/ranker) and discusses Python libraries and techniques that could be used to implement each component today, noting improved stability, performant C/Cython libraries, and algorithmic changes. It calls for contributors to help build out additional features and discusses open challenges.
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013Sylvain Zimmer
Ma session de live-coding à DevoxxFR 2013. Le but était de faire une présentation rapide de Backbone et de montrer très simplement aux gens pourquoi et comment l'utiliser.
Le code que j'ai live-codé est disponible sur https://github.com/sylvinus/backbone-simpleapp-kitlers
5-minute lightning talk presented at ParisJS #12 by Sylvain Zimmer from Joshfire (@sylvinus)
140byt.es is a project created by the awesome @jed with contributions from an army of code golfers ;-)
The document provides an overview of the Joshfire Framework version 0.9 release. It describes Joshfire as a powerful and modular framework based on standard web technologies that allows developers to build one application that works across multiple devices using a single codebase. It achieves this through the use of device-specific adapters and by separating an application's data and user interface definitions.
Javascript Views, Client-side or Server-side with NodeJSSylvain Zimmer
The document summarizes a presentation on building applications that can render on both the server and client using a single codebase. It discusses how traditional server-side and client-side apps are structured, then shows how server-side JavaScript allows building a single app with a shared core that can adapt for the server or browser through the use of adapters. It demonstrates this approach with a sample app and discusses benefits like serving HTML versions for search engines or legacy browsers. Key aspects covered are rendering on the server/client with a View class and handling browser history across environments.
Kinect + Javascript tech talk at #ParisJS Jan 2011Sylvain Zimmer
My analog slides for a very quick tech demo of DepthJS working on an app built with Joshfire's javascript framework, Joshlib (demo not included in the prez). I explained briefly the data flow between the kinect, libusb, libfreenect, opencv, tornado, websockets and finally the javascript page.
Presentation I gave 30/05/2009 at PyCon FR in Paris http://pycon.fr
I'm not a twisted guru but I tried to explain to the audience as simply as I could the idea of asynchronous programming and the benefits of Twisted.
Discovery Series - Zero to Hero - Task Mining Session 1DianaGray10
This session is focused on providing you with an introduction to task mining. We will go over different types of task mining and provide you with a real-world demo on each type of task mining in detail.
Develop Secure Enterprise Solutions with iOS Mobile App Development ServicesDamco Solutions
The security of enterprise apps should not be overlooked by organizations. Since these apps handle confidential finance/user data and business operations, ensuring greater security is crucial. That’s why, businesses should hire dedicated iOS mobile application development services providers for creating super-secured enterprise apps. By incorporating sophisticated security mechanisms, these developers make enterprise apps resistant to a range of cyber threats.
Content source - https://www.bizbangboom.com/articles/enterprise-mobile-app-development-with-ios-augmenting-business-security
Read more - https://www.damcogroup.com/ios-application-development-services
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptxFwdays
I will share my personal experience of full-time development on wasm Blazor
What difficulties our team faced: life hacks with Blazor app routing, whether it is necessary to write JavaScript, which technology stack and architectural patterns we chose
What conclusions we made and what mistakes we committed
"Building Future-Ready Apps with .NET 8 and Azure Serverless Ecosystem", Stan...Fwdays
.NET 8 brought a lot of improvements for developers and maturity to the Azure serverless container ecosystem. So, this talk will cover these changes and explain how you can apply them to your projects. Another reason for this talk is the re-invention of Serverless from a DevOps perspective as a Platform Engineering trend with Backstage and the recent Radius project from Microsoft. So now is the perfect time to look at developer productivity tooling and serverless apps from Microsoft's perspective.
Mastering OnlyFans Clone App Development: Key Strategies for SuccessDavid Wilson
Dive into the critical elements of OnlyFans clone app development, from understanding user needs and designing engaging platforms to implementing robust monetization strategies and ensuring scalability. Discover how RichestSoft can guide you through the development process, offering expert insights and proven strategies to help you succeed in the competitive market of content monetization.
Keynote : Presentation on SASE TechnologyPriyanka Aash
Secure Access Service Edge (SASE) solutions are revolutionizing enterprise networks by integrating SD-WAN with comprehensive security services. Traditionally, enterprises managed multiple point solutions for network and security needs, leading to complexity and resource-intensive operations. SASE, as defined by Gartner, consolidates these functions into a unified cloud-based service, offering SD-WAN capabilities alongside advanced security features like secure web gateways, CASB, and remote browser isolation. This convergence not only simplifies management but also enhances security posture and application performance across global networks and cloud environments. Discover how adopting SASE can streamline operations and fortify your enterprise's digital transformation strategy.
Self-Healing Test Automation Framework - HealeniumKnoldus Inc.
Revolutionize your test automation with Healenium's self-healing framework. Automate test maintenance, reduce flakes, and increase efficiency. Learn how to build a robust test automation foundation. Discover the power of self-healing tests. Transform your testing experience.
The History of Embeddings & Multimodal EmbeddingsZilliz
Frank Liu will walk through the history of embeddings and how we got to the cool embedding models used today. He'll end with a demo on how multimodal RAG is used.
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...Snarky Security
How wonderful it is that in our modern age, every bit of our biological data can be digitized, stored, and potentially pilfered by cyber thieves! Isn't it just splendid to think that while scientists are busy pushing the boundaries of biotechnology, hackers could be plotting the next big bio-data heist? This delightful scenario is brought to you by the ever-expanding digital landscape of biology and biotechnology, where the integration of computer science, engineering, and data science transforms our understanding and manipulation of biological systems.
While the fusion of technology and biology offers immense benefits, it also necessitates a careful consideration of the ethical, security, and associated social implications. But let's be honest, in the grand scheme of things, what's a little risk compared to potential scientific achievements? After all, progress in biotechnology waits for no one, and we're just along for the ride in this thrilling, slightly terrifying, adventure.
So, as we continue to navigate this complex landscape, let's not forget the importance of robust data protection measures and collaborative international efforts to safeguard sensitive biological information. After all, what could possibly go wrong?
-------------------------
This document provides a comprehensive analysis of the security implications biological data use. The analysis explores various aspects of biological data security, including the vulnerabilities associated with data access, the potential for misuse by state and non-state actors, and the implications for national and transnational security. Key aspects considered include the impact of technological advancements on data security, the role of international policies in data governance, and the strategies for mitigating risks associated with unauthorized data access.
This view offers valuable insights for security professionals, policymakers, and industry leaders across various sectors, highlighting the importance of robust data protection measures and collaborative international efforts to safeguard sensitive biological information. The analysis serves as a crucial resource for understanding the complex dynamics at the intersection of biotechnology and security, providing actionable recommendations to enhance biosecurity in an digital and interconnected world.
The evolving landscape of biology and biotechnology, significantly influenced by advancements in computer science, engineering, and data science, is reshaping our understanding and manipulation of biological systems. The integration of these disciplines has led to the development of fields such as computational biology and synthetic biology, which utilize computational power and engineering principles to solve complex biological problems and innovate new biotechnological applications. This interdisciplinary approach has not only accelerated research and development but also introduced new capabilities such as gene editing and biomanufact
Latest Tech Trends Series 2024 By EY IndiaEYIndia1
Stay ahead of the curve with our comprehensive Tech Trends Series! Explore the latest technology trends shaping the world today, from the 2024 Tech Trends report and top emerging technologies to their impact on business technology trends. This series delves into the most significant technological advancements, giving you insights into both established and emerging tech trends that will revolutionize various industries.
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...Zilliz
Enterprises have traditionally prioritized data quantity, assuming more is better for AI performance. However, a new reality is setting in: high-quality data, not just volume, is the key. This shift exposes a critical gap – many organizations struggle to understand their existing data and lack effective curation strategies and tools. This talk dives into these data challenges and explores the methods of automating data curation.
Keynote : AI & Future Of Offensive SecurityPriyanka Aash
In the presentation, the focus is on the transformative impact of artificial intelligence (AI) in cybersecurity, particularly in the context of malware generation and adversarial attacks. AI promises to revolutionize the field by enabling scalable solutions to historically challenging problems such as continuous threat simulation, autonomous attack path generation, and the creation of sophisticated attack payloads. The discussions underscore how AI-powered tools like AI-based penetration testing can outpace traditional methods, enhancing security posture by efficiently identifying and mitigating vulnerabilities across complex attack surfaces. The use of AI in red teaming further amplifies these capabilities, allowing organizations to validate security controls effectively against diverse adversarial scenarios. These advancements not only streamline testing processes but also bolster defense strategies, ensuring readiness against evolving cyber threats.
8. Problems w/ Apricot
if (file.match(/^https?:///)) {
var urlInfo = url.parse(file, parseQueryString=false),
host = http.createClient(((urlInfo.protocol === 'http:') ? 80 : 443),
urlInfo.hostname),
req_url = urlInfo.pathname;
if (urlInfo.search) {
req_url += urlInfo.search;
}
var request = host.request('GET', req_url, { host: urlInfo.hostname });
request.addListener('response', function (response) {
var data = '';
response.addListener('data', function (chunk) {
data += chunk;
});
response.addListener("end", function() {
fnLoaderHandle(null, data);
});
});
if (request.end) {
request.end();
} else {
request.close();
}
} else {
fs.readFile(file, encoding='utf8', fnLoaderHandle);
}
9. Problems w/ Apricot
No advanced HTTP client in Node’s lib
npm install request
https + redirects + buffering
10. Problems w/ Apricot
Apricot.parse("<p id='test'>An HTML Fragment</p>", function(doc) {
doc.find("selector"); // Populates internal collection, See Sizzle selector syntax (rules)
doc.each(callback); // Itterates over the collection, applying a callback to each match
(element)
doc.remove(); // Removes all elements in the internal collection (See XUI Syntax)
doc.inner("fragment"); // See XUI Syntax
doc.outer("fragment"); // See XUI Syntax
doc.top("fragment"); // See XUI Syntax
doc.bottom("fragment"); // See XUI Syntax
doc.before("fragment"); // See XUI Syntax
doc.after("fragment"); // See XUI Syntax
doc.hasClass("class"); // See XUI Syntax
doc.addClass("class"); // See XUI Syntax
doc.removeClass("class"); // See XUI Syntax
doc.toHTML; // Returns the HTML
doc.innerHTML; // Returns the innerHTML of the body.
doc.toDOM; // Returns the DOM representation
// Most methods are chainable, so this works
doc.find("selector").addClass('foo').after(", just because");
});
13. generic-pool
// Create a MySQL connection pool with
// a max of 10 connections and a 30 second max idle time
var poolModule = require('generic-pool');
var pool = poolModule.Pool({
name : 'mysql',
create : function(callback) {
var Client = require('mysql').Client;
var c = new Client();
c.user = 'scott';
c.password = 'tiger';
c.database = 'mydb';
c.connect();
callback(c);
},
destroy : function(client) { client.end(); },
max : 10,
idleTimeoutMillis : 30000,
log : false
});
// borrow connection - callback function is called
// once a resource becomes available
pool.borrow(function(client) {
client.query("select * from foo", [], function() {
// return object back to pool
pool.returnToPool(client);
});
});