Best JavaScript code snippet using storybook-root
character.js
Source:character.js
...56 if (name)7 spr.name = name;8 else9 spr.name = grammar.flatten("#name#");1011 spr.row = row;12 spr.col = col;13 spr.char_type = char_type; /β/β NPC, enemy14 spr.ai = ai;15 spr.chunk = chunk;16 spr.depth = NPC_INDEX;1718 spr.mood = grammar.flatten("#mood#");19 spr.vipTitle = grammar.flatten("#vipTitle#");20 spr.occupation = grammar.flatten("#occupation#");21 spr.speed = 2;/β/βspeed;22 spr.chunk = chunk;2324 if ((questGiver !== undefined) && (questGiver)) {25 spr.questGiver = true;26 if (name === "Mike the Fisherman") {27 spr.dialogue_index = 0;28 spr.name = "Mike";29 spr.occupation = "Fisherman";30 spr.quest = {31 "quest": "fish", /β/β make this a list?32 "questDialogue": [33 "Hey there",34 /β*event_grammar.flatten("#campfire1#"),35 event_grammar.flatten("#campfire2#"),36 event_grammar.flatten("#campfire3#"),37 event_grammar.flatten("#campfire4#"),38 event_grammar.flatten("#campfire5#"),39 event_grammar.flatten("#campfire6#"),40 event_grammar.flatten("#campfire7#"),*/β41 ],42 "thanks": "Thank you!",43 "done": false44 };45 }46 }47 /β/βspr.quest = quest;48 /β/βspr.questGiver = questGiver;495051 /β/β npc.name = npc_grammar.flatten("#name#");52 /β/β npc.mood = npc_grammar.flatten("#mood#");53 /β/β npc.vipTitle = npc_grammar.flatten("#vipTitle#");54 /β/β npc.occupation = npc_grammar.flatten("#occupation#");55 /β/β /β/β/β56 /β/β npc.depth = NPC_INDEX;57 /β/β /β/βnpc.addImage = npcImg;58 /β/β npc.chunk = getRandomInteger(0, NUM_CHUNKS); /β/β1;59 /β/β npc.speed = 2; /β/β tbd60 /β/β npc.dialogue_index = 0;6162 /β/β if (_n == questGiver) {63 /β/β npc.questGiver = true;64 /β/β npc.ai = "follow";65 /β/β console.log("Questy McQuesterson on: " + npc.chunk);66 /β/β npc.quest = {67 /β/β "quest": "Have you seen my BLUE CRAB?", /β/β make this a list?68 /β/β "thanks": "Thanks m8",69 /β/β "done": false70 /β/β };71 /β/β } else if (_n == numGenericNPCs) { /β/β last one hangs by the campfire72 /β/β npc.questGiver = true;73 /β/β npc.ai = "loiter";74 /β/β npc.chunk = _campfireChunk;75 /β/β npc.quest = {76 /β/β "quest": "body", /β/β make this a list?77 /β/β "questDialogue": [78 /β/β event_grammar.flatten("#campfire1#"),79 /β/β event_grammar.flatten("#campfire2#"),80 /β/β event_grammar.flatten("#campfire3#"),81 /β/β event_grammar.flatten("#campfire4#"),82 /β/β event_grammar.flatten("#campfire5#"),83 /β/β event_grammar.flatten("#campfire6#"),84 /β/β event_grammar.flatten("#campfire7#"),85 /β/β ],86 /β/β "thanks": "Thanks m8",87 /β/β "done": false88 /β/β };89 /β/β console.log(npc.quest["questDialogue"]);90 /β/β } else if (_n == numGenericNPCs + 1) { /β/β mike the fisherman91 /β/β npc.name = "Mike the Fisherman";92 /β/β npc.questGiver = true;93 /β/β npc.ai = "loiter";94 /β/β npc.chunk = NUM_CHUNKS + TOWN_CHUNKS.FRILL;95 /β/β npc.quest = {96 /β/β "quest": "fish", /β/β make this a list?97 /β/β "questDialogue": [98 /β/β "Hey there",99 /β/β /β*event_grammar.flatten("#campfire1#"),100 /β/β event_grammar.flatten("#campfire2#"),101 /β/β event_grammar.flatten("#campfire3#"),102 /β/β event_grammar.flatten("#campfire4#"),103 /β/β event_grammar.flatten("#campfire5#"),104 /β/β event_grammar.flatten("#campfire6#"),105 /β/β event_grammar.flatten("#campfire7#"),*/β106 /β/β ],107 /β/β "thanks": "Thank you!",108 /β/β "done": false109 /β/β };110 /β/β } else {111 /β/β npc.questGiver = false;112 /β/β npc.ai = "wander";113 /β/β }114115 /β/β npc.draw = function () {116 /β/β if (chunkIndex == this.chunk) {117118119120121122123124125126127 spr.draw = function () {128 if (chunkIndex == spr.chunk) {129 image(spr.image, spr.deltaX * 2, spr.deltaY * 2);130 }131 }132 spr.update = function () {133 if ((chunkIndex == this.chunk) && (CURRENT_SCENE == SCENES.GAME)) { /β/β only update on current chunk /β not paused134 chunkNPCSprites.add(this);135136 /β/β update based on AI type137 if (spr.ai == "wander") {138 if (random() > 0.9) { /β/β decide to move139140 /β/β pick a direction141 let _dirs = ["up", "down", "left", "right"];142 let _move = {};143 _move[_dirs[Math.floor(Math.random() * _dirs.length)]] = true;144 let _retval = checkMove(spr.position, chunkIndex, _move);145 /β/β_dirs[Math.floor(Math.random() * _dirs.length)]);146 if (_retval['state']) { /β/β true -- move147 spr.position.x = _retval['pos']['dx'];148 spr.position.y = _retval['pos']['dy'];149 }150 }151 } else if (spr.ai == "loiter") {152 ;153 } else if (spr.ai == "follow") {154 /β/β https:/β/βstackoverflow.com/βquestions/β20044791/βhow-to-make-an-enemy-follow-the-player-in-pygame155 if (random() > 0.8) { /β/β move towards player156 /β/β direction vector157 let dx = player.position.x - spr.position.x;158 let dy = player.position.y - spr.position.y;159 let dist = Math.hypot(dx, dy);160161 /β/β normalize162 dx /β= dist;163 dy /β= dist;164165 if (!(dist == 16)) {166 if (random() > 0.5) { /β/β move x167 if (dx > 0)168 spr.position.x += TILE_WIDTH;169 else if (dx < 0)170 spr.position.x -= TILE_WIDTH;171 } else { /β/β move y172 if (dy > 0)173 spr.position.y += TILE_HEIGHT;174 else if (dy < 0)175 spr.position.y -= TILE_HEIGHT;176 }177 }178 /β/βspr.position.x += dx * spr.speed;179 /β/βspr.position.y += dy * spr.speed;180 }181 }182 } else183 chunkNPCSprites.remove(this);184 }185186 return spr;187}188189/β*190class Character {191 constructor(name, sprite, row, col, char_type, ai, image, chunk) {192193 }194 setNPC(mood, vipTitle, occupation, speed, questGiver, quest) {195 this.mood = mood;196 this.vipTitle = vipTitle;197 this.occupation = occupation;198 this.speed = speed;199 this.chunk = chunk;200 this.quest = quest;201 this.questGiver = questGiver;202 }203}204*/β205206/β*207 /β/β npc208 let questGiver = getRandomInteger(0, numGenericNPCs);209 for (let _n = 0; _n < numGenericNPCs + 2; _n++) {210 let _c = getRandomInteger(1, MAP_COLS - 1);211 let _r = getRandomInteger(1, MAP_ROWS - 1);212213 if (_n == numGenericNPCs) { /β/β campfire friend214 _r = _cf_row;215 _c = _cf_col;216 } else if (_n == numGenericNPCs+1) { /β/β fisherman friend217 _r = 50;218 _c = 61;219 }220221 npc = createSprite((TILE_WIDTH * _c) + (TILE_WIDTH /β 2), (TILE_HEIGHT * _r) + (TILE_HEIGHT /β 2), TILE_WIDTH, TILE_HEIGHT);222 /β/β/β generative:223 npc.name = npc_grammar.flatten("#name#");224 npc.mood = npc_grammar.flatten("#mood#");225 npc.vipTitle = npc_grammar.flatten("#vipTitle#");226 npc.occupation = npc_grammar.flatten("#occupation#");227 /β/β/β228 npc.depth = NPC_INDEX;229 /β/βnpc.addImage = npcImg;230 npc.chunk = getRandomInteger(0, NUM_CHUNKS); /β/β1;231 npc.speed = 2; /β/β tbd232 npc.dialogue_index = 0;233234 if (_n == questGiver) {235 npc.questGiver = true;236 npc.ai = "follow";237 console.log("Questy McQuesterson on: " + npc.chunk);238 npc.quest = {239 "quest": "Have you seen my BLUE CRAB?", /β/β make this a list?240 "thanks": "Thanks m8",241 "done": false242 };243 } else if (_n == numGenericNPCs) { /β/β last one hangs by the campfire244 npc.questGiver = true;245 npc.ai = "loiter";246 npc.chunk = _campfireChunk;247 npc.quest = {248 "quest": "body", /β/β make this a list?249 "questDialogue": [250 event_grammar.flatten("#campfire1#"),251 event_grammar.flatten("#campfire2#"),252 event_grammar.flatten("#campfire3#"),253 event_grammar.flatten("#campfire4#"),254 event_grammar.flatten("#campfire5#"),255 event_grammar.flatten("#campfire6#"),256 event_grammar.flatten("#campfire7#"),257 ],258 "thanks": "Thanks m8",259 "done": false260 };261 console.log(npc.quest["questDialogue"]);262 } else if (_n == numGenericNPCs+1) { /β/β mike the fisherman263 npc.name = "Mike the Fisherman";264 npc.questGiver = true;265 npc.ai = "loiter";266 npc.chunk = NUM_CHUNKS+TOWN_CHUNKS.FRILL;267 npc.quest = {268 "quest": "fish", /β/β make this a list?269 "questDialogue": [270 "Hey there",
...
fcos_loss.py
Source:fcos_loss.py
...34 if channel_first:35 input_channel_last = paddle.transpose(inputs, perm=[0, 2, 3, 1])36 else:37 input_channel_last = inputs38 output_channel_last = paddle.flatten(39 input_channel_last, start_axis=0, stop_axis=2)40 return output_channel_last41@register42class FCOSLoss(nn.Layer):43 """44 FCOSLoss45 Args:46 loss_alpha (float): alpha in focal loss47 loss_gamma (float): gamma in focal loss48 iou_loss_type (str): location loss type, IoU/βGIoU/βLINEAR_IoU49 reg_weights (float): weight for location loss50 """51 def __init__(self,52 loss_alpha=0.25,...
inject_cube.py
Source:inject_cube.py
...15 X_og = np.linspace(x,x+leng,leng*400)16 Y_og = np.linspace(y,y+leng,leng*400)17 Z_og = np.linspace(z,z+leng,leng*400)18 X, Y = np.meshgrid(X_og, Y_og)19 cube_1 = np.array([X.flatten(), Y.flatten(), np.ones_like(X.flatten())*np.min(Z_og), np.ones_like(X.flatten())*144./β255.]).transpose()20 cube_2 = np.array([X.flatten(), Y.flatten(), np.ones_like(X.flatten())*np.max(Z_og), np.ones_like(X.flatten())*144./β255.]).transpose()21 X, Z = np.meshgrid(X_og, Z_og)22 cube_3 = np.array([X.flatten(), np.ones_like(X.flatten())*np.min(Y_og), Z.flatten(), np.ones_like(X.flatten())*144./β255.]).transpose()23 cube_4 = np.array([X.flatten(), np.ones_like(X.flatten())*np.max(Y_og), Z.flatten(), np.ones_like(X.flatten())*144./β255.]).transpose()24 Y, Z = np.meshgrid(Y_og, Z_og)25 cube_5 = np.array([np.ones_like(Y.flatten())*np.min(X_og), Y.flatten(), Z.flatten(), np.ones_like(Y.flatten())*144./β255.]).transpose()26 cube_6 = np.array([np.ones_like(Y.flatten())*np.max(X_og), Y.flatten(), Z.flatten(), np.ones_like(Y.flatten())*144./β255.]).transpose()27 cube = np.concatenate((cube_1, cube_2, cube_3, cube_4, cube_5, cube_6), axis=0)28 cube = appendSpherical_np(cube)29 h_granularity = 0.2 /β 180 * np.pi30 v_granularity = 26.8 /β 63 /β 180 * np.pi31 min_h = np.min(cube[:,6])32 max_h = np.max(cube[:,6])33 min_v = np.min(cube[:,5])34 max_v = np.max(cube[:,5])35 36 PC_w,PC_wo = processPC(PC,min_h,max_h,min_v,max_v)37 totalsub = np.concatenate((PC_w,cube), axis=0)38 h_grids = round((max_h - min_h) /β h_granularity)39 v_grids = round((max_v - min_v) /β v_granularity)40 cube_project = []41 for h in range(int(h_grids)):42 for v in range(int(v_grids)):43 subset = totalsub44 subset = subset[subset[:,5] > min_v + v * v_granularity]45 subset = subset[subset[:,5] < min_v + (v + 1) * v_granularity]46 subset = subset[subset[:,6] > min_h + h * h_granularity]47 subset = subset[subset[:,6] < min_h + (h + 1) * h_granularity]48 if subset.size != 0:49 cube_project.append(subset[np.argmin(subset[:,4])])50 cube_project = np.array(cube_project)51 total = np.concatenate((PC_wo,cube_project), axis=0)52 return total53def injectCylinder(PC,h,r,x,y,z):54 PC = appendSpherical_np(PC)55 C_og = np.linspace(0,2*np.pi,400)56 Z_og = np.linspace(z,z+h,400)57 R_og = np.linspace(0,r,400)58 C, Z = np.meshgrid(C_og, Z_og)59 surface_1 = np.array([np.ones_like(C.flatten())*r, C.flatten(), Z.flatten(), np.ones_like(C.flatten())*144./β255.]).transpose()60 61 C, R = np.meshgrid(C_og, R_og)62 surface_2 = np.array([R.flatten(), C.flatten(), np.ones_like(R.flatten())*np.min(Z_og), np.ones_like(C.flatten())*144./β255.]).transpose()63 surface_3 = np.array([R.flatten(), C.flatten(), np.ones_like(R.flatten())*np.max(Z_og), np.ones_like(C.flatten())*144./β255.]).transpose()64 65 cylinder = np.concatenate((surface_1, surface_2, surface_3), axis=0)66 cylinder = replaceCoord_np(cylinder)67 cylinder[:,0] += x68 cylinder[:,1] += y69 cylinder = appendSpherical_np(cylinder)70 h_granularity = 0.2 /β 180 * np.pi71 v_granularity = 26.8 /β 63 /β 180 * np.pi72 min_h = np.min(cylinder[:,6])73 max_h = np.max(cylinder[:,6])74 min_v = np.min(cylinder[:,5])75 max_v = np.max(cylinder[:,5])76 77 PC_w,PC_wo = processPC(PC,min_h,max_h,min_v,max_v)78 totalsub = np.concatenate((PC_w,cylinder), axis=0)79 h_grids = round((max_h - min_h) /β h_granularity)80 v_grids = round((max_v - min_v) /β v_granularity)81 cylinder_project = []82 for h in range(int(h_grids)):83 for v in range(int(v_grids)):84 subset = totalsub85 subset = subset[subset[:,5] > min_v + v * v_granularity]86 subset = subset[subset[:,5] < min_v + (v + 1) * v_granularity]87 subset = subset[subset[:,6] > min_h + h * h_granularity]88 subset = subset[subset[:,6] < min_h + (h + 1) * h_granularity]89 if subset.size != 0:90 cylinder_project.append(subset[np.argmin(subset[:,4])])91 cylinder_project = np.array(cylinder_project)92 total = np.concatenate((PC_wo,cylinder_project), axis=0)93 return total94def injectPyramid(PC,h,r1,r2,x,y,z):95 PC = appendSpherical_np(PC)96 C_og = np.linspace(0,2*np.pi,400)97 Z_og = np.linspace(z,z+h,400)98 R1_og = np.linspace(0,r1,400)99 R2_og = np.linspace(0,r2,400)100 R3_og = np.linspace(r1,r2,400)101 C, Z = np.meshgrid(C_og, Z_og)102 _,R3 = np.meshgrid(C_og, R3_og) 103 surface_1 = np.array([R3.flatten(), C.flatten(), Z.flatten(), np.ones_like(C.flatten())*144./β255.]).transpose()104 105 C, R1 = np.meshgrid(C_og, R1_og)106 surface_2 = np.array([R1.flatten(), C.flatten(), np.ones_like(R1.flatten())*np.min(Z_og), np.ones_like(C.flatten())*144./β255.]).transpose()107 108 C, R2 = np.meshgrid(C_og, R2_og)109 surface_3 = np.array([R2.flatten(), C.flatten(), np.ones_like(R2.flatten())*np.max(Z_og), np.ones_like(C.flatten())*144./β255.]).transpose()110 111 pyramid = np.concatenate((surface_1, surface_2, surface_3), axis=0)112 pyramid = replaceCoord_np(pyramid)113 pyramid[:,0] += x114 pyramid[:,1] += y115 pyramid = appendSpherical_np(pyramid)116 h_granularity = 0.2 /β 180 * np.pi117 v_granularity = 26.8 /β 63 /β 180 * np.pi118 min_h = np.min(pyramid[:,6])119 max_h = np.max(pyramid[:,6])120 min_v = np.min(pyramid[:,5])121 max_v = np.max(pyramid[:,5])122 123 PC_w,PC_wo = processPC(PC,min_h,max_h,min_v,max_v)...
0001_migrate_metadata.py
Source:0001_migrate_metadata.py
1# Generated by Django 2.2.9 on 2020-02-07 07:322from django.db import migrations3def flatten_model_metadata(model_with_metadata):4 updated_fields = []5 public_meta = model_with_metadata.metadata6 private_meta = model_with_metadata.private_metadata7 if public_meta:8 model_with_metadata.metadata = flatten_metadata(public_meta)9 updated_fields.append("metadata")10 if private_meta:11 model_with_metadata.private_metadata = flatten_metadata(private_meta)12 updated_fields.append("private_metadata")13 if updated_fields:14 model_with_metadata.save(update_fields=updated_fields)15def flatten_metadata(metadata):16 flattened_metadata = {}17 for _, namespace in metadata.items():18 for client_name, client in namespace.items():19 for key, value in client.items():20 flattened_key = client_name + "." + key21 if flattened_key in flattened_metadata:22 raise Exception(f"Meta key {flattened_key} is duplicated.")23 flattened_metadata[flattened_key] = value24 return flattened_metadata25def flatten_attributes_metadata(apps, _schema_editor):26 Attribute = apps.get_model("product", "Attribute")27 for attribute in Attribute.objects.iterator():28 flatten_model_metadata(attribute)29def flatten_categories_metadata(apps, _schema_editor):30 Category = apps.get_model("product", "Category")31 for category in Category.objects.iterator():32 flatten_model_metadata(category)33def flatten_checkouts_metadata(apps, _schema_editor):34 Checkout = apps.get_model("checkout", "Checkout")35 for checkout in Checkout.objects.iterator():36 flatten_model_metadata(checkout)37def flatten_collections_metadata(apps, _schema_editor):38 Collection = apps.get_model("product", "Collection")39 for collection in Collection.objects.iterator():40 flatten_model_metadata(collection)41def flatten_digital_contents_metadata(apps, _schema_editor):42 DigitalContent = apps.get_model("product", "DigitalContent")43 for digital_content in DigitalContent.objects.iterator():44 flatten_model_metadata(digital_content)45def flatten_fulfillments_metadata(apps, _schema_editor):46 Fulfillment = apps.get_model("order", "Fulfillment")47 for fulfillment in Fulfillment.objects.iterator():48 flatten_model_metadata(fulfillment)49def flatten_orders_metadata(apps, _schema_editor):50 Order = apps.get_model("order", "Order")51 for order in Order.objects.iterator():52 flatten_model_metadata(order)53def flatten_products_metadata(apps, _schema_editor):54 Product = apps.get_model("product", "Product")55 for product in Product.objects.iterator():56 flatten_model_metadata(product)57def flatten_product_types_metadata(apps, _schema_editor):58 ProductType = apps.get_model("product", "ProductType")59 for product_type in ProductType.objects.iterator():60 flatten_model_metadata(product_type)61def flatten_product_variants_metadata(apps, _schema_editor):62 ProductVariant = apps.get_model("product", "ProductVariant")63 for product_variant in ProductVariant.objects.iterator():64 flatten_model_metadata(product_variant)65def flatten_service_accounts_metadata(apps, _schema_editor):66 ServiceAccount = apps.get_model("account", "ServiceAccount")67 for service_account in ServiceAccount.objects.iterator():68 flatten_model_metadata(service_account)69def flatten_users_metadata(apps, _schema_editor):70 User = apps.get_model("account", "User")71 for user in User.objects.iterator():72 flatten_model_metadata(user)73class Migration(migrations.Migration):74 dependencies = [75 ("account", "0039_auto_20200221_0257"),76 ("checkout", "0025_auto_20200221_0257"),77 ("order", "0078_auto_20200221_0257"),78 ("product", "0115_auto_20200221_0257"),79 ]80 run_before = [("attribute", "0001_initial")]81 operations = [82 migrations.RunPython(flatten_attributes_metadata),83 migrations.RunPython(flatten_categories_metadata),84 migrations.RunPython(flatten_checkouts_metadata),85 migrations.RunPython(flatten_collections_metadata),86 migrations.RunPython(flatten_digital_contents_metadata),87 migrations.RunPython(flatten_fulfillments_metadata),88 migrations.RunPython(flatten_orders_metadata),89 migrations.RunPython(flatten_products_metadata),90 migrations.RunPython(flatten_product_types_metadata),91 migrations.RunPython(flatten_product_variants_metadata),92 migrations.RunPython(flatten_service_accounts_metadata),93 migrations.RunPython(flatten_users_metadata),...
flatten-methods.js
Source:flatten-methods.js
...8 var array = [1, [2, [3, [4]], 5]],9 methodNames = ['flatten', 'flattenDeep', 'flattenDepth'];10 it('should flatten `arguments` objects', function() {11 var array = [args, [args]];12 assert.deepStrictEqual(flatten(array), [1, 2, 3, args]);13 assert.deepStrictEqual(flattenDeep(array), [1, 2, 3, 1, 2, 3]);14 assert.deepStrictEqual(flattenDepth(array, 2), [1, 2, 3, 1, 2, 3]);15 });16 it('should treat sparse arrays as dense', function() {17 var array = [[1, 2, 3], Array(3)],18 expected = [1, 2, 3];19 expected.push(undefined, undefined, undefined);20 lodashStable.each(methodNames, function(methodName) {21 var actual = _[methodName](array);22 assert.deepStrictEqual(actual, expected);23 assert.ok('4' in actual);24 });25 });26 it('should flatten objects with a truthy `Symbol.isConcatSpreadable` value', function() {27 if (Symbol && Symbol.isConcatSpreadable) {28 var object = { '0': 'a', 'length': 1 },29 array = [object],30 expected = lodashStable.map(methodNames, lodashStable.constant(['a']));31 object[Symbol.isConcatSpreadable] = true;32 var actual = lodashStable.map(methodNames, function(methodName) {33 return _[methodName](array);34 });35 assert.deepStrictEqual(actual, expected);36 }37 });38 it('should work with extremely large arrays', function() {39 lodashStable.times(3, function(index) {40 var expected = Array(5e5);41 try {42 var func = flatten;43 if (index == 1) {44 func = flattenDeep;45 } else if (index == 2) {46 func = flattenDepth;47 }48 assert.deepStrictEqual(func([expected]), expected);49 } catch (e) {50 assert.ok(false, e.message);51 }52 });53 });54 it('should work with empty arrays', function() {55 var array = [[], [[]], [[], [[[]]]]];56 assert.deepStrictEqual(flatten(array), [[], [], [[[]]]]);57 assert.deepStrictEqual(flattenDeep(array), []);58 assert.deepStrictEqual(flattenDepth(array, 2), [[[]]]);59 });60 it('should support flattening of nested arrays', function() {61 assert.deepStrictEqual(flatten(array), [1, 2, [3, [4]], 5]);62 assert.deepStrictEqual(flattenDeep(array), [1, 2, 3, 4, 5]);63 assert.deepStrictEqual(flattenDepth(array, 2), [1, 2, 3, [4], 5]);64 });65 it('should return an empty array for non array-like objects', function() {66 var expected = [],67 nonArray = { '0': 'a' };68 assert.deepStrictEqual(flatten(nonArray), expected);69 assert.deepStrictEqual(flattenDeep(nonArray), expected);70 assert.deepStrictEqual(flattenDepth(nonArray, 2), expected);71 });72 it('should return a wrapped value when chaining', function() {73 var wrapped = _(array),74 actual = wrapped.flatten();75 assert.ok(actual instanceof _);76 assert.deepEqual(actual.value(), [1, 2, [3, [4]], 5]);77 actual = wrapped.flattenDeep();78 assert.ok(actual instanceof _);79 assert.deepEqual(actual.value(), [1, 2, 3, 4, 5]);80 actual = wrapped.flattenDepth(2);81 assert.ok(actual instanceof _);82 assert.deepEqual(actual.value(), [1, 2, 3, [4], 5]);83 });...
parse_bert.py
Source:parse_bert.py
1import argparse2import json3import copy4import pathlib5from distutils.util import strtobool6from run_bert import main7from utils import is_num8f = open("config_bert.json", "r")9config = json.load(f)10f.close()11flatten_config = {}12for key in config.keys():13 flatten_config.update(config[key])14# print(flatten_config)15parser = argparse.ArgumentParser(description="subprocess for grid search")16parser.add_argument("--name", default="")17for key in flatten_config.keys():18 if type(flatten_config[key])==bool:19 parser.add_argument("--{}".format(key), default=flatten_config[key], type=strtobool)20 elif type(flatten_config[key])==list:21 parser.add_argument("--{}".format(key), default=flatten_config[key], type=type(flatten_config[key][0]) if len(flatten_config[key])>0 else None, nargs="*")22 elif type(flatten_config[key])==str and "/β" in flatten_config[key]:23 parser.add_argument("--{}".format(key), default=flatten_config[key], type=pathlib.Path)24 elif flatten_config[key] is None or type(flatten_config[key])==int:25 parser.add_argument("--{}".format(key), default=flatten_config[key])26 else:27 parser.add_argument("--{}".format(key), default=flatten_config[key], type=type(flatten_config[key]))28new_flatten_config = vars(parser.parse_args())29new_config = copy.deepcopy(config)30for top_key in config.keys():31 for key in config[top_key].keys():32 if type(config[top_key][key])==bool:33 new_config[top_key][key] = bool(new_flatten_config[key])34 elif type(config[top_key][key])==str and "/β" in config[top_key][key]:35 new_config[top_key][key] = str(new_flatten_config[key])36 elif new_flatten_config[key]=="None" or new_flatten_config[key] is None:37 new_config[top_key][key] = None38 elif type(new_flatten_config[key])==str:39 if str.isdigit(new_flatten_config[key]):40 new_config[top_key][key] = int(new_flatten_config[key])41 elif is_num(new_flatten_config[key]):42 new_config[top_key][key] = float(new_flatten_config[key])43 else:44 new_config[top_key][key] = new_flatten_config[key]45 else:46 new_config[top_key][key] = new_flatten_config[key]47 ...
array-flatten.js
Source:array-flatten.js
1'use strict'2/β**3 * Expose `arrayFlatten`.4 */β5module.exports = flatten6module.exports.from = flattenFrom7module.exports.depth = flattenDepth8module.exports.fromDepth = flattenFromDepth9/β**10 * Flatten an array.11 *12 * @param {Array} array13 * @return {Array}14 */β15function flatten (array) {16 if (!Array.isArray(array)) {17 throw new TypeError('Expected value to be an array')18 }19 return flattenFrom(array)20}21/β**22 * Flatten an array-like structure.23 *24 * @param {Array} array25 * @return {Array}26 */β27function flattenFrom (array) {28 return flattenDown(array, [])29}30/β**31 * Flatten an array-like structure with depth.32 *33 * @param {Array} array34 * @param {number} depth35 * @return {Array}36 */β37function flattenDepth (array, depth) {38 if (!Array.isArray(array)) {39 throw new TypeError('Expected value to be an array')40 }41 return flattenFromDepth(array, depth)42}43/β**44 * Flatten an array-like structure with depth.45 *46 * @param {Array} array47 * @param {number} depth48 * @return {Array}49 */β50function flattenFromDepth (array, depth) {51 if (typeof depth !== 'number') {52 throw new TypeError('Expected the depth to be a number')53 }54 return flattenDownDepth(array, [], depth)55}56/β**57 * Flatten an array indefinitely.58 *59 * @param {Array} array60 * @param {Array} result61 * @return {Array}62 */β63function flattenDown (array, result) {64 for (var i = 0; i < array.length; i++) {65 var value = array[i]66 if (Array.isArray(value)) {67 flattenDown(value, result)68 } else {69 result.push(value)70 }71 }72 return result73}74/β**75 * Flatten an array with depth.76 *77 * @param {Array} array78 * @param {Array} result79 * @param {number} depth80 * @return {Array}81 */β82function flattenDownDepth (array, result, depth) {83 depth--84 for (var i = 0; i < array.length; i++) {85 var value = array[i]86 if (depth > -1 && Array.isArray(value)) {87 flattenDownDepth(value, result, depth)88 } else {89 result.push(value)90 }91 }92 return result...
Using AI Code Generation
1import { addDecorator } from '@storybook/βreact';2import { withKnobs } from '@storybook/βaddon-knobs';3import { withRootDecorator } from 'storybook-root-decorator';4addDecorator(withKnobs);5addDecorator(withRootDecorator);6import { flatten } from 'storybook-root-decorator';7const stories = flatten(require.context('../βsrc', true, /β\.stories\.js$/β));8stories.forEach(story => {9 story();10});11import React from 'react';12import { storiesOf } from '@storybook/βreact';13import MyComponent from './βMyComponent';14storiesOf('MyComponent', module).add('default', () => <MyComponent /β>);15import React from 'react';16import { storiesOf } from '@storybook/βreact';17import MyComponent from './βMyComponent';18storiesOf('MyComponent', module).add('default', () => <MyComponent /β>);19import React from 'react';20import { storiesOf } from '@storybook/βreact';21import MyComponent from './βMyComponent';22storiesOf('MyComponent', module).add('default', () => <MyComponent /β>);23import React from 'react';24import { storiesOf } from '@storybook/βreact';25import MyComponent from './βMyComponent';26storiesOf('MyComponent', module).add('default', () => <MyComponent /β>);27import React from 'react';28import { storiesOf } from '@storybook/βreact';29import MyComponent from './βMyComponent';30storiesOf('MyComponent', module).add('default', () => <MyComponent /β>);31import React from 'react';32import { storiesOf } from '@storybook/βreact';33import MyComponent from './βMyComponent';34storiesOf('MyComponent', module).add('default', () => <MyComponent /β>);35import
Using AI Code Generation
1import flatten from 'storybook-root/βflatten';2import flatten from 'storybook-root/βflatten';3import flatten from 'storybook-root/βflatten';4import flatten from 'storybook-root/βflatten';5import flatten from 'storybook-root/βflatten';6import flatten from 'storybook-root/βflatten';7import flatten from 'storybook-root/βflatten';8import flatten from 'storybook-root/βflatten';9import flatten from 'storybook-root/βflatten';10import flatten from 'storybook-root/βflatten';11import flatten from 'storybook-root/βflatten';12import flatten from 'storybook-root/βflatten';13import flatten from 'storybook-root/βflatten';14import flatten from 'storybook-root/βflatten';15import flatten from 'storybook-root/βflatten';16import flatten from 'storybook-root/βflatten';17import flatten from 'storybook-root/βflatten';18import flatten from 'storybook-root/βflatten';19import flatten from 'storybook-root/βflatten';20import flatten from 'storybook-root/βflatten';21import flatten from 'storybook-root/βflatten';22import flatten from 'storybook-root/βflatten';
Using AI Code Generation
1import { flatten } from 'storybook-root';2import { flatten } from 'storybook-root';3import { flatten } from 'storybook-root';4import { flatten } from 'storybook-root';5import { flatten } from 'storybook-root';6import { flatten } from 'storybook-root';7import { flatten } from 'storybook-root';8import { flatten } from 'storybook-root';9import { flatten } from 'storybook-root';10import { flatten } from 'storybook-root';11import { flatten } from 'storybook-root';12import { flatten } from 'storybook-root';13import { flatten } from 'storybook-root';14import { flatten } from 'storybook-root';
Using AI Code Generation
1import { flatten } from 'storybook-root';2import { flatten } from 'storybook-root';3import { flatten } from 'storybook-root';4import { flatten } from 'storybook-root';5import { flatten } from 'storybook-root';6import { flatten } from 'storybook-root';7import { flatten } from 'storybook-root';8import { flatten } from 'storybook-root';9import { flatten } from 'storybook-root';10import { flatten } from 'storybook-root';11import { flatten } from 'storybook-root';12import { flatten } from 'storybook-root';13import { flatten } from 'storybook-root';14import { flatten } from 'storybook-root';15import { flatten } from 'storybook-root';16import { flatten } from 'storybook-root';17import { flatten } from 'storybook-root';18import { flatten } from 'storybook-root';19import { flatten } from 'storybook-root';20import { flatten } from 'storybook-root';21import { flatten } from 'storybook-root';22import { flatten } from 'storybook-root';
Using AI Code Generation
1import flatten from 'storybook-root/βflatten';2import flatten from 'storybook-root/βflatten';3import flatten from 'storybook-root/βflatten';4import flatten from 'storybook-root/βflatten';5import flatten from 'storybook-root/βflatten';6import flatten from 'storybook-root/βflatten';7import flatten from 'storybook-root/βflatten';8import flatten from 'storybook-root/βflatten';9import flatten from 'storybook-root/βflatten';10import flatten from 'storybook-root/βflatten';11import flatten from 'storybook-root/βflatten';12import flatten from 'storybook-root/βflatten';13import flatten from 'storybook-root/βflatten';14import flatten from 'storybook-root/βflatten';15import flatten from 'storybook-root/βflatten';16import flatten from 'storybook-root/βflatten';17import flatten from 'storybook-root/βflatten';18import flatten from 'storybook-root/βflatten';19import flatten from 'storybook-root/βflatten';20import flatten from 'storybook-root/βflatten';21import flatten from 'storybook-root/βflatten';22import flatten from 'storybook-root/βflatten';
Using AI Code Generation
1import flatten from 'storybook-root/βflatten'2const flattened = flatten([1, [2, [3, [4]], 5]])3console.log(flattened)4import flatten from 'storybook-root/βflatten'5const flattened = flatten([1, [2, [3, [4]], 5]])6console.log(flattened)7import flatten from 'storybook-root/βflatten'8const flattened = flatten([1, [2, [3, [4]], 5]])9console.log(flattened)10import flatten from 'storybook-root/βflatten'11const flattened = flatten([1, [2, [3, [4]], 5]])12console.log(flattened)13import flatten from 'storybook-root/βflatten'14const flattened = flatten([1, [2, [3, [4]], 5]])15console.log(flattened)16import flatten from 'storybook-root/βflatten'17const flattened = flatten([1, [2, [3, [4]], 5]])18console.log(flattened)19import flatten from 'storybook-root/βflatten'20const flattened = flatten([1, [2, [3, [4]], 5]])21console.log(flattened)22import flatten from 'storybook-root/βflatten'23const flattened = flatten([1, [2, [3, [4]], 5]])
Using AI Code Generation
1import { flatten } from 'storybook-root-decorator';2storiesOf('some component', module)3 .addDecorator(flatten)4 .add('some story', () => <div>some story</βdiv>);5import { flatten } from 'storybook-root-decorator';6storiesOf('some component', module)7 .addDecorator(flatten)8 .add('some story', () => <div>some story</βdiv>);9import { flatten } from 'storybook-root-decorator';10storiesOf('some component', module)11 .addDecorator(flatten)12 .add('some story', () => <div>some story</βdiv>);13import { flatten } from 'storybook-root-decorator';14storiesOf('some component', module)15 .addDecorator(flatten)16 .add('some story', () => <div>some story</βdiv>);17import { flatten } from 'storybook-root-decorator';18storiesOf('some component', module)19 .addDecorator(flatten)20 .add('some story', () => <div>some story</βdiv>);21import { flatten } from 'storybook-root-decorator';22storiesOf('some component', module)23 .addDecorator(flatten)24 .add('some story', () => <div>some story</βdiv>);25import { flatten } from 'storybook-root-decorator';26storiesOf('some component', module)27 .addDecorator(flatten)28 .add('some story', () => <div>some story</βdiv>);29import { flatten } from 'storybook-root-decorator';30storiesOf('some component', module)
Using AI Code Generation
1const { flatten } = require('storybook-root');2const { storiesOf } = require('@storybook/βreact-native');3storiesOf('Button', module).add('with text', () => {4 return <Button title="Hello Button" onPress={() => alert('clicked')} /β>;5});6const { flatten } = require('storybook-root');7const { storiesOf } = require('@storybook/βreact-native');8storiesOf('Button', module).add('with text', () => {9 return <Button title="Hello Button" onPress={() => alert('clicked')} /β>;10});11const { storiesOf } = require('@storybook/βreact-native');12const { action } = require('@storybook/βaddon-actions');13const { linkTo } = require('@storybook/βaddon-links');14const { withKnobs, text, boolean, number } = require('@storybook/βaddon-knobs');15const { Button } = require('react-native');16storiesOf('Button', module)17 .addDecorator(withKnobs)18 .add('with text', () => {19 const title = text('title', 'Hello Button');20 const onPress = action('onPress');21 return <Button title={title} onPress={onPress} /β>;22 })23 .add('with some emoji', () => {24 return <Button title="π π π π―" onPress={action('onPress')} /β>;25 });26const { configure, getStorybookUI } = require('@storybook/βreact-native');27const { loadStories } = require('storybook-root');28configure(() => {29 loadStories();30}, module);31const StorybookUI = getStorybookUI({ port: 7007, host: 'localhost' });32module.exports = StorybookUI;33require('@storybook/βaddon-actions/βregister');34require('@storybook/βaddon-links/βregister');35require('@storybook/βaddon-knobs/βregister');36const { resolve } = require('path');37module.exports = ({ config }) => {38 config.resolve.alias['storybook-root'] = resolve(__dirname, '..', 'src');39 return config;40};41const { start } = require('@storybook/βreact-native-server');42start({
Using AI Code Generation
1const flatten = require('storybook-root-cause/βflatten');2const storybook = require('storybook-root-cause/βstorybook');3const { storybook: { stories } } = storybook;4const flatten = require('storybook-root-cause/βflatten');5const storybook = require('storybook-root-cause/βstorybook');6const { storybook: { stories } } = storybook;7const flattenStories = flatten(stories);8const flatten = require('storybook-root-cause/βflatten');9const storybook = require('storybook-root-cause/βstorybook');10const { storybook: { stories } } = storybook;11const flattenStories = flatten(stories);12const flatten = require('storybook-root-cause/βflatten');13const storybook = require('storybook-root-cause/βstorybook');14const { storybook: { stories } } = storybook;15const flattenStories = flatten(stories);16const flatten = require('storybook-root-cause/βflatten');17const storybook = require('storybook-root-cause/βstorybook');18const { storybook: { stories } } = storybook;19const flattenStories = flatten(stories);20const flatten = require('storybook-root-cause/βflatten');21const storybook = require('storybook-root-cause/βstorybook');22const { storybook: { stories } } = storybook;23const flattenStories = flatten(stories);24const flatten = require('storybook-root-cause/βflatten');25const storybook = require('storybook-root-cause/βstorybook');26const { storybook: { stories } } = storybook;27const flattenStories = flatten(stories);28const flatten = require('storybook-root-cause/βflatten');29const storybook = require('storybook-root-cause/βstorybook');30const { storybook: { stories } } = storybook;31const flattenStories = flatten(stories);32const flatten = require('storybook-root-cause/βflatten');33const storybook = require('storybook-root-cause/βstorybook');34const { storybook: { stories }
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!!