Lua: Add a table inside a table - lua

local test = {
{
Resource = "test",
},
},
How can I add a table inside another table? so it will look like this
local test = {
{
Resource = "test",
{
File = "this is a test",
Code = "this is a test",
},
{
File = "this is a test",
Code = "this is a test",
},
},
}
Umm im only writing this because this post is mostly code and therefore have to put more text.
so please ignore this part :) and good new year

local test = {
{
Resource = "test",
},
}
for i = 1,2 do
test[1][i] = {
File = "this is a test",
Code = "this is a test",
}
end
or
for _ = 1,2 do
table.insert(test[1], {
File = "this is a test",
Code = "this is a test",
}
end

Related

Terraform for_each iteration with the file function

My requirement is to create a dynamic resource Confluent Schema. Below is the schema.tf file.
Basically, need to include map type object and will be creating different Schema by passing name and file attributes. What changes to be done on below highlighted "schema" file parameter so that it can be included in the for_each block?
resource "confluent_schema" "sample_avro_schema" {
schema_registry_cluster {
id = confluent_schema_registry_cluster.essentials.id
}
rest_endpoint = confluent_schema_registry_cluster.essentials.rest_endpoint
for_each = toset(var.subject_name_avro)
subject_name = each.key
format = "AVRO"
**schema = file("modules/confluent_kafka_cluster_dedicated/schemas/sample_schema_avro.avsc")**
credentials {
key = confluent_api_key.env-manager-schema-registry-api-key.id
secret = confluent_api_key.env-manager-schema-registry-api-key.secret
}
}
Variable declaration as below: variable.tf file
variable "subject_name_avro" {
description = "AVRO Schema Name"
type = list(string)
default = ["avro-topic-value"]
}
And I am running this execution using .tfvars file:
subject_name_avro = ["avro-topic-1-value"]
My requirement is to include below changes in .tfvars file. Kindly suggest what resource and variable level changes to be done to include schema file parameter dynamically.
subject_name_avro = [
{
subject_name_avro = "avro-topic-1-value"
schema = file("modules/confluent_kafka_cluster_dedicated/schemas/sample_schema_avro1.avsc")
},
{
subject_name_avro = "avro-topic-2-value"
schema = file("modules/confluent_kafka_cluster_dedicated/schemas/sample_schema_avro2.avsc")
},
]
Sample file content "sample_schema_avro.avsc"
{
"type": "record",
"namespace": "io.confluent.developer.avro",
"name": "Purchase",
"fields": [
{
"name": "item",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "customer_id",
"type": "string"
}
]
}
You can't use file in a variabiles. You can use only path in your case:
subject_name_avro = [
{
subject_name_avro = "avro-topic-1-value"
schema = "./modules/confluent_kafka_cluster_dedicated/schemas/sample_schema_avro1.avsc"
},
{
subject_name_avro = "avro-topic-2-value"
schema = "./modules/confluent_kafka_cluster_dedicated/schemas/sample_schema_avro2.avsc"
},
]
To iterate over this you can use count or for_each. With for_each it would be:
resource "confluent_schema" "sample_avro_schema" {
for_each = {for idx, val in var.subject_name_avro: idx => val}
schema_registry_cluster {
id = confluent_schema_registry_cluster.essentials.id
}
rest_endpoint = confluent_schema_registry_cluster.essentials.rest_endpoint
subject_name = each.value.subject_name_avro
format = "AVRO"
**schema = file(each.value.schema)
credentials {
key = confluent_api_key.env-manager-schema-registry-api-key.id
secret = confluent_api_key.env-manager-schema-registry-api-key.secret
}
}

Ruby make put / post http call with array of object

i have this http call code, the type is form
param = {
form: {
"creatives[]" => [
{
is_visible: params[:creative_banner_is_visible],
type: "banner",
value_translations: {
id: params[:creative_banner_value_id],
en: params[:creative_banner_value_en]
}
},
{
is_visible: params[:creative_video_is_visible],
type: "video",
value_translations: {
id: params[:creative_video_value_id],
en: params[:creative_video_value_en]
}
}
]
}
}
http = HTTP.headers(headers)
http.put(base_url, param)
but somehow this is translated to this on the target server
"creatives"=>[
"{:is_visible=>\"true\", :type=>\"banner\", :value_translations=>{:id=>\"Banner URL ID\", :en=>\"Banner URL EN\"}}",
"{:is_visible=>\"true\", :type=>\"video\", :value_translations=>{:id=>\"12345ID\", :en=>\"12345EN\"}}"
]
do you know how to make this http call not stringified? i used same schema on postman and work just fine
"creatives": [
{
"is_visible": true,
"type": "banner",
"value_translations": {
"id": "http://schroeder.info/elinore",
"en": "http://wehner.info/dusti"
}
},
{
"is_visible": true,
"type": "video",
"value_translations": {
"id": "85177e87-6b53-4268-9a3c-b7f1c206e002",
"en": "5134f3ca-ead7-4ab1-986f-a695e69ace96"
}
}
]
i'm using this gem https://github.com/httprb/http
EDIT
First, replace your "creatives[]" => [ ... with creatives: [ ... so the end result should be the following.
creatives = [
{
is_visible: params[:creative_banner_is_visible],
type: "banner",
value_translations: {
id: params[:creative_banner_value_id],
en: params[:creative_banner_value_en]
}
},
{
is_visible: params[:creative_video_is_visible],
type: "video",
value_translations: {
id: params[:creative_video_value_id],
en: params[:creative_video_value_en]
}
}
]
http = HTTP.headers(headers)
http.put(base_url, creatives.to_json)
Second, I don't see any problem with what you get in your target server, you just have to parse it to JSON, so if you also have a Rails app there use JSON.parse on the body.
somehow this approach fixed the issue
create_params = {}.compare_by_identity
create_params["creatives[][is_visible]"] = params[:creative_banner_is_visible]
create_params["creatives[][type]"] = 'banner'
create_params["creatives[][value_translations][id]"] = params[:creative_banner_value_id]
create_params["creatives[][value_translations][en]"] = params[:creative_banner_value_en]
create_params["creatives[][is_visible]"] = params[:creative_video_is_visible]
create_params["creatives[][type]"] = 'video'
create_params["creatives[][value_translations][id]"] = params[:creative_video_value_id]
create_params["creatives[][value_translations][en]"] = params[:creative_video_value_en]

Robot allowed the website but being identified and rejected

I need to do web scraping for a website which has allowed robot access. Below is the robot.txt file's content.
User-agent: *
Disallow:
Sitemap:https://www.sample.com/sitemap-index.xml
But when I try to fetch the website's content using nokogiri, it's being detected.
Nokogiri::HTML(open('https://www.sample.com/search?q=test', :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE))
Here the output:
> (Document:0x3fda40e7cf70 {
name = "document",
children = [
#(DTD:0x3fda40e9591c { name = "html" }),
#(Element:0x3fda40e8c95c {
name = "html",
attributes = [ #(Attr:0x3fda4071a598 { name = "style", value = "height:100%" })],
children = [
#(Element:0x3fda3fefa28c {
name = "head",
children = [
#(Element:0x3fda401a3088 {
name = "meta",
attributes = [ #(Attr:0x3fda40ebd7a0 { name = "name", value = "ROBOTS" }), #(Attr:0x3fda40ebd778 { name = "content", value = "NOINDEX, NOFOLLOW" })]
}),
#(Element:0x3fda4074faf4 {
name = "meta",
attributes = [ #(Attr:0x3fda3ff0beec { name = "name", value = "format-detection" }), #(Attr:0x3fda3ff0bed8 { name = "content", value = "telephone=no" })]
}),
#(Element:0x3fda401ca700 {
name = "meta",
attributes = [ #(Attr:0x3fda401c2050 { name = "name", value = "viewport" }), #(Attr:0x3fda401c217c { name = "content", value = "initial-scale=1.0" })]
}),
#(Element:0x3fda4079a284 {
name = "meta",
attributes = [ #(Attr:0x3fda4078bfb8 { name = "http-equiv", value = "X-UA-Compatible" }), #(Attr:0x3fda4078bf04 { name = "content", value = "IE=edge,chrome=1" })]
})]
}),
#(Element:0x3fda407e2e6c {
name = "body",
attributes = [ #(Attr:0x3fda430205f0 { name = "style", value = "margin:0px;height:100%" })],
children = [
#(Element:0x3fda4072e2a0 {
name = "iframe",
attributes = [
#(Attr:0x3fda3ff45214 {
name = "src",
value = "/_Incapsula_Resource?SWUDNSAI=28&xinfo=5-66719320-0%200NNN%20RT%281543054979096%20247%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B12%284%2c315%2c0%29%20U2&incident_id=245000650118470008-256430953704260629&edet=12&cinfo=04000000"
}),
#(Attr:0x3fda3ff451d8 { name = "frameborder", value = "0" }),
#(Attr:0x3fda3ff451b0 { name = "width", value = "100%" }),
#(Attr:0x3fda3ff45188 { name = "height", value = "100%" }),
#(Attr:0x3fda3ff45174 { name = "marginheight", value = "0px" }),
#(Attr:0x3fda3ff4514c { name = "marginwidth", value = "0px" })],
children = [ #(Text "Request unsuccessful. Incapsula incident ID: 245000650118470008-256430953704260629")]
})]
})]
})]
})
How can I achieve this web scraping?

gui.openurl not working (no error)

The following code is for an escape menu in a garrys mod server. It's written in lua. I have no idea what the problem could be and I've been working at it for a very long time. There is absolutely no error returned. Here's the full thing:
local buttonList = {
{
name = "Continue",
callback = function(panel)
panel:Remove();
Atomic.pauseUI = nil;
end
},
{
name = "Menu",
callback = function(panel)
panel:Remove();
gui.ActivateGameUI();
Atomic.showDefaultMenu = true;
Atomic.delayCheck = true;
end
},
--[[
{
name = "Settings",
callback = function(panel)
// panel:Remove();
end
},
--]]
{
name = "Rules",
callback = function(panel)
gui.OpenURL("https://steamcommunity.com/linkfilter/?url=https://facepunch.com")
end;
},
{
name = "Disconnect",
callback = function(panel)
RunConsoleCommand("disconnect");
end
}
};

payday2 demo menu script syntax error in Lua

I get an error when I run ingame it says
also posted source on pastebin SOURCE
The place where the error happens:
menu1 = menu1 or {
{ text = "Cancel", is_cancel_button = true }
{},
{ text = "+G0DM0DE~", callback = godmode }
{ text = "+Stamina Hack~", callback = staminahx }
{ text = "+Equipment/Tie Hack~", callback = sawsandties }
{ text = "No Recoil Or Spread!", callback = norclorsprd }
{ text = "< - Back", callback = callmenu0 },
}
You need to add comma between each elements of the table:
menu1 = menu1 or {
{ text = "Cancel", is_cancel_button = true }, --here
{},
{ text = "+G0DM0DE~", callback = godmode }, --here
{ text = "+Stamina Hack~", callback = staminahx }, --here
{ text = "+Equipment/Tie Hack~", callback = sawsandties }, --here
{ text = "No Recoil Or Spread!", callback = norclorsprd }, --here
{ text = "< - Back", callback = callmenu0 },
}

Resources