class MyModel < Sry::Struct
attribute :created_at, ::Types::Strict::Time.default(-> _ { Time.now }.freeze)
# attribute :created_at, ::Types::Strict::Time.default(Proc.new { Time.now }.freeze)
# attribute :created_at, ::Types::Strict::Time.default(lambda { |_| Time.now }.freeze)
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'app' | |
| require 'dry-struct' | |
| require 'types' | |
| class Events | |
| def self.migrate! | |
| return if db.table_exists?(table_name) | |
| db.create_table table_name do | |
| String :project, null: false |
Using rsync from cron on server A to pull files from server B via ssh.
Server A has a passwordless private key, the public key is in authorized_keys on Server B.
I can ssh from Server A to Server B.
To prevent use of ForwardAgent specific no configuration file:
ssh -F /dev/null -v admin@servera
Create some files (via templating) on the server
- name: Create backup configuration files
template:
src: "{{ item.type }}.yml.j2"
dest: "/tmp/{{ item.project }}_{{ item.env }}_{{ item.type }}.yml"
with_items:
- "{{ backup }}"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [1,2,3,4,5,6,7].drop(2) # => [3,4,5,6,7] | |
| [1,2,3,4,5,6,7].take(2) # => [1,2] | |
| [1,2,3,4,5,6,7].reverse.take(2) # => [5,7] | |
| [1,2,3,4,5,6,7].reverse.drop(2) # => [5, 4, 3, 2, 1] | |
| # sorting asc and desc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add = Proc.new { |a,b| a+b } | |
| add.call(1,2) # => 3 | |
| add_one = add.curry.call(1) | |
| add_one.call(2) # => 3 | |
| # with a method | |
| def subtract(a,b); b-a; end | |
system("bash -c 'set -o pipefail; mysqldump #{mysql_auth(configuration)} --force #{configuration[:database][:name]} | gzip -9 > #{tmp_file}'")pipefail is not avalible with sh only bash.
The exit code will be non-zero if an error occurs with mysqldump, however the pipe will still be processed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler/setup' | |
| env = ENV.fetch('RACK_ENV', 'production') | |
| Bundler.require(:default, env) | |
| require 'hanami/router' | |
| require 'hanami/controller' | |
| require 'hanami/validations' | |
| require 'haml' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client = Aws::S3::Client.new(region: 'eu-west-2', | |
| access_key_id: '...', | |
| secret_access_key: '...') | |
| # buckets are top-level, there are no sub-buckets and must be unique | |
| client.create_bucket(bucket: 'acme-test', acl: 'private') | |
| client.delete_bucket(bucket: 'acme-test') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "bundler" | |
| Bundler.setup | |
| require 'pathname' | |
| AppRoot = Pathname.new(__dir__) | |
| require 'yaml' |