converting ruby struct to yaml - struct

I have a struct in ruby that looks like this:
Struct.new("Device", :brand, :model, :port_id)
#devices = [
Struct::Device.new('Apple', 'iphone5', 3),
Struct::Device.new('Samsung', 'Galaxy S4', 1)
]
Converting this to_yaml gives me this result:
---
- !ruby/struct:Struct::Device
brand: Apple
model: iphone5
port_id: 3
- !ruby/struct:Struct::Device
brand: Samsung
model: Galaxy S4
port_id: 1
However I'm still not sure how to convert my struct back from yaml whenever I need to use it in my code. When I add devices: on top of the yaml code and then try to parse it back to ruby struct from the CONFIG['devices'] variable - I don't get any results.
Any help will be appreciated!

I'm not seeing your problem:
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> Struct.new("Device", :brand, :model, :port_id)
=> Struct::Device
irb(main):003:0> devices = [
irb(main):004:1* Struct::Device.new('Apple', 'iphone5', 3),
irb(main):005:1* Struct::Device.new('Samsung', 'Galaxy S4', 1)
irb(main):006:1> ]
=> [#<struct Struct::Device brand="Apple", model="iphone5", port_id=3>, #<struct Struct::Device brand="Samsung", model="Galaxy S4", port_id=1>]
irb(main):007:0> y = devices.to_yaml
=> "---\n- !ruby/struct:Struct::Device\n brand: Apple\n model: iphone5\n port_id: 3\n- !ruby/struct:Struct::Device\n brand: Samsung\n model: Galaxy S4\n port_id: 1\n"
irb(main):008:0> obj = YAML::load(y)
=> [#<struct Struct::Device brand="Apple", model="iphone5", port_id=3>, #<struct Struct::Device brand="Samsung", model="Galaxy S4", port_id=1>]
You must make sure that the Struct.new runs before the YAML::load as well as before the .to_yaml. Otherwise Ruby doesn't know how to create the struct from text.
Okay, as I said, you must run the Struct definition before trying to load. Plus you are trying to build a hash, so use that YAML syntax:
config.yml:
---
devices:
- !ruby/struct:Struct::Device
brand: Apple
model: iphone5
port_id: 3
- !ruby/struct:Struct::Device
brand: Samsung
model: Galaxy S4
port_id: 1
And test.rb:
require 'yaml'
Struct.new("Device", :brand, :model, :port_id)
CONFIG = YAML::load_file('./config.yml') unless defined? CONFIG
devices = CONFIG['devices']
puts devices.inspect
Result:
C:\>ruby test.rb
[#<struct Struct::Device brand="Apple", model="iphone5", port_id=3>, #<struct Struct::Device brand="Samsung", model="Galaxy S4", port_id=1>]

Related

need an appropriate loader to handle this file type in audio files

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file
i get this error when i want to console.log my audio files in array in my audioData.js
here is my audioData.js :
export const audios =[
{
name: 'Ağlatma Gelem',
artist: 'Oğuz Aksaç',
music: require('../audios/oguz-aksac-aglatma-gelem.mp3')
},
{
name: 'NKBİ',
artist: 'Güneş',
music: require('../audios/gunes-nkbi.mp3')
},
{
name: 'Goge Bakmak Icin',
artist: 'Saian, Çagri Sinci',
music: require('../audios/sai-cs-gbi.mp3')
}
]
i noticed that error is about loader(maybe about babel-loader) in my webpack.config.js but i cant solve it

Can not use keyboard 3rd level on Manjaro

I feel all my settings right:
~/: setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules: evdev
model: pc105
layout: us,ru
variant: ,
options: grp:shift_caps_switch,lv3:switch,nbsp:level2
Trying to build keymap using the following components:
keycodes: evdev+aliases(qwerty)
types: complete
compat: complete
symbols: pc+us+ru:2+inet(evdev)+group(shift_caps_switch)+level3(switch)+nbsp(level2)
geometry: pc(pc105)
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+ru:2+inet(evdev)+group(shift_caps_switch)+level3(switch)+nbsp(level2)" };
xkb_geometry { include "pc(pc105)" };
};
~/: localectl status
System Locale: LANG=ru_RU.UTF-8
VC Keymap: us
X11 Layout: us,ru
X11 Model: pc105
X11 Variant: ,
X11 Options: grp:shift_caps_switch,lv3:ralt_switch_multikey,numpad:mac,nbsp:level2
But the 3rd level or compose layer (ralt+shift) just does nothing. And it seems to me like there is no of these layouts in my Manjaro (XFCE) distribution.
Finally, I've found the reason: need to add typo layout to every layout in xkb:
$ setxkbmap -layout us+typo,ru:2+typo
Also, 3rd level should be enabled, for example like:
lv3:ralt_switch_multikey

Can't set environment variables for container in ApplicationLoadBalancedFargateService

(CDK 1.18.0 and Python 3.6)
task_role = iam.Role(
self,
id=f"...",
assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"),
managed_policies=[...]
)
repo = get_repo(self)
task_def = ecs.FargateTaskDefinition(
self,
"...",
memory_limit_mib=30720,
cpu=4096,
task_role=task_role,
execution_role=self.ecs_execution_role,
)
cont = task_def.add_container(
"...",
image=ecs.ContainerImage.from_ecr_repository(repo),
logging=ecs.LogDrivers.aws_logs(stream_prefix=f"Logging"),
command=["bash", "start.sh"],
environment={"NAME1": 'VALUE1', "NAME2": 'VALUE2'} # what would I have to put here?
)
cont.add_port_mappings(ecs.PortMapping(container_port=8080))
fg = ecsp.ApplicationLoadBalancedFargateService(
self,
"...",
task_definition=task_def,
assign_public_ip=True,
)
I want to pass NAME1=VALUE1 and NAME2=VALUE2 to the container.
I tried various ways to express the environment variables. But none worked. Am I doing something fundamentally wrong here?
Other than this specific issue the service deploys and runs.
The approach you follow seems to work here on the latest version (1.23.0). But I could not find any hint in the release notes why this might have changed. Can you update to the latest version?
task_def.add_container("container", environment={"a": "b", "c": "d"}, image=aws_ecs.ContainerImage.from_registry(name="TestImage"), memory_limit_mib=512)
newtask1C300F30:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Environment:
- Name: a
Value: b
- Name: c
Value: d
Essential: true
Image: TestImage
Memory: 512
Name: container

In Cloudformation YAML, use a Ref in a multiline string (? use Fn:Sub)

Imagine you have a aws resource such as
Resources:
IdentityPool:
Type: "AWS::Cognito::IdentityPool"
Properties:
IdentityPoolName: ${self:custom.appName}_${self:provider.stage}_identity
CognitoIdentityProviders:
- ClientId:
Ref: UserPoolClient
The Ref for "AWS::Cognito::IdentityPool" returns the id of this resource. Now lets say I want to reference that id in a multiline string. I've tried
Outputs:
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value: |
{
'aws_cognito_identity_pool_id': ${Ref: IdentityPool}, ##<------ Error
'aws_sign_in_enabled': 'enable',
'aws_user_pools_mfa_type': 'OFF',
}
I've also tried to use Fn:Sub but without luck.
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value:
Fn::Sub
- |
{
'aws_cognito_identity_pool_id': '${Var1Name}',
'aws_sign_in_enabled': 'enable',
}
- Var1Name:
Ref: IdentityPool
Any way to do this?
Using a pipe symbol | in YAML turns all of the following indented lines into a multi-line string.
A pipe, combined with !Sub will let you use:
your resources Ref return value easily like ${YourResource}
their Fn::GetAtt return values with just a period ${YourResource.TheAttribute}
any Pseudo Parameter just as is like ${AWS:region}
As easy as !Sub |, jumping to the next line and adding proper indentation. Example:
Resources:
YourUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: blabla
Outputs:
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value: !Sub |
{
'aws_cognito_identity_pool_id': '${YourUserPool}',
'aws_sign_in_enabled': 'enable',
'aws_user_pools_mfa_type': 'OFF',
}
AdvancedUsage:
Description: use Pseudo Parameters and/or resources attributes
Value: !Sub |
{
'aws_region': '${AWS::Region}',
'user_pool_arn': '${YourUserPool.Arn}',
}
I found out how to do this using Join
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value:
Fn::Join:
- ''
- - "{"
- "\n 'aws_cognito_identity_pool_id':"
- Ref : IdentityPool
- "\n 'aws_user_pools_id':"
- Ref : UserPool
- "\n 'aws_user_pools_web_client_id':"
- Ref : UserPoolClient
- ",\n 'aws_cognito_region': '${self:provider.region}'"
- ",\n 'aws_sign_in_enabled': 'enable'"
- ",\n 'aws_user_pools': 'enable'"
- ",\n 'aws_user_pools_mfa_type': 'OFF'"
- "\n}"
This works but it's kinda ugly. I'm going to leave this answer unaccepted for a while to see if anyone can show how to do this with Fn::Sub.
Using YAML you could compose this simply:
Outputs:
AmplifyConfig:
Description: key/values to be passed to Amplify.configure(config);
Value: !Sub '
{
"aws_cognito_identity_pool_id": "${IdentityPool}",
"aws_sign_in_enabled": "enable",
"aws_user_pools_mfa_type": "OFF",
}'
Leaving this here as I encountered a Base64 encoding error when doing something similar and this question came up when searching for
a solution.
In my case I was a using multi line string + !Sub to populate UserData and receiving the following error in AWS Cloudformation.
Error:
Invalid BASE64 encoding of user data. (Service: AmazonEC2; Status
Code: 400; Error Code: InvalidUserData.Malformed; Request ID: *;
Proxy: null)
Solution:
Can be solved by combining two built in Cloudformation functions; Fn::Base64 and !Sub:
UserData:
Fn::Base64: !Sub |
#!/bin/bash
echo ${SomeVar}

jsonix properties - ogc-schemas .js aren't same

The manual on jsonix properties at https://github.com/highsource/jsonix/wiki/Properties shows properties as being something like:
name: 'MyModule',
typeInfos: [{
type: 'classInfo',
localName: 'InputType',
propertyInfos: [{
type: 'attribute',
typeInfo: 'Boolean',
name: 'checked'
}]
}],
But then (after npm install ogc-schemas) what I am seeing is:
ln: 'TimeClockPropertyType',
ps: [{
n: 'timeClock',
rq: true,
en: 'TimeClock',
ti: '.TimeClockType'
},
With the abbreviated names.
Which should it be and why doesn't it matter if it doesn't?
Disclaimer: I'm the author of jsonix.
This is what's called compact naming. This is an option of the Jsonix Schema Compiler which generates shorter names in mappings, like n instead of name or dens instead of defaultElementNamespaceURI. The goal is clearly to make mappings smaller and since ogc-schemas are pretty large, they are compiled with compact naming by default.
If you want standard naming, fork and remove
<arg>-Xjsonix-compact</arg>
from all the pom.xmls.
Both compact and standard names work in runtime, I think standard names have higher priority.

Resources