Skip to content

Instantly share code, notes, and snippets.

View LucasKuhn's full-sized avatar
🧙‍♂️
Casting spells

Lucas Kuhn LucasKuhn

🧙‍♂️
Casting spells
  • Brazil
View GitHub Profile
@LucasKuhn
LucasKuhn / pipe.c
Created February 21, 2022 12:11
Exemplo de pipes
# include <fcntl.h>
# include "string.h"
# include <unistd.h>
int main()
{
int pipe_fds[2];
pipe(pipe_fds);
printf("Antes de redirecionar...\n");
{"Key Mappings":{"0xf700-0x260000":{"Text":"[1;6A","Action":10},"0x37-0x40000":{"Text":"0x1f","Action":11},"0x32-0x40000":{"Text":"0x00","Action":11},"0xf709-0x20000":{"Text":"[17;2~","Action":10},"0xf70c-0x20000":{"Text":"[20;2~","Action":10},"0xf729-0x20000":{"Text":"[1;2H","Action":10},"0xf72b-0x40000":{"Text":"[1;5F","Action":10},"0xf705-0x20000":{"Text":"[1;2Q","Action":10},"0xf703-0x260000":{"Text":"[1;6C","Action":10},"0xf700-0x220000":{"Text":"[1;2A","Action":10},"0xf701-0x280000":{"Text":"0x1b 0x1b 0x5b 0x42","Action":11},"0x38-0x40000":{"Text":"0x7f","Action":11},"0x33-0x40000":{"Text":"0x1b","Action":11},"0x7f-0x100000-0x33":{"Label":"","Action":11,"Text":"0x15"},"0xf703-0x220000":{"Text":"[1;2C","Action":10},"0x7f-0x80000-0x33":{"Label":"","Action":11,"Text":"0x1B 0x08"},"0xf701-0x240000":{"Text":"[1;5B","Action":10},"0xf70d-0x20000":{"Text":"[21;2~","Action":10},"0xf702-0x280000-0x7b":{"Label":"","Action":38,"Text":"\\033b"},"0xf702-0x260000":{"Text":"[1;6D","Action":10},"0xf729-0x40000":{"Text":
@LucasKuhn
LucasKuhn / instructions.md
Last active June 28, 2022 13:26
Downloading S3 files locally to be used with Rails' Active Storage

Download the S3 bucket to your local ./storage folder

  cd <your_app>
  AWS_ACCESS_KEY_ID=<key> AWS_SECRET_ACCESS_KEY=<secret> aws s3 sync s3://<bucket_name> storage

And then run a script to add the missing subfolders expected by Active Storage

  #script.rb 
@LucasKuhn
LucasKuhn / copy_s3.md
Created August 19, 2020 14:11
Copy a S3 bucket from different owners using only API_KEYS
  1. Copy the origin S3 bucket to a local temp folder using the origin key:
AWS_ACCESS_KEY_ID=<key-here> AWS_SECRET_ACCESS_KEY=<secret-here> aws s3 sync s3://origin-bucket-name temp
  1. Copy from your local temp folder to the destination bucket, using the destination key:
AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= aws s3 sync temp s3://destination-bucket-name
en:
activerecord:
models:
post: "The Masterpiece"
helpers:
submit:
create: "Mr Rails, create %{model} for me"
update: "I screwed up. Please update %{model}"
def submit(value = nil, options = {})
# ...
value ||= submit_default_value
# ...
end
def submit_default_value
object = convert_to_model(@object)
key = object ? (object.persisted? ? :update : :create) : :submit
@LucasKuhn
LucasKuhn / form_helper.rb
Created July 17, 2020 14:29
What form_with does
# helpers/form_helper.rb
def form_with(model: nil, scope: nil, url: nil)
# ...
url = polymorphic_path(model)
html_options = html_options_for_form_with(url, model, **options)
form_tag_html(html_options)
end
# helpers/form_tag_helper.rb
def form_tag_html(html_options)
<%= form_with(model: post, local: true) do |form| %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :content %>
<%= form.text_area :content %>
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->