Best JavaScript code snippet using chromy
plugin.js
Source:plugin.js
1/* 2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5var testthing;6CKEDITOR.plugins.add('bootstrapVisibility', {7 icons: false,8 lang: 'en,es,fr,it,ru',9 init: function(editor) {10 var lang = editor.lang.bootstrapVisibility;11 editor.filter.allow ( {12 textarea: {13 attributes: 'class',14 propertiesOnly: true15 },16 input: {17 attributes: 'class',18 propertiesOnly: true19 },20 select: {21 attributes: 'class',22 propertiesOnly: true23 },24 form: {25 attributes: 'class',26 propertiesOnly: true27 },28 button: {29 attributes: 'class',30 propertiesOnly: true31 },32 div: {33 attributes: 'class',34 propertiesOnly: true35 },36 img: {37 attributes: 'class',38 propertiesOnly: true39 },40 table: {41 attributes: 'class',42 propertiesOnly: true43 }44 }, 'formRequired');45 CKEDITOR.on('dialogDefinition', function(ev) {46 var dialogName = ev.data.name;47 var dialogDefinition = ev.data.definition;48 if(ev.data.definition.contents.length >=3) {49 ev.data.definition.minWidth=46050 }51 if(dialogName == 'checkbox' || dialogName == 'textfield' || dialogName == 'radio') {52 dialogDefinition.addContents( {53 id: 'responsiveVisibility',54 label: lang.respTabLabel,55 elements: [56 {57 id: 'respoVisibility',58 type: 'select',59 items: [60 [lang.none, ''],61 [lang.hidden_xs, 'hidden-xs'],62 [lang.hidden_sm, 'hidden-sm'],63 [lang.hidden_md, 'hidden-md'],64 [lang.hidden_lg, 'hidden-lg'],65 [lang.visible_xs_block, 'visible-xs-block'],66 [lang.visible_sm_block, 'visible-sm-block'],67 [lang.visible_md_block, 'visible-md-block'],68 [lang.visible_lg_block, 'visible-lg-block'],69 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],70 [lang.visible_sm_inline_block, 'visible-s--inline-block'],71 [lang.visible_md_inline_block, 'visible-md-inline-block'],72 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],73 [lang.visible_xs_inline, 'visible-xs-inline'],74 [lang.visible_sm_inline, 'visible-sm-inline'],75 [lang.visible_md_inline, 'visible-md-inline'],76 [lang.visible_lg_inline, 'visible-lg-inline']77 ],78 label: lang.visibilityLabel,79 setup: function(elem) {80 var value = elem.hasAttribute('class') && tws_getResponsiveVisibility( elem.getAttribute('class'));81 this.setValue(value);82 },83 commit: function(a) {84 var element = a.element;85 var val = this.getValue();86 var classes = tws_removeResponsiveClass(element.getAttribute('class'));87 88 if(classes.length != 'undefined' && classes.length>0) {89 classes = classes + ' ' + val;90 } else {91 classes = val;92 }93 if(classes.length != 'undefined' && classes.length >0) {94 element.setAttribute('class', classes.trim());95 } else {96 element.removeAttribute('class');97 }98 }99 },100 {101 type: 'html',102 html: '<p>'+lang.classDetailsHtml+'</p>'103 }104 ]105 });106 }107 else if(dialogName == 'select') {108 dialogDefinition.addContents( {109 id: 'responsiveVisibility',110 label: lang.respTabLabel,111 elements: [112 {113 id: 'respoVisibility',114 type: 'select',115 items: [116 [lang.none, ''],117 [lang.hidden_xs, 'hidden-xs'],118 [lang.hidden_sm, 'hidden-sm'],119 [lang.hidden_md, 'hidden-md'],120 [lang.hidden_lg, 'hidden-lg'],121 [lang.visible_xs_block, 'visible-xs-block'],122 [lang.visible_sm_block, 'visible-sm-block'],123 [lang.visible_md_block, 'visible-md-block'],124 [lang.visible_lg_block, 'visible-lg-block'],125 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],126 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],127 [lang.visible_md_inline_block, 'visible-md-inline-block'],128 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],129 [lang.visible_xs_inline, 'visible-xs-inline'],130 [lang.visible_sm_inline, 'visible-sm-inline'],131 [lang.visible_md_inline, 'visible-md-inline'],132 [lang.visible_lg_inline, 'visible-lg-inline']133 ],134 label: lang.visibilityLabel,135 setup: function(name, element) {136 if(name == 'clear') {137 this.setValue('');138 } else if(name == 'select') {139 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));140 this.setValue(value);141 }142 },143 commit: function(element) {144 var val = this.getValue();145 var classes = tws_removeResponsiveClass(element.getAttribute('class'));146 147 if(classes.length != 'undefined' && classes.length>0) {148 classes = classes + ' ' + val;149 } else {150 classes = val;151 }152 if(classes.length != 'undefined' && classes.length >0) {153 element.setAttribute('class', classes.trim());154 } else {155 element.removeAttribute('class');156 }157 }158 },159 {160 type: 'html',161 html: '<p>'+lang.classDetailsHtml+'</p>'162 }163 ]164 });165 } else if(dialogName == 'form' || dialogName == 'textarea') {166 dialogDefinition.addContents( {167 id: 'responsiveVisibility',168 label: lang.respTabLabel,169 elements: [170 {171 id: 'respoVisibility',172 type: 'select',173 items: [174 [lang.none, ''],175 [lang.hidden_xs, 'hidden-xs'],176 [lang.hidden_sm, 'hidden-sm'],177 [lang.hidden_md, 'hidden-md'],178 [lang.hidden_lg, 'hidden-lg'],179 [lang.visible_xs_block, 'visible-xs-block'],180 [lang.visible_sm_block, 'visible-sm-block'],181 [lang.visible_md_block, 'visible-md-block'],182 [lang.visible_lg_block, 'visible-lg-block'],183 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],184 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],185 [lang.visible_md_inline_block, 'visible-md-inline-block'],186 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],187 [lang.visible_xs_inline, 'visible-xs-inline'],188 [lang.visible_sm_inline, 'visible-sm-inline'],189 [lang.visible_md_inline, 'visible-md-inline'],190 [lang.visible_lg_inline, 'visible-lg-inline']191 ],192 label: lang.visibilityLabel,193 setup: function(element) {194 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));195 this.setValue(value);196 },197 commit: function(element) {198 var val = this.getValue();199 var classes = tws_removeResponsiveClass(element.getAttribute('class'));200 201 if(classes.length != 'undefined' && classes.length>0) {202 classes = classes + ' ' + val;203 } else {204 classes = val;205 }206 if(classes.length != 'undefined' && classes.length >0) {207 element.setAttribute('class', classes.trim());208 } else {209 element.removeAttribute('class');210 }211 }212 },213 {214 type: 'html',215 html: '<p>'+lang.classDetailsHtml+'</p>'216 }217 ]218 });219 } else if(dialogName == 'creatediv' || dialogName == 'editdiv') {220 dialogDefinition.addContents( {221 id: 'responsiveVisibility',222 label: lang.respTabLabel,223 elements: [224 {225 id: 'respoVisibility',226 type: 'select',227 items: [228 [lang.none, ''],229 [lang.hidden_xs, 'hidden-xs'],230 [lang.hidden_sm, 'hidden-sm'],231 [lang.hidden_md, 'hidden-md'],232 [lang.hidden_lg, 'hidden-lg'],233 [lang.visible_xs_block, 'visible-xs-block'],234 [lang.visible_sm_block, 'visible-sm-block'],235 [lang.visible_md_block, 'visible-md-block'],236 [lang.visible_lg_block, 'visible-lg-block'],237 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],238 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],239 [lang.visible_md_inline_block, 'visible-md-inline-block'],240 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],241 [lang.visible_xs_inline, 'visible-xs-inline'],242 [lang.visible_sm_inline, 'visible-sm-inline'],243 [lang.visible_md_inline, 'visible-md-inline'],244 [lang.visible_lg_inline, 'visible-lg-inline']245 ],246 label: lang.visibilityLabel,247 setup: function(element) {248 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));249 this.setValue(value);250 },251 commit: function(element) {252 var val = this.getValue();253 var classes = tws_removeResponsiveClass(element.getAttribute('class'));254 255 if(classes.length != 'undefined' && classes.length>0) {256 classes = classes + ' ' + val;257 } else {258 classes = val;259 }260 if(classes.length != 'undefined' && classes.length >0) {261 element.setAttribute('class', classes.trim());262 } else {263 element.removeAttribute('class');264 }265 }266 },267 {268 type: 'html',269 html: '<p>'+lang.classDetailsHtml+'</p>'270 }271 ]272 });273 }274 else if(dialogName == 'button') {275 dialogDefinition.addContents( {276 id: 'responsiveVisibility',277 label: lang.respTabLabel,278 elements: [279 {280 id: 'respoVisibility',281 type: 'select',282 items: [283 [lang.none, ''],284 [lang.hidden_xs, 'hidden-xs'],285 [lang.hidden_sm, 'hidden-sm'],286 [lang.hidden_md, 'hidden-md'],287 [lang.hidden_lg, 'hidden-lg'],288 [lang.visible_xs_block, 'visible-xs-block'],289 [lang.visible_sm_block, 'visible-sm-block'],290 [lang.visible_md_block, 'visible-md-block'],291 [lang.visible_lg_block, 'visible-lg-block'],292 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],293 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],294 [lang.visible_md_inline_block, 'visible-md-inline-block'],295 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],296 [lang.visible_xs_inline, 'visible-xs-inline'],297 [lang.visible_sm_inline, 'visible-sm-inline'],298 [lang.visible_md_inline, 'visible-md-inline'],299 [lang.visible_lg_inline, 'visible-lg-inline']300 ],301 label: lang.visibilityLabel,302 setup: function(element) {303 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));304 this.setValue(value);305 },306 commit: function(elem) {307 var val = this.getValue();308 var element = elem.element;309 var classes = tws_removeResponsiveClass(element.getAttribute('class'));310 311 if(classes.length != 'undefined' && classes.length>0) {312 classes = classes + ' ' + val;313 } else {314 classes = val;315 }316 if(classes.length != 'undefined' && classes.length >0) {317 element.setAttribute('class', classes.trim());318 } else {319 element.removeAttribute('class');320 }321 }322 },323 {324 type: 'html',325 html: '<p>'+lang.classDetailsHtml+'</p>'326 }327 ]328 });329 }330 else if(dialogName == 'tableProperties' || dialogName == 'table') {331 dialogDefinition.addContents( {332 id: 'responsiveVisibility',333 label: lang.respTabLabel,334 elements: [335 {336 id: 'respoVisibility',337 type: 'select',338 items: [339 [lang.none, ''],340 [lang.hidden_xs, 'hidden-xs'],341 [lang.hidden_sm, 'hidden-sm'],342 [lang.hidden_md, 'hidden-md'],343 [lang.hidden_lg, 'hidden-lg'],344 [lang.visible_xs_block, 'visible-xs-block'],345 [lang.visible_sm_block, 'visible-sm-block'],346 [lang.visible_md_block, 'visible-md-block'],347 [lang.visible_lg_block, 'visible-lg-block'],348 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],349 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],350 [lang.visible_md_inline_block, 'visible-md-inline-block'],351 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],352 [lang.visible_xs_inline, 'visible-xs-inline'],353 [lang.visible_sm_inline, 'visible-sm-inline'],354 [lang.visible_md_inline, 'visible-md-inline'],355 [lang.visible_lg_inline, 'visible-lg-inline']356 ],357 label: lang.visibilityLabel,358 setup: function(element) {359 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));360 this.setValue(value);361 },362 commit: function(hmm,element) {363 var val = this.getValue();364 var classes = tws_removeResponsiveClass(element.getAttribute('class'));365 366 if(classes.length != 'undefined' && classes.length>0) {367 classes = classes + ' ' + val;368 } else {369 classes = val;370 }371 if(classes.length != 'undefined' && classes.length >0) {372 element.setAttribute('class', classes.trim());373 } else {374 element.removeAttribute('class');375 }376 }377 },378 {379 type: 'html',380 html: '<p>'+lang.classDetailsHtml+'</p>'381 }382 ]383 });384 }385 else if(dialogName == 'image' || dialogName == 'imagebutton') {386 dialogDefinition.addContents( {387 id: 'responsiveVisibility',388 label: lang.respTabLabel,389 elements: [390 {391 id: 'respoVisibility',392 type: 'select',393 items: [394 [lang.none, ''],395 [lang.hidden_xs, 'hidden-xs'],396 [lang.hidden_sm, 'hidden-sm'],397 [lang.hidden_md, 'hidden-md'],398 [lang.hidden_lg, 'hidden-lg'],399 [lang.visible_xs_block, 'visible-xs-block'],400 [lang.visible_sm_block, 'visible-sm-block'],401 [lang.visible_md_block, 'visible-md-block'],402 [lang.visible_lg_block, 'visible-lg-block'],403 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],404 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],405 [lang.visible_md_inline_block, 'visible-md-inline-block'],406 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],407 [lang.visible_xs_inline, 'visible-xs-inline'],408 [lang.visible_sm_inline, 'visible-sm-inline'],409 [lang.visible_md_inline, 'visible-md-inline'],410 [lang.visible_lg_inline, 'visible-lg-inline']411 ],412 label: lang.visibilityLabel,413 setup: function(hmm, element) {414 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));415 this.setValue(value);416 },417 commit: function(hmm,element) {418 var val = this.getValue();419 var classes = tws_removeResponsiveClass(element.getAttribute('class'));420 421 if(classes.length != 'undefined' && classes.length>0) {422 classes = classes + ' ' + val;423 } else {424 classes = val;425 }426 if(classes.length != 'undefined' && classes.length >0) {427 element.setAttribute('class', classes.trim());428 } else {429 element.removeAttribute('class');430 }431 }432 },433 {434 type: 'html',435 html: '<p>'+lang.classDetailsHtml+'</p>'436 }437 ]438 });439 }440 else if(dialogName == 'flash') {441 dialogDefinition.addContents( {442 id: 'responsiveVisibility',443 label: lang.respTabLabel,444 elements: [445 {446 id: 'respoVisibility',447 type: 'select',448 items: [449 [lang.none, ''],450 [lang.hidden_xs, 'hidden-xs'],451 [lang.hidden_sm, 'hidden-sm'],452 [lang.hidden_md, 'hidden-md'],453 [lang.hidden_lg, 'hidden-lg'],454 [lang.visible_xs_block, 'visible-xs-block'],455 [lang.visible_sm_block, 'visible-sm-block'],456 [lang.visible_md_block, 'visible-md-block'],457 [lang.visible_lg_block, 'visible-lg-block'],458 [lang.visible_xs_inline_block, 'visible-xs-inline-block'],459 [lang.visible_sm_inline_block, 'visible-sm-inline-block'],460 [lang.visible_md_inline_block, 'visible-md-inline-block'],461 [lang.visible_lg_inline_block, 'visible-lg-inline-block'],462 [lang.visible_xs_inline, 'visible-xs-inline'],463 [lang.visible_sm_inline, 'visible-sm-inline'],464 [lang.visible_md_inline, 'visible-md-inline'],465 [lang.visible_lg_inline, 'visible-lg-inline']466 ],467 label: lang.visibilityLabel,468 setup: function(element,b,c) {469 var value = element.hasAttribute('class') && tws_getResponsiveVisibility( element.getAttribute('class'));470 this.setValue(value);471 },472 commit: function(element,b,c,d) {473 var val = this.getValue();474 var classes = tws_removeResponsiveClass(element.getAttribute('class'));475 476 if(classes.length != 'undefined' && classes.length>0) {477 classes = classes + ' ' + val;478 } else {479 classes = val;480 }481 if(classes.length != 'undefined' && classes.length >0) {482 element.setAttribute('class', classes.trim());483 } else {484 element.removeAttribute('class');485 }486 }487 },488 {489 type: 'html',490 html: '<p>'+lang.classDetailsHtml+'</p>'491 }492 ]493 });494 }495 });496 497 }498 499 500});501function isArray(arr) {502 return arr.constructor.toString().indexOf("Array") > -1;503}504function tws_isResponsiveClass(className) {505 var responsiveClassList = new Array(506 'hidden-xs','hidden-sm','hidden-md','hidden-lg',507 'visible-xs-block','visible-sm-block','visible-md-block','visible-lg-block',508 'visible-xs-inline-block','visible-sm-inline-block', 'visible-md-inline-block','visible-lg-inline-block',509 'visible-xs-inline', 'visible-sm-inline','visible-md-inline,','visible-lg-inline'510 );511 512 for(i=0;i<responsiveClassList.length;i++) {513 if(className == responsiveClassList[i]) {514 return true;515 }516 }517 return false;518}519function tws_getResponsiveVisibility(classes) {520 if(classes.length > 0) {521 list = classes.split(' ');522 if(isArray(list)) {523 for(iasd=0; iasd<list.length; iasd++) {524 if(tws_isResponsiveClass(list[iasd])) {525 return list[iasd];526 }527 }528 } else {529 if(tws_isResponsiveClass(list)) {530 return list;531 532 } else {533 return '';534 }535 }536 }537 return '';538}539function tws_removeResponsiveClass(classes) {540 var returnData = '';541 if( classes != null && classes.length>0) {542 list = classes.split(' ');543 if(isArray(list)) {544 for(ib=0;ib<list.length;ib++) {545 if(!tws_isResponsiveClass(list[ib])) {546 returnData = returnData + ' '+list[ib];547 }548 }549 } else {550 returnData = classes;551 }552 }553 return returnData.trim();...
rbm.py
Source:rbm.py
...93 :return: self94 """95 self._create_placeholders(n_features)96 self._create_variables(n_features)97 self.encode = self.sample_hidden_from_visible(self.input_data)[0]98 self.reconstruction = self.sample_visible_from_hidden(99 self.encode, n_features)100 hprob0, hstate0, vprob, hprob1, hstate1 = self.gibbs_sampling_step(101 self.input_data, n_features)102 positive = self.compute_positive_association(self.input_data,103 hprob0, hstate0)104 nn_input = vprob105 for step in range(self.gibbs_sampling_steps - 1):106 hprob, hstate, vprob, hprob1, hstate1 = self.gibbs_sampling_step(107 nn_input, n_features)108 nn_input = vprob109 negative = tf.matmul(tf.transpose(vprob), hprob1)110 self.w_upd8 = self.W.assign_add(111 self.learning_rate * (positive - negative) / self.batch_size)112 self.bh_upd8 = self.bh_.assign_add(tf.multiply(self.learning_rate, tf.reduce_mean(113 tf.subtract(hprob0, hprob1), 0)))114 self.bv_upd8 = self.bv_.assign_add(tf.multiply(self.learning_rate, tf.reduce_mean(115 tf.subtract(self.input_data, vprob), 0)))116 variables = [self.W, self.bh_, self.bv_]117 regterm = Layers.regularization(variables, self.regtype, self.regcoef)118 self.cost = self.loss.compile(vprob, self.input_data, regterm=regterm)119 def _create_placeholders(self, n_features):120 """Create the TensorFlow placeholders for the model.121 :param n_features: number of features122 :return: self123 """124 self.input_data = tf.placeholder(tf.float32, [None, n_features],125 name='x-input')126 self.hrand = tf.placeholder(tf.float32, [None, self.num_hidden],127 name='hrand')128 self.vrand = tf.placeholder(tf.float32, [None, n_features],129 name='vrand')130 # not used in this model, created just to comply with131 # unsupervised_model.py132 self.input_labels = tf.placeholder(tf.float32)133 self.keep_prob = tf.placeholder(tf.float32, name='keep-probs')134 def _create_variables(self, n_features):135 """Create the TensorFlow variables for the model.136 :param n_features: number of features137 :return: self138 """139 w_name = 'weights'140 self.W = tf.Variable(tf.truncated_normal(141 shape=[n_features, self.num_hidden], stddev=0.1), name=w_name)142 tf.summary.histogram(w_name, self.W)143 bh_name = 'hidden-bias'144 self.bh_ = tf.Variable(tf.constant(0.1, shape=[self.num_hidden]),145 name=bh_name)146 tf.summary.histogram(bh_name, self.bh_)147 bv_name = 'visible-bias'148 self.bv_ = tf.Variable(tf.constant(0.1, shape=[n_features]),149 name=bv_name)150 tf.summary.histogram(bv_name, self.bv_)151 def gibbs_sampling_step(self, visible, n_features):152 """Perform one step of gibbs sampling.153 :param visible: activations of the visible units154 :param n_features: number of features155 :return: tuple(hidden probs, hidden states, visible probs,156 new hidden probs, new hidden states)157 """158 hprobs, hstates = self.sample_hidden_from_visible(visible)159 vprobs = self.sample_visible_from_hidden(hprobs, n_features)160 hprobs1, hstates1 = self.sample_hidden_from_visible(vprobs)161 return hprobs, hstates, vprobs, hprobs1, hstates1162 def sample_hidden_from_visible(self, visible):163 """Sample the hidden units from the visible units.164 This is the Positive phase of the Contrastive Divergence algorithm.165 :param visible: activations of the visible units166 :return: tuple(hidden probabilities, hidden binary states)167 """168 hprobs = tf.nn.sigmoid(tf.add(tf.matmul(visible, self.W), self.bh_))169 hstates = utilities.sample_prob(hprobs, self.hrand)170 return hprobs, hstates171 def sample_visible_from_hidden(self, hidden, n_features):172 """Sample the visible units from the hidden units.173 This is the Negative phase of the Contrastive Divergence algorithm.174 :param hidden: activations of the hidden units175 :param n_features: number of features176 :return: visible probabilities...
visible_rect.py
Source:visible_rect.py
1import numpy as np23from rectangle import Rectangle4import copy56class RegionRect:7 def __init__(self, x, y, visible_region):8 self.x = x9 self.y = y10 self.visible_region = visible_region11 self.width = self.visible_region.shape[1]12 self.height = self.visible_region.shape[0]13 self.rect = Rectangle(x, y, x + self.width, y + self.height)1415 def __deepcopy__(self, memo_dict):16 x = self.x17 y = self.y18 visible_region = np.copy(self.visible_region)19 return RegionRect(x, y, visible_region)2021 @staticmethod22 def compute_visible_clipping(inner_visible_region_rect, outer_visible_region_rect):23 intersect_rect = inner_visible_region_rect.rect & outer_visible_region_rect.rect24 if intersect_rect is None:25 return None26 intersect_visible_region = inner_visible_region_rect.visible_region[27 intersect_rect.y1 - inner_visible_region_rect.rect.y1:intersect_rect.y1 - inner_visible_region_rect.rect.y1 + intersect_rect.get_height(),28 intersect_rect.x1 - inner_visible_region_rect.rect.x1:intersect_rect.x1 - inner_visible_region_rect.rect.x1 + intersect_rect.get_width()29 ]30 intersect_visible_region = np.copy(intersect_visible_region)31 outer_intersect_visible_region = outer_visible_region_rect.visible_region[32 intersect_rect.y1 - outer_visible_region_rect.rect.y1:intersect_rect.y1 - outer_visible_region_rect.rect.y1 + intersect_rect.get_height(),33 intersect_rect.x1 - outer_visible_region_rect.rect.x1:intersect_rect.x1 - outer_visible_region_rect.rect.x1 + intersect_rect.get_width()34 ]35 intersect_visible_region = np.bitwise_and(intersect_visible_region, outer_intersect_visible_region)36 return RegionRect(intersect_rect.x1, intersect_rect.y1, intersect_visible_region)373839 def check_if_overlapped_with(self, outer_visible_region_rect):40 intersect_rect = self.rect & outer_visible_region_rect.rect41 if intersect_rect is None:42 return False43 intersect_self_region = self.visible_region[44 intersect_rect.y1 - self.rect.y1:intersect_rect.y1 - self.rect.y1 + intersect_rect.get_height(),45 intersect_rect.x1 - self.rect.x1:intersect_rect.x1 - self.rect.x1 + intersect_rect.get_width()46 ]47 outer_intersect_visible_region = outer_visible_region_rect.visible_region[48 intersect_rect.y1 - outer_visible_region_rect.rect.y1:intersect_rect.y1 - outer_visible_region_rect.rect.y1 + intersect_rect.get_height(),49 intersect_rect.x1 - outer_visible_region_rect.rect.x1:intersect_rect.x1 - outer_visible_region_rect.rect.x1 + intersect_rect.get_width()50 ]51 result = np.bitwise_and(intersect_self_region, outer_intersect_visible_region)52 result = np.bitwise_and(result, intersect_self_region)53 if np.sum(result) > 0:54 return True55 return False5657 @staticmethod58 def compute_visible_subintersect(inner_visible_region_rect, outer_visible_region_rect):59 result_region_rect = copy.deepcopy(inner_visible_region_rect)60 intersect_rect = result_region_rect.rect & outer_visible_region_rect.rect61 if intersect_rect is None:62 return result_region_rect63 intersect_visible_region = result_region_rect.visible_region[64 intersect_rect.y1 - result_region_rect.rect.y1:intersect_rect.y1 - result_region_rect.rect.y1 + intersect_rect.get_height(),65 intersect_rect.x1 - result_region_rect.rect.x1:intersect_rect.x1 - result_region_rect.rect.x1 + intersect_rect.get_width()66 ]67 outer_intersect_visible_region = outer_visible_region_rect.visible_region[68 intersect_rect.y1 - outer_visible_region_rect.rect.y1:intersect_rect.y1 - outer_visible_region_rect.rect.y1 + intersect_rect.get_height(),69 intersect_rect.x1 - outer_visible_region_rect.rect.x1:intersect_rect.x1 - outer_visible_region_rect.rect.x1 + intersect_rect.get_width()70 ]71 outer_intersect_visible_region = np.bitwise_not(outer_intersect_visible_region)72 union = np.bitwise_and(intersect_visible_region, outer_intersect_visible_region)73 result_region_rect.visible_region[74 intersect_rect.y1 - result_region_rect.rect.y1:intersect_rect.y1 - result_region_rect.rect.y1 + intersect_rect.get_height(),75 intersect_rect.x1 - result_region_rect.rect.x1:intersect_rect.x1 - result_region_rect.rect.x1 + intersect_rect.get_width()76 ] = union77 return result_region_rect7879 @staticmethod80 def compute_visible_subtract(inner_visible_region_rect, outer_visible_region_rect):81 result_region_rect = copy.deepcopy(inner_visible_region_rect)82 intersect_rect = result_region_rect.rect & outer_visible_region_rect.rect83 if intersect_rect is None:84 return result_region_rect85 intersect_visible_region = result_region_rect.visible_region[86 intersect_rect.y1 - result_region_rect.rect.y1:intersect_rect.y1 - result_region_rect.rect.y1 + intersect_rect.get_height(),87 intersect_rect.x1 - result_region_rect.rect.x1:intersect_rect.x1 - result_region_rect.rect.x1 + intersect_rect.get_width()88 ]89 outer_intersect_visible_region = outer_visible_region_rect.visible_region[90 intersect_rect.y1 - outer_visible_region_rect.rect.y1:intersect_rect.y1 - outer_visible_region_rect.rect.y1 + intersect_rect.get_height(),91 intersect_rect.x1 - outer_visible_region_rect.rect.x1:intersect_rect.x1 - outer_visible_region_rect.rect.x1 + intersect_rect.get_width()92 ]93 union = np.where(outer_intersect_visible_region>0, False, intersect_visible_region)94 # outer_intersect_visible_region = np.bitwise_not(outer_intersect_visible_region)95 # union = np.bitwise_and(intersect_visible_region, outer_intersect_visible_region)96 result_region_rect.visible_region[97 intersect_rect.y1 - result_region_rect.rect.y1:intersect_rect.y1 - result_region_rect.rect.y1 + intersect_rect.get_height(),98 intersect_rect.x1 - result_region_rect.rect.x1:intersect_rect.x1 - result_region_rect.rect.x1 + intersect_rect.get_width()99 ] = union100 return result_region_rect101102 def get_visible_region(self, visible_region_rect):103 if visible_region_rect is None:104 return self.visible_region105 intersect_rect = self.rect & visible_region_rect.rect106 if intersect_rect is None:107 return None108 y1 = intersect_rect.y1 - self.rect.y1109 x1 = intersect_rect.x1 - self.rect.x1110 intersect_region = self.visible_region[y1:y1+intersect_rect.get_height(),111 x1:x1+intersect_rect.get_width()]112 y1 = intersect_rect.y1 - visible_region_rect.rect.y1113 x1 = intersect_rect.x1 - visible_region_rect.rect.x1114 intersect_visible_region = visible_region_rect.visible_region[y1:y1+intersect_rect.get_height(),115 x1:x1+intersect_rect.get_width()]116 return np.bitwise_and(intersect_region, intersect_visible_region)117118 @staticmethod119 def compute_height_and_width(visible_region):120 """121 return the minimum region containing the content region122 :param visible_region: a region containing information123 :return: the height and width of this minimum region124 """125 width = np.sum(np.where(np.sum(visible_region, axis=0) > 0, 1, 0))126 height = np.sum(np.where(np.sum(visible_region, axis=1) > 0, 1, 0))127 return height, width128129 @staticmethod130 def compute_offset(visible_region):131 """132 return the minimum region containing the content region133 :param visible_region: a region containing information134 :return: the height and width of this minimum region135 """136 width = np.where(np.sum(visible_region, axis=0) > 0, 1, 0)137 width_index = np.argwhere(width==1).reshape((-1))138 if len(width_index)>1:139 width_offset = sorted(width_index)[0]140 else:141 width_offset = -1142143 height = np.where(np.sum(visible_region, axis=1) > 0, 1, 0)144 height_index = np.argwhere(height == 1).reshape((-1))145 if len(height_index) > 1:146 height_offset = sorted(height_index)[0]147 else:148 height_offset = -1149 if height_offset!=-1 and height_offset!=-1:150 visible_region = visible_region[height_offset:height_offset+np.sum(height),151 width_offset:width_offset+np.sum(width)]152153
...
modifyclusterattributes.py
Source:modifyclusterattributes.py
1# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from awscli.customizations.emr import emrutils14from awscli.customizations.emr import exceptions15from awscli.customizations.emr import helptext16from awscli.customizations.emr.command import Command17class ModifyClusterAttr(Command):18 NAME = 'modify-cluster-attributes'19 DESCRIPTION = ("Modifies the cluster attributes 'visible-to-all-users' and"20 " 'termination-protected'.")21 ARG_TABLE = [22 {'name': 'cluster-id', 'required': True,23 'help_text': helptext.CLUSTER_ID},24 {'name': 'visible-to-all-users', 'required': False, 'action':25 'store_true', 'group_name': 'visible',26 'help_text': 'Change cluster visibility for IAM users'},27 {'name': 'no-visible-to-all-users', 'required': False, 'action':28 'store_true', 'group_name': 'visible',29 'help_text': 'Change cluster visibility for IAM users'},30 {'name': 'termination-protected', 'required': False, 'action':31 'store_true', 'group_name': 'terminate',32 'help_text': 'Set termination protection on or off'},33 {'name': 'no-termination-protected', 'required': False, 'action':34 'store_true', 'group_name': 'terminate',35 'help_text': 'Set termination protection on or off'},36 ]37 def _run_main_command(self, args, parsed_globals):38 if (args.visible_to_all_users and args.no_visible_to_all_users):39 raise exceptions.MutualExclusiveOptionError(40 option1='--visible-to-all-users',41 option2='--no-visible-to-all-users')42 if (args.termination_protected and args.no_termination_protected):43 raise exceptions.MutualExclusiveOptionError(44 option1='--termination-protected',45 option2='--no-termination-protected')46 if not(args.termination_protected or args.no_termination_protected or47 args.visible_to_all_users or args.no_visible_to_all_users):48 raise exceptions.MissingClusterAttributesError()49 if (args.visible_to_all_users or args.no_visible_to_all_users):50 visible = (args.visible_to_all_users and51 not args.no_visible_to_all_users)52 parameters = {'JobFlowIds': [args.cluster_id],53 'VisibleToAllUsers': visible}54 emrutils.call_and_display_response(self._session,55 'SetVisibleToAllUsers',56 parameters, parsed_globals)57 if (args.termination_protected or args.no_termination_protected):58 protected = (args.termination_protected and59 not args.no_termination_protected)60 parameters = {'JobFlowIds': [args.cluster_id],61 'TerminationProtected': protected}62 emrutils.call_and_display_response(self._session,63 'SetTerminationProtection',64 parameters, parsed_globals)...
object_interactivity.js
Source:object_interactivity.js
1(function() {2 QUnit.module('fabric.ObjectInteractivity');3 test('isControlVisible', function(){4 ok(fabric.Object);5 var cObj = new fabric.Object({ });6 ok(typeof cObj.isControlVisible == 'function', 'isControlVisible should exist');7 equal(cObj.isControlVisible('tl'), true);8 equal(cObj.isControlVisible('tr'), true);9 equal(cObj.isControlVisible('br'), true);10 equal(cObj.isControlVisible('bl'), true);11 equal(cObj.isControlVisible('ml'), true);12 equal(cObj.isControlVisible('mt'), true);13 equal(cObj.isControlVisible('mr'), true);14 equal(cObj.isControlVisible('mb'), true);15 equal(cObj.isControlVisible('mtr'), true);16 });17 test('setControlVisible', function(){18 ok(fabric.Object);19 var cObj = new fabric.Object({ });20 ok(typeof cObj.setControlVisible == 'function', 'setControlVisible should exist');21 equal(cObj.setControlVisible('tl'), cObj, 'chainable');22 cObj.setControlVisible('tl', false);23 equal(cObj.isControlVisible('tl'), false);24 cObj.setControlVisible('tl', true);25 equal(cObj.isControlVisible('tl'), true);26 });27 test('setControlsVisibility', function(){28 ok(fabric.Object);29 var cObj = new fabric.Object({ });30 ok(typeof cObj.setControlsVisibility == 'function', 'setControlsVisibility should exist');31 equal(cObj.setControlsVisibility(), cObj, 'chainable');32 cObj.setControlsVisibility({33 bl: false,34 br: false,35 mb: false,36 ml: false,37 mr: false,38 mt: false,39 tl: false,40 tr: false,41 mtr: false42 });43 equal(cObj.isControlVisible('tl'), false);44 equal(cObj.isControlVisible('tr'), false);45 equal(cObj.isControlVisible('br'), false);46 equal(cObj.isControlVisible('bl'), false);47 equal(cObj.isControlVisible('ml'), false);48 equal(cObj.isControlVisible('mt'), false);49 equal(cObj.isControlVisible('mr'), false);50 equal(cObj.isControlVisible('mb'), false);51 equal(cObj.isControlVisible('mtr'), false);52 cObj.setControlsVisibility({53 bl: true,54 br: true,55 mb: true,56 ml: true,57 mr: true,58 mt: true,59 tl: true,60 tr: true,61 mtr: true62 });63 equal(cObj.isControlVisible('tl'), true);64 equal(cObj.isControlVisible('tr'), true);65 equal(cObj.isControlVisible('br'), true);66 equal(cObj.isControlVisible('bl'), true);67 equal(cObj.isControlVisible('ml'), true);68 equal(cObj.isControlVisible('mt'), true);69 equal(cObj.isControlVisible('mr'), true);70 equal(cObj.isControlVisible('mb'), true);71 equal(cObj.isControlVisible('mtr'), true);72 });...
Using AI Code Generation
1const Chromy = require('chromy');2(async function() {3 const chromy = new Chromy();4 await chromy.chain()5 .visible('#hplogo')6 .end()7 .result(function(err, r) {8 console.log(r);9 });10})();11const puppeteer = require('puppeteer');12(async function() {13 const browser = await puppeteer.launch();14 const page = await browser.newPage();15 const logo = await page.$('#hplogo');16 const isVisible = await page.evaluate(logo => {17 const style = window.getComputedStyle(logo);18 return (style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0');19 }, logo);20 console.log(isVisible);21 await browser.close();22})();23var casper = require('casper').create();24 this.echo(this.visible('#hplogo'));25});26casper.run();27const webdriverio = require('webdriverio');28const options = {29 desiredCapabilities: {30 }31};32(async function() {33 const browser = await webdriverio.remote(options);34 const isVisible = await browser.isVisible('#hplogo');35 console.log(isVisible);36 await browser.end();37})();38const nightwatch = require('nightwatch');39const client = nightwatch.initClient();40client.isVisible('#hplogo', function(result) {41 console.log(result.value);42 client.end();43});44const webdriver = require('selenium-webdriver');45const driver = new webdriver.Builder()46 .forBrowser('chrome')47 .build();48driver.findElement(webdriver.By.id('hplogo')).isDisplayed().then(function(isVisible) {49 console.log(isVisible);50 driver.quit();51});
Using AI Code Generation
1const chromy = require('chromy');2chromy.chain()3 .visible('#not-exist')4 .result(function (visible) {5 })6 .end()7 .then(function () {8 chromy.close();9 });10### waitForVisible(selector, [options])11const chromy = require('chromy');12chromy.chain()13 .waitForVisible('#not-exist')14 .result(function (visible) {15 })16 .end()17 .then(function () {18 chromy.close();19 });20### waitForVisible(selector, [options])21const chromy = require('chromy');22chromy.chain()23 .waitForInvisible('#not-exist')24 .result(function (visible) {25 })26 .end()27 .then(function () {28 chromy.close();29 });30### text(selector, [options])31const chromy = require('chromy');32chromy.chain()33 .text('#not-exist')34 .result(function (text) {35 })36 .end()37 .then(function () {38 chromy.close();39 });40### value(selector, [options])41const chromy = require('chromy');42chromy.chain()43 .value('#not-exist')44 .result(function
Using AI Code Generation
1var chromy = new Chromy({visible: true});2chromy.chain()3 .wait(5000)4 .end()5 .result(function() {6 console.log('Done');7 });8var chromy = new Chromy({visible: false});9chromy.chain()10 .wait(5000)11 .end()12 .result(function() {13 console.log('Done');14 });15Chromy is a node module that uses Chrome's remote debugging protocol to control the browser. It is a wrapper around the Chrome Remote Interface (CRI) module. It is similar to PhantomJS, but it is based on Chrome/Chromium, which has a much larger market share than PhantomJS. Chromy is also similar to NightmareJS and Selenium Webdriver. Chromy is designed to be used for functional testing and web scraping. Chromy can be used in a continuous integration environment, such as TravisCI, to run functional tests against a web application. Chromy can also be used to scrape data from a web page, which can be used to populate a database. Chromy is a very powerful tool that can be used for many purposes. The following are some of the features that Chromy supports:
Using AI Code Generation
1chromy.visible('#some-element').then(function (visible) {2 console.log(visible);3});4chromy.visible('#some-element', true).then(function (visible) {5 console.log(visible);6});7chromy.visible('#some-element', false).then(function (visible) {8 console.log(visible);9});10chromy.visible('#some-element', true, 5000).then(function (visible) {11 console.log(visible);12});13chromy.visible('#some-element', false, 5000).then(function (visible) {14 console.log(visible);15});16chromy.visible('#some-element', true, 5000, 100).then(function (visible) {17 console.log(visible);18});19chromy.visible('#some-element', false, 5000, 100).then(function (visible) {20 console.log(visible);21});22chromy.visible('#some-element', true, 5000, 100, 'linear').then(function (visible) {23 console.log(visible);24});25chromy.visible('#some-element', false, 5000, 100, 'linear').then(function (visible) {26 console.log(visible);27});28chromy.visible('#some-element', true, 5000, 100, 'linear', function () {29 console.log('Animation complete');30}).then(function (visible) {31 console.log(visible);32});33chromy.visible('#some-element', false, 5000, 100, 'linear', function () {34 console.log('Animation complete');35}).then(function (visible) {36 console.log(visible);37});38chromy.visible('#some-element', true,
Using AI Code Generation
1chromy.visible('#main', function(err, visible){2 if(err) throw err;3 console.log(visible);4 chromy.close();5});6chromy.visibleWait('#main', function(err, visible){7 if(err) throw err;8 console.log(visible);9 chromy.close();10});11chromy.wait(5000, function(err){12 if(err) throw err;13 chromy.close();14});15chromy.waitUntilVisible('#main', function(err, visible){16 if(err) throw err;17 console.log(visible);18 chromy.close();19});20chromy.waitUntilVisible('#main', function(err, visible){21 if(err) throw err;22 console.log(visible);23 chromy.close();24});25chromy.waitWhileVisible('#main', function(err, visible){26 if(err) throw err;27 console.log(visible);28 chromy.close();29});30chromy.waitWhileVisible('#main', function(err, visible){31 if(err) throw err;32 console.log(visible);33 chromy.close();34});35chromy.waitUntilExists('#main', function(err, exists){36 if(err) throw err;37 console.log(exists);38 chromy.close();39});40chromy.waitWhileExists('#main', function(err, exists){41 if(err) throw err;42 console.log(exists);43 chromy.close();44});
Using AI Code Generation
1chromy.visible('#selector').then(function(visible) {2 if (visible) {3 } else {4 }5});6### chromy.waitVisible(selector, [timeout])7chromy.waitVisible('#selector', 3000).then(function(visible) {8 if (visible) {9 } else {10 }11});12### chromy.waitVisibleAll(selector, [timeout])13chromy.waitVisibleAll('#selector', 3000).then(function(visible) {14 if (visible) {15 } else {16 }17});18### chromy.exists(selector)19chromy.exists('#selector').then(function(exists) {20 if (exists) {21 } else {22 }23});24### chromy.waitExists(selector, [timeout])25chromy.waitExists('#selector', 3000).then(function(exists) {26 if (exists) {27 } else {28 }29});30### chromy.waitExistsAll(selector, [timeout])31chromy.waitExistsAll('#selector', 3000).then(function(exists) {32 if (exists) {33 } else {34 }35});36### chromy.notExists(selector)37chromy.notExists('#selector').then(function(notExists) {38 if (notExists) {39 } else {
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!!