Best JavaScript code snippet using best
server.js
Source: server.js
1(function () {23 'use strict';45 var PORT = 5000,6 PROXY_URL = 'https://api.vk.com',7 LONG_POLL_URL = 'https://newimv4.vk.com',8 PHOTO_UPLOAD_URL = 'https://pu.vk.com/';910 var http = require('http'),11 url = require('url'),12 path = require('path'),13 fs = require('fs'),14 request = require('request'),15 mime = require('mime'),16 bodyParser = require('body-parser');1718 var server = http.createServer(function (req, res) {19 res.setHeader('Access-Control-Allow-Origin', '*');20 res.setHeader('Access-Control-Request-Method', '*');21 res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');22 res.setHeader('Access-Control-Allow-Headers', '*');2324 var urlData = url.parse(req.url),25 theUrl = urlData.pathname,26 someFileName = path.join(process.cwd(), theUrl);2728 res.on('error', function (err) {29 console.log(err);30 });3132 if (~theUrl.indexOf('method') || ~theUrl.indexOf('access_token')) {33 var proxyUrl = PROXY_URL + theUrl + (urlData.search || '');34 var proxyStream = request(proxyUrl);35 proxyStream.on('error', function (e) {36 console.log(e);37 res.end();38 proxyStream.destroy();39 });4041 req.pipe(proxyStream).pipe(res);4243 req.on('close', function () {44 proxyStream.destroy();45 res.destroy();46 });4748 } else if (~theUrl.indexOf('nim0800')) {49 var proxyUrl = LONG_POLL_URL + theUrl + (urlData.search || '');50 var proxyStream = request(proxyUrl);51 proxyStream.on('error', function (e) {52 res.end();53 proxyStream.destroy();54 });5556 req.pipe(proxyStream).pipe(res);5758 req.on('close', function () {59 proxyStream.destroy();60 res.destroy();61 });62 } else if (~theUrl.indexOf('pu.vk.com')) {6364 var proxyUrl = theUrl.substr(1, theUrl.length) + (urlData.search || '');65 var proxyStream = request.post(proxyUrl);6667 proxyStream.on('error', function (e) {68 res.end();69 proxyStream.destroy();70 });7172 req.pipe(proxyStream).pipe(res);7374 req.on('close', function () {75 proxyStream.destroy();76 res.destroy();77 });7879 } else {8081 if (theUrl === '/') {82 someFileName += 'web/index.html';83 }84 if (theUrl === '/messages' || theUrl === '/friends' || theUrl === '/photos' || theUrl === '/news') {85 someFileName = 'web/index.html';86 }87 if (theUrl === '/stylesheets/app.css') {88 someFileName = 'web/css/app.css';89 }9091 fs.exists(someFileName, function (exists) {92 var type = mime.lookup(someFileName);93 if (!exists) {94 res.writeHead(404, {'Content-Type': 'text/plain'});95 res.write('404 Nothing Here\n');96 res.end();97 return;98 }99 fs.readFile(someFileName, 'binary', function (err, file) {100 if (err) {101 res.writeHead(500, {'Content-Type': 'text/plain'});102 res.write(err + '\n');103 res.end();104 return;105 }106107 res.writeHead(200, {'Content-Type': type});108 res.write(file, 'binary');109 res.end();110 });111 });112 }113 });114115 server.listen(PORT);116117 console.log('Server running at http://localhost:' + PORT);118119 server.on('error', function () {120 server.listen(PORT);121 });122}());
...
index.all.js
Source: index.all.js
1var __extends = (this && this.__extends) || (function () {2 var extendStatics = Object.setPrototypeOf ||3 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||4 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };5 return function (d, b) {6 extendStatics(d, b);7 function __() { this.constructor = d; }8 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());9 };10})();11var core_1 = mostCore;12var ProxyStream = /** @class */ (function (_super) {13 __extends(ProxyStream, _super);14 function ProxyStream() {15 var _this = _super.call(this, core_1.never()) || this;16 _this.attached = false;17 _this.running = false;18 return _this;19 }20 ProxyStream.prototype.run = function (sink, scheduler) {21 this.scheduler = scheduler;22 this.add(sink);23 var shouldRun = this.attached && !this.running;24 if (shouldRun) {25 this.running = true;26 this.disposable = this.source.run(this, scheduler);27 return this.disposable;28 }29 return new ProxyDisposable(this, sink);30 };31 ProxyStream.prototype.attach = function (stream) {32 if (this.attached)33 throw new Error('Can only attach 1 stream');34 this.attached = true;35 this.source = stream;36 var hasMoreSinks = this.sinks.length > 0;37 if (hasMoreSinks)38 this.disposable = stream.run(this, this.scheduler);39 return stream;40 };41 ProxyStream.prototype.error = function (time, error) {42 this.cleanup();43 _super.prototype.error.call(this, time, error);44 };45 ProxyStream.prototype.end = function (time) {46 this.cleanup();47 _super.prototype.end.call(this, time);48 };49 ProxyStream.prototype.cleanup = function () {50 this.attached = false;51 this.running = false;52 };53 return ProxyStream;54}(core_1.MulticastSource));55var ProxyDisposable = /** @class */ (function () {56 function ProxyDisposable(source, sink) {57 this.source = source;58 this.sink = sink;59 this.disposed = false;60 }61 ProxyDisposable.prototype.dispose = function () {62 if (this.disposed)63 return;64 var _a = this, source = _a.source, sink = _a.sink;65 this.disposed = true;66 var remainingSinks = source.remove(sink);67 var hasNoMoreSinks = remainingSinks === 0;68 return hasNoMoreSinks && source.dispose();69 };70 return ProxyDisposable;71}());72//# sourceMappingURL=ProxyStream.js.map73var prelude_1 = mostPrelude;74function __event(time, value, sink) {75 sink.event(time, value);76}77function __error(time, error, sink) {78 sink.error(time, error);79}80function __end(time, sink) {81 sink.end(time);82}83function create(f) {84 if (f === void 0) { f = prelude_1.id; }85 var source = new ProxyStream.ProxyStream();86 return [source, f(source)];87}88function __attach(sink, stream) {89 return sink.attach(stream);90}91let attach = prelude_1.curry2(__attach);92let end = prelude_1.curry2(__end);93let error = prelude_1.curry3(__error);94let event = prelude_1.curry3(__event);...
index.ts
Source: index.ts
1import { StreamAdapter, Observer} from '@cycle/base'2export type Stream = any3export interface ProxyFn {4 (originalStream: Stream) : Stream 5} 6export const makeProxy = (adapter: StreamAdapter) => { 7 return (composeFn = (_: any) => _): Stream & { proxy: ProxyFn } => {8 const subject = adapter.makeSubject() 9 let proxyDispose: any10 let targetStream: Stream 11 const proxyStream = subject.stream12 const proxyObserver = subject.observer 13 proxyStream.proxy = (target: Stream) => {14 if (!target || !adapter.isValidStream(target)){15 throw new Error('You should provide a valid target stream to proxy')16 }17 if (targetStream){18 throw new Error('You may provide only one target stream to proxy')19 }20 targetStream = composeFn(target)21 proxyStream.__proxyRefs = 0 22 return adapter.adapt({}, (_: any, observer: Observer<any>) => { 23 let dispose = adapter.streamSubscribe(target, observer) 24 if (proxyStream.__proxyRefs++ === 0) { 25 proxyDispose = adapter.streamSubscribe(26 targetStream, proxyObserver27 ) 28 }29 return () => {30 dispose()31 if (--proxyStream.__proxyRefs === 0) {32 proxyDispose()33 proxyObserver.complete()34 if (proxyStream.__onProxyDispose) {35 proxyStream.__onProxyDispose()36 }37 }38 }39 })40 }41 return proxyStream42 }43}...
Using AI Code Generation
1using UnityEngine;2using System.Collections;3using BestHTTP;4public class test4 : MonoBehaviour {5 void Start () {6 request.Send();7 }8 void Update () {9 }10 void OnRequestFinished(HTTPRequest request, HTTPResponse response) {11 Debug.Log("OnRequestFinished");12 Debug.Log(response.DataAsText);13 }14}15using UnityEngine;16using System.Collections;17using BestHTTP;18public class test5 : MonoBehaviour {19 void Start () {20 request.Send();21 }22 void Update () {23 }24 void OnRequestFinished(HTTPRequest request, HTTPResponse response) {25 Debug.Log("OnRequestFinished");26 Debug.Log(response.DataAsText);27 }28}29using UnityEngine;30using System.Collections;31using BestHTTP;32public class test6 : MonoBehaviour {33 void Start () {34 request.Send();35 }36 void Update () {37 }38 void OnRequestFinished(HTTPRequest request, HTTPResponse response) {39 Debug.Log("On
Using AI Code Generation
1using System;2using System.IO;3using BestHTTP.Extensions;4using BestHTTP.Extensions.Proxy;5using BestHTTP.Logger;6using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;7{8 {9 public static Stream ProxyStream(Stream clientStream, Stream serverStream)10 {11 return ProxyStream(clientStream, serverStream, null);12 }13 public static Stream ProxyStream(Stream clientStream, Stream serverStream, ProxyAuthOptions authOptions)14 {15 return new ProxyStream(clientStream, serverStream, authOptions);16 }17 }18}19using System;20using System.IO;21using BestHTTP.Extensions;22using BestHTTP.Extensions.Proxy;23using BestHTTP.Logger;24using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;25{26 {27 public static Stream ProxyStream(Stream clientStream, Stream serverStream)28 {29 return ProxyStream(clientStream, serverStream, null);30 }31 public static Stream ProxyStream(Stream clientStream, Stream serverStream, ProxyAuthOptions authOptions)32 {33 return new ProxyStream(clientStream, serverStream, authOptions);34 }35 }36}
Check out the latest blogs from LambdaTest on this topic:
LambdaTest has recently received two notable awards from the leading business software directory FinancesOnline after their experts were impressed with our test platform’s capabilities in accelerating one’s development process.
The layout of a web page is one of the most important features of a web page. It can affect the traffic inflow by a significant margin. At times, a designer may come up with numerous layout ideas and sometimes he/she may struggle the entire day to come up with one. Moreover, design becomes even more important when it comes to ensuring cross browser compatibility.
Chrome is hands down the most used browsers by developers and users alike. It is the primary reason why there is such a solid chrome community and why there is a huge list of Chrome Extensions targeted at developers.
In a startup, the major strength of the people is that they are multitaskers. Be it anything, the founders and the core team wears multiple hats and takes complete responsibilities to get the ball rolling. From designing to deploying, from development to testing, everything takes place under the hawk eyes of founders and the core members.
We are in the era of the ‘Heads down’ generation. Ever wondered how much time you spend on your smartphone? Well, let us give you an estimate. With over 2.5 billion smartphone users, an average human spends approximately 2 Hours 51 minutes on their phone every day as per ComScore’s 2017 report. The number increases by an hour if we include the tab users as well!
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!