Create a drag and droppable List in Rails
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
| numbers = [1, 2, 5, 8, 10, 13] | |
| enum.filter_map { |i| i * 2 if i.even? } | |
| # => [4, 16, 20] |
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
| const previewImageOnFileSelect = () => { | |
| // we select the photo input | |
| const input = document.getElementById('photo-input'); | |
| if (input) { | |
| // we add a listener to know when a new picture is uploaded | |
| input.addEventListener('change', () => { | |
| // we call the displayPreview function (who retrieve the image url and display it) | |
| displayPreview(input); | |
| }) | |
| } |
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
| array = %w( | |
| 1768 | |
| 1847 | |
| 1905 | |
| 1713 | |
| 1826 | |
| 1846 | |
| 1824 | |
| 1976 | |
| 1687 |
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
| string = "1-4 m: mrfmmbjxr | |
| 5-16 b: bbbbhbbbbpbxbbbcb | |
| 7-8 x: qxrxmxccxxx | |
| 9-11 k: kkkkkkktmkhk | |
| 8-12 g: sgwvdxzhkvndv | |
| 6-9 v: zvmvvmvvvd | |
| 8-19 f: ffffsplmfflffhtfrfj | |
| 5-16 p: pppppppppspppjpcp | |
| 2-3 w: wwmw | |
| 7-19 j: jjjjjjjjjjjjjjjjjjvj |
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
| # 02-Flow-Array/01-Can-you-vote/ | |
| def allowed_to_vote?(age) | |
| # TODO: return (not print!) a boolean stating whether `age` is old enough to vote | |
| # NOTE: Use an if/else statment | |
| unless age > 18 | |
| puts false | |
| else | |
| puts true | |
| 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 "date" | |
| def greetings(name) | |
| "Welcome to London #{name}! I hope you enjoy it!" | |
| end | |
| # puts greetings("James") | |
| # puts greetings("Nathan") | |
| # def one_plus_one |
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
| puts "----------------------------------------" | |
| puts "-----Welcome to The Price is Right!-----" | |
| puts "----------------------------------------" | |
| puts "Guess the price of this wonderful imaginary product" | |
| # computer picks a random number (generate random number) | |
| computer_number = rand(1..100) | |
| # ask the user to enter a number => gets.chomp |
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 'csv' | |
| # 1. Greet/Welcome the user to the Christmas List program! | |
| puts "(炉`路._(炉`路._(炉`路._(炉`路._(炉`路.__.路炉) _.路炉)_.路炉)_.路炉)_.路炉)" | |
| puts "(炉`路._(炉`路._ Welcome to the Christmas List! _.路炉)_.路炉)" | |
| puts "(炉`路._(炉`路._(炉`路._(炉`路._(炉`路.__.路炉) _.路炉)_.路炉)_.路炉)_.路炉)" | |
| options = [ | |
| "list", | |
| "add", | |
| "delete", |
simple_form_array_input.rb
class ArrayInput < SimpleForm::Inputs::StringInput
def input
input_html_options[:type] ||= input_type
existing_values = Array(object.public_send(attribute_name)).map do |element|
@builder.text_field(nil, input_html_options.merge(value: element, name: "#{object_name}[#{attribute_name}][]"))
end