Best JavaScript code snippet using mountebank
rtl.js
Source:rtl.js
1Ext.require([2 'Ext.container.Viewport',3 'Ext.grid.Panel',4 'Ext.grid.plugin.RowEditing',5 'Ext.layout.container.Border'6]);7Ext.onReady(function() {8 var text = '\u0635\u0650\u0641 \u062E\u064E\u0644\u0642\u064E \u062E\u064E\u0648\u062F\u0650 \u0643\u064E\u0645\u0650\u062B\u0644\u0650 \u0627\u0644\u0634\u064E\u0645\u0633\u0650 \u0625\u0650\u0630 \u0628\u064E\u0632\u064E\u063A\u064E\u062A \u2014 \u064A\u064E\u062D\u0638\u0649 \u0627\u0644\u0636\u064E\u062C\u064A\u0639\u064F \u0628\u0650\u0647\u0627 \u0646\u064E\u062C\u0644\u0627\u0621\u064E \u0645\u0650\u0639\u0637\u0627\u0631\u0650',9 i = 50,10 sentences = [],11 words = text.split(' '),12 edCfg = {13 xtype: 'textfield' 14 },15 paragraph;16 17 while (i--) {18 sentences.push(text);19 }20 paragraph = sentences.join(' ');21 Ext.define('Fubar', {22 extend: 'Ext.data.Model',23 fields: [ 'foo', 'bar', 'baz', 'zork', 'gork', 'bork' ]24 });25 Ext.create('Ext.container.Viewport', {26 layout: 'border',27 rtl: true,28 items: [{29 region: 'north',30 title: '\u0634\u0645\u0627\u0644',31 height: 100,32 html: paragraph,33 autoScroll: true,34 collapsible: true,35 split: true36 },{37 region: 'west',38 id: 'west-region',39 title: '\u0627\u0644\u0645\u0646\u0637\u0642\u0629 \u0627\u0644\u063a\u0631\u0628\u064a\u0629',40 width: 200,41 collapsible: true,42 split: true,43 tbar: {44 enableOverflow: true,45 items: [{46 text: words[9]47 }, {48 text: words[3]49 }, {50 text: words[4]51 }, {52 text: words[0]53 }, {54 text: words[12]55 }]56 }57 }, {58 region: 'center',59 xtype: 'grid',60 plugins: [new Ext.grid.plugin.RowEditing()],61 title: '\u0645\u0631\u0643\u0632 \u0627\u0644\u0645\u0646\u0637\u0642\u0629',62 columns: [63 { dataIndex: 'foo', text: words[0], field: edCfg},64 { dataIndex: 'bar', text: words[1], field: edCfg },65 { dataIndex: 'baz', text: words[2], field: edCfg },66 { dataIndex: 'zork', text: words[3], field: edCfg },67 { dataIndex: 'gork', text: words[4], field: edCfg },68 { dataIndex: 'bork', text: words[5], field: edCfg, flex: 1 }69 ],70 store: Ext.create('Ext.data.Store', {71 model: 'Fubar',72 data: [73 [words[6], words[8], words[9], words[10], words[11], words[12]],74 [words[5], words[4], words[3], words[2], words[1], words[0]],75 [words[12], words[11], words[10], words[9], words[8], words[6]],76 [words[0], words[1], words[2], words[3], words[4], words[5]],77 [words[6], words[8], words[9], words[10], words[11], words[12]],78 [words[5], words[4], words[3], words[2], words[1], words[0]],79 [words[12], words[11], words[10], words[9], words[8], words[6]],80 [words[0], words[1], words[2], words[3], words[4], words[5]],81 [words[6], words[8], words[9], words[10], words[11], words[12]],82 [words[5], words[4], words[3], words[2], words[1], words[0]],83 [words[12], words[11], words[10], words[9], words[8], words[6]],84 [words[0], words[1], words[2], words[3], words[4], words[5]],85 [words[6], words[8], words[9], words[10], words[11], words[12]],86 [words[5], words[4], words[3], words[2], words[1], words[0]],87 [words[12], words[11], words[10], words[9], words[8], words[6]],88 [words[0], words[1], words[2], words[3], words[4], words[5]],89 [words[6], words[8], words[9], words[10], words[11], words[12]],90 [words[5], words[4], words[3], words[2], words[1], words[0]],91 [words[12], words[11], words[10], words[9], words[8], words[6]],92 [words[0], words[1], words[2], words[3], words[4], words[5]]93 ]94 })95 }, {96 region: 'east',97 title: '\u0627\u0644\u0645\u0646\u0637\u0642\u0629 \u0627\u0644\u0634\u0631\u0642\u064a\u0629',98 width: 200,99 collapsible: true,100 split: true101 }, {102 region: 'south',103 title: '\u062c\u0646\u0648\u0628 \u0627\u0644\u0645\u0646\u0637\u0642\u0629',104 height: 100,105 collapsible: true,106 split: true107 }]108 });...
run.py
Source:run.py
1# -*- coding:utf-8 -*-2import numpy as np3import json4from zemberek import Stemmer5stemmer = Stemmer()6# probability threshold7ERROR_THRESHOLD = 0.018# load our calculated synapse values9synapse_file = 'synapses.json'10with open(synapse_file) as data_file:11 synapse = json.load(data_file)12 synapse_0 = np.asarray(synapse['synapse0'])13 synapse_1 = np.asarray(synapse['synapse1'])14 words = synapse['words']15 classes = synapse['classes']16# compute sigmoid nonlinearity17def sigmoid(x):18 output = 1 / (1 + np.exp(-x))19 return output20# convert output of sigmoid function to its derivative21def sigmoid_output_to_derivative(output):22 return output * (1 - output)23def myStemmer(word):24 # kelime köklerini bulma iÅlemi yapılacak25 word = stemmer.stem(word)26 return word.lower()27def clean_up_sentence(sentence):28 sentence = sentence.strip()29 sentence_words = sentence.split(' ')30 words = [myStemmer(w) for w in sentence_words]31 stemmer.close()32 sentence_words = [w.replace('Ä', 'g') for w in words]33 sentence_words = [w.replace('Ä', 'g') for w in words]34 sentence_words = [w.replace('Ã', 'c') for w in words]35 sentence_words = [w.replace('ç', 'c') for w in words]36 sentence_words = [w.replace('ü', 'u') for w in words]37 sentence_words = [w.replace('Ã', 'u') for w in words]38 sentence_words = [w.replace('Ã', 'u') for w in words]39 sentence_words = [w.replace('Ã', 'o') for w in words]40 sentence_words = [w.replace('ö', 'o') for w in words]41 sentence_words = [w.replace('Ä°', 'i') for w in words]42 sentence_words = [w.replace('I', 'i') for w in words]43 sentence_words = [w.replace('ı', 'i') for w in words]44 sentence_words = [w.replace('Å', 's') for w in words]45 sentence_words = [w.replace('Å', 's') for w in words]46 sentence_words = [w.replace('\'', '') for w in words]47 sentence_words = [w.replace('"', '') for w in words]48 sentence_words = [w.replace('?', '') for w in words]49 sentence_words = [w.replace('!', '') for w in words]50 sentence_words = [w.replace('.', '') for w in words]51 sentence_words = [w.replace(',', '') for w in words]52 sentence_words = [w.replace(':', '') for w in words]53 sentence_words = [w.replace(';', '') for w in words]54 sentence_words = [w.replace('#', '') for w in words]55 sentence_words = [w.replace('-', ' ') for w in words]56 sentence_words = list(set(sentence_words))57 return sentence_words58# return bag of words array: 0 or 1 for each word in the bag that exists in the sentence59def bow(sentence, words, show_details=False):60 # tokenize the pattern61 sentence_words = clean_up_sentence(sentence)62 # bag of words63 bag = [0] * len(words)64 for s in sentence_words:65 for i, w in enumerate(words):66 if w == s:67 bag[i] = 168 if show_details:69 print ("found in bag: %s" % w)70 return (np.array(bag))71def think(sentence, show_details=False):72 #verilen cümlenin bag of words vektörünü hesaplıyor73 x = bow(sentence, words, show_details)74 #cümleyi ve bow u ekranda gösteriyor75 if show_details:76 print ("sentence:", sentence, "\n bow:", x)77 # input layer is our bag of words78 #layer 0 bag of words vektörü79 l0 = x80 # matrix multiplication of input and hidden layer81 # aÄırlıklarla layer 0 vektörünün çarpımı layer 1 in inputu oluyor82 l1 = sigmoid(np.dot(l0, synapse_0))83 # output layer84 # çıkıŠverisi layer1 ile aÄırlık 1 in çarpımı85 l2 = sigmoid(np.dot(l1, synapse_1))86 return l287def classify(sentence, show_details=False):88 #çıkıŠverisini alıyor89 results = think(sentence, show_details)90 #eÅik deÄerinden yüksek olan çıkıŠverisi çiftlerini alıyor91 #örn [2,0.953531243] 2 = class number, 0.95 = olasılık92 results = [[i,r] for i,r in enumerate(results) if r>ERROR_THRESHOLD ]93 #verileri sıralıyor94 results.sort(key=lambda x: x[1], reverse=True)95 return_results =[[classes[r[0]],r[1]] for r in results]96 print ("%s \n classification: %s" % (sentence, return_results))97 return return_results...
Postprocessing.py
Source:Postprocessing.py
1from TextIO import TextIO2from DefinitionCharacteristics import DefinitionCharacteristics3class Postprocessing:4 def __init__(self, candidate_words, size):5 self.candidate_words = candidate_words6 self.size = size7 self.PrelProc()8 def PrelProc(self):9 self.Rank_Cand()10 self.KSampCalculare()11 def Rank_Cand(self):12 for key_w in self.candidate_words:13 n_char = len(self.candidate_words[key_w]) - 114 for i in range(n_char):15 n = 116 for key_w in self.candidate_words:17 (self.candidate_words[key_w]).append(n)18 n += 119 for key_w in self.candidate_words:20 (self.candidate_words[key_w]).append(0)21 for key_w in self.candidate_words:22 for key_w2 in self.candidate_words:23 if self.candidate_words[key_w][1] < self.candidate_words[key_w2][1] and \24 self.candidate_words[key_w][1 + n_char] > self.candidate_words[key_w2][1 + n_char]:25 self.candidate_words[key_w][1 + n_char], self.candidate_words[key_w2][1 + n_char] =\26 self.candidate_words[key_w2][1 + n_char], self.candidate_words[key_w][1 + n_char]27 if self.candidate_words[key_w][2] < self.candidate_words[key_w2][2] and \28 self.candidate_words[key_w][2 + n_char] < self.candidate_words[key_w2][2 + n_char]:29 self.candidate_words[key_w][2 + n_char], self.candidate_words[key_w2][2 + n_char] = \30 self.candidate_words[key_w2][2 + n_char], self.candidate_words[key_w][2 + n_char]31 for key_w in self.candidate_words:32 for i in range(3, 5):33 self.candidate_words[key_w][5] = \34 (int(self.candidate_words[key_w][5]) + 1 / int(self.candidate_words[key_w][i]))35 print(self.candidate_words)36 print('Fin Rank_Cand')37 def KSampCalculare(self):38 sorted_x = self.candidate_words.items()39 KeyWords = []40 for n in sorted_x:41 KeyWords.append([n[0], n[1][5]])42 KeyWords.sort(key=lambda i: i[1], reverse=1)43 try:44 i = 045 self.fin_KeyWords = []46 while i < self.size:47 self.fin_KeyWords.append(KeyWords[i][0])48 i += 149 except IndexError:50 print('IndexError')51 print(self.fin_KeyWords)52 print('Fin KSampCalculare')53# base_text = TextIO()54# f = DefinitionCharacteristics(base_text.ReadJson('Text_dis_alg.json'))...
Using AI Code Generation
1var mb = require('mountebank');2var words = mb.words;3 {4 {5 {6 is: {7 }8 }9 }10 }11];12mb.start({13}, function () {14 console.log("Mountebank has started");15});16var mb = require('mountebank');17var words = mb.words;18mb.start({19}, function () {20 console.log("Mountebank has started");21});22var mb = require('mountebank');23var words = mb.words;24mb.start({25}, function () {26 console.log("Mountebank has started");27});28var mb = require('mountebank');29var words = mb.words;30mb.start({31}, function () {32 console.log("Mountebank has started");33});34var mb = require('mountebank');35var words = mb.words;36mb.start({37}, function () {38 console.log("Mountebank has started");39});40var mb = require('mount
Using AI Code Generation
1var mb = require('mountebank');2var words = mb.words;3var port = 2525;4 {5 {6 {7 "is": {8 }9 }10 }11 }12];13mb.create({port: port, ipWhitelist: ["*"]}, imposters)14 .then(function (server) {15 console.log("mb server started on port " + port);16 return server;17 })18 .then(function (server) {19 return server.get("/imposters");20 })21 .then(function (response) {22 console.log(words(response.body));23 })24 .then(function () {25 return mb.stopAll();26 })27 .then(function () {28 console.log("mb server stopped");29 })30 .catch(function (error) {31 console.error(error);32 });
Using AI Code Generation
1var mb = require('mountebank');2var assert = require('assert');3var Q = require('q');4{5{6{7"is": {8"headers": {9},10"body": {11}12}13}14}15}16];17mb.createImposters(imposters, function (error, response) {18assert.equal(response.statusCode, 201);19});20mb.getImposters(function (error, response, imposters) {21assert.equal(response.statusCode, 200);22assert.equal(imposters.length, 1);23});24mb.getImposter(3000, function (error, response, imposter) {25assert.equal(response.statusCode, 200);26assert.equal(imposter.port, 3000);27});28mb.deleteImposter(3000, function (error, response) {29assert.equal(response.statusCode, 200);30});31mb.deleteImposters(function (error, response) {32assert.equal(response.statusCode, 200);33});34mb.resetImposters(function (error, response) {35assert.equal(response.statusCode, 200);36});37mb.resetImposter(3000, function (error, response) {38assert.equal(response.statusCode, 200);39});40mb.getImposterLogs(3000, function (error, response, logs) {41assert.equal(response.statusCode, 200);42assert.equal(logs.length, 1);43});44mb.getImposterLog(3000, 0, function (error, response, log) {45assert.equal(response.statusCode, 200);46assert.equal(log.length, 1);47});48mb.getImposterRequests(3000, function (error, response, requests) {49assert.equal(response.statusCode, 200);50assert.equal(requests.length, 1);51});52mb.getImposterRequest(3000, 0, function (error, response, request) {53assert.equal(response.statusCode, 200);54assert.equal(request.length, 1);55});
Using AI Code Generation
1const mb = require('mountebank');2const fs = require('fs');3const path = require('path');4const port = 2525;5const protocol = 'http';6const host = 'localhost';7const imposter = {8 stubs: [{9 responses: [{10 is: {11 }12 }]13 }]14};15mb.start({ port, ip: '
Using AI Code Generation
1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var Q = require('q');5var port = 2525;6var imposters = [];7var imposter = {8 {9 {10 "is": {11 }12 }13 {14 "equals": {15 "query": {16 }17 }18 }19 }20};21var imposter1 = {22 {23 {24 "is": {25 }26 }27 {28 "equals": {29 "query": {30 }31 }32 }33 }34};35var imposter2 = {36 {37 {38 "is": {39 }40 }41 {42 "equals": {43 "query": {44 }45 }46 }47 }48};49imposters.push(imposter);50imposters.push(imposter1);51imposters.push(imposter2);52var imposterData = {53};54var options = {55};56mb.start(port)57 .then(function () {58 return mb.post('/imposters', imposterData);59 })60 .then(function (response) {61 console.log(response
Using AI Code Generation
1var mb = require('mountebank');2var imposter = mb.create();3var stub = {4 {5 is: {6 }7 }8};9var predicate = {10 equals: {11 }12};13var mock = {14 {15 is: {16 }17 }18};19var mockWithStub = {20};21var port = 2525;22imposter.create(port, mock)23 .then(function (response) {24 console.log(response);25 })26 .catch(function (error) {27 console.error(error);28 });29imposter.create(port, mockWithStub)30 .then(function (response) {31 console.log(response);32 })33 .catch(function (error) {34 console.error(error);35 });36imposter.create(port, mockWithStub)37 .then(function (response) {38 console.log(response);39 })40 .catch(function (error) {41 console.error(error);42 });43imposter.create(port, mockWithStub)44 .then(function (response) {45 console.log(response);46 })47 .catch(function (error) {48 console.error(error);49 });50imposter.create(port, mockWithStub)51 .then(function (response) {52 console.log(response);53 })54 .catch(function (error) {55 console.error(error);56 });57imposter.create(port, mockWithStub)58 .then(function (response) {59 console.log(response);60 })61 .catch(function (error) {62 console.error(error);63 });64imposter.create(port, mockWithStub)65 .then(function (response
Using AI Code Generation
1const { createImposterFromSpec } = require('mountebank');2const imposter = {3 {4 predicates: [{ equals: { method: 'GET' } }],5 responses: [{ is: { body: 'Hello World!' } }],6 },7};8createImposterFromSpec(imposter).then(() => {9 console.log('Imposter created');10});11const { createImposterFromSpec } = require('mountebank');12const imposter = {13 {14 predicates: [{ equals: { method: 'GET' } }],15 responses: [{ is: { body: 'Hello World!' } }],16 },17};18createImposterFromSpec(imposter).then(() => {19 console.log('Imposter created');20});21const { createImposterFromSpec } = require('mountebank');22const imposter = {23 {24 predicates: [{ equals: { method: 'GET' } }],25 responses: [{ is: { body: 'Hello World!' } }],26 },27};28createImposterFromSpec(imposter).then(() => {29 console.log('Imposter created');30});31const { createImposterFromSpec } = require('mountebank');32const imposter = {33 {34 predicates: [{ equals: { method: 'GET' } }],35 responses: [{ is: { body: 'Hello World!' } }],36 },37};38createImposterFromSpec(imposter).then(() => {
Using AI Code Generation
1var mb = require('mountebank');2var words = mb.words;3 if (error) {4 console.log('error', error);5 } else {6 console.log('response', response);7 }8});
Using AI Code Generation
1const mb = require('mountebank');2const words = mb.words;3const assert = require('assert');4const http = require('http');5const port = 2525;6const server = http.createServer((req, res) => {7 res.writeHead(200, {'Content-Type': 'text/plain'});8 res.end('Hello World!');9});10server.listen(port, () => {11});12describe('mb', function () {13 beforeEach(function () {14 this.mb = mb.create();15 });16 afterEach(function () {17 return this.mb.stop();18 });19 it('should be running', function () {20 return this.mb.start()21 .then(() => this.mb.get('/ping'))22 .then(response => {23 assert.equal(response.body, 'Hello!');24 });25 });26 it('should be running', function () {27 return this.mb.start()28 .then(() => this.mb.get(words.ping))29 .then(response => {30 assert.equal(response.body, 'Hello!');31 });32 });33});34 2 passing (1s)
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!!