Posts by vinibrsl • 19,711 points
378 posts
-
7
votes1
answer85
viewsA: What is the Java equivalent of this Ruby lambda?
Closures The following is not lambda, but a block or closure. It is quite common to see blocks in high-order functions acting as first class functions, not only in Ruby but also in most languages.…
-
15
votes2
answers1855
viewsA: What is Monkey patch?
What is Monkey patching? The term, which has a strange name, refers to when you modify or extend the behavior of an application at its runtime. The term popular form is called Monkey patching, but…
terminologyanswered vinibrsl 19,711 -
0
votes1
answer210
viewsA: Nomethoderror: Undefined method `Production' for "Development":Activesupport::Stringinquirer
You’re running with production environment while it’s supposed to be development. Seven the RAILS_ENV for development and run the migrations in this way: RAILS_ENV=development rails db:drop…
-
1
votes1
answer53
viewsA: Rails - Gem Cancancan and Devise
Every time the function authenticate_user! is called, so Devise requires you to need a user. What I would do in that case is to create a ApplicationController only for your party that needs…
-
1
votes1
answer138
viewsA: How to generate sequential number automatically in Rails?
That one 00012018 that you want does not need to be persisted, and can be used only for visualization. To do this, you can implement a method in the model. class Inscricao < ApplicationRecord def…
-
0
votes1
answer66
viewsA: How to find the number of records of a model?
Active Record models have the method #count, which can be used as follows: Book.count # SELECT COUNT(*) FROM books => 10 You can even apply conditions to the query, this way: Book.where(status:…
-
1
votes1
answer26
viewsA: Ruby unit test does not work
This is not a Minitest mistake, but a Rubymine mistake. You need to setup the Minitest for the IDE you are using. Here is the official tutorial from Jetbrains how to setup it.…
-
5
votes5
answers2767
viewsA: HTTP methods in practice
TL;DR: not that there needs to be a resource for authentication, but it needs authorization for you to manipulate a resource. The first concept to be understood from REST is the recourse. It is…
-
0
votes2
answers50
viewsA: Ruby Application Hosting with Sinatra
The Heroku is the simplest to resolve in the short term. If you’re looking for a more robust solution that can be even cheaper than Heroku, look for the Google Cloud Platform App Engine with CI/CD…
-
2
votes1
answer178
viewsA: Ruby syntax error: Unexpected tCONSTANT, expecting keyword_end
You are repeating double quotes, Ruby cannot know where your string actually ends. Change the double quotes at the beginning by simple and will solve. @testes = Teste.find_by_sql( ' SELECT * FROM…
-
3
votes1
answer58
viewsA: Enumerable and Ruby Comparable
DRT: the Enumerable is responsible for seeking and ordering and the Comparable by setting out the ordination rules (>, <, >=, <=) of the items of the enumeration. The relationship…
-
0
votes1
answer226
viewsA: Vue-router replace not working?
Your beforeEach is not correct. It must be in the same scope where its instantiated router. const router = new VueRouter({ ... }) router.beforeEach((to, from, next) => { // ... })…
-
1
votes2
answers555
viewsA: How to use for in Ruby?
Rubists are not fans of explicit ties like for and while. It is very common to see loops using iterators, as does the Array#each: a = [ "a", "b", "c" ] a.each {|x| print x, " -- " } => a -- b --…
-
0
votes3
answers169
viewsA: check if you have a comma and delete a comma if you have it in the string by Ruby
You can use the method String#delete. 'Essa é uma string de testes, ok?'.delete(',') => 'Essa é uma string de testes ok?' The nice thing about this method is that you can write some expressions.…
-
8
votes1
answer975
viewsQ: Do front-end or back-end processing?
In the client-side and server-side separation architecture, it is common to doubt who is responsible for some processing. On the one hand, processing on the client-side can be beneficial for…
-
19
votes2
answers1855
viewsQ: What is Monkey patch?
What is Monkey patch in programming and what is the usefulness and risk of using such a technique? This concept varies from technology to technology, from language to language or what? And another…
terminologyasked vinibrsl 19,711 -
4
votes2
answers663
viewsA: Ruby - comparison of values between a range or greater than, less than
The response of @Anthraxisbr works well, but I’d like to extend it explaining why it works. The comparison when > 10 does not work because an expression needs two sides. The when expects a value…
-
1
votes1
answer217
viewsA: Do not stop setTimeOut when changing browser tabs
Modern browsers suspend some Javascript codes, such as setTimeout, when the window is not in focus to save power and processing resources. Imagine if you were running Javascript when you minimized…
-
16
votes1
answer798
viewsA: What are the metadata?
Meta, Greek (μετά), means "behind" or "beyond". Metadata is information about a given. Think of a photo taken from a camera: The data itself is the image. It’s what you see above. Metadata could be:…
terminologyanswered vinibrsl 19,711 -
5
votes1
answer425
viewsQ: What is Hoisting’s utility in Javascript?
Before ES6, all variables of a function are created independent of JS scope. That is to say: if(false) { var mensagem = "Olá!"; // declaração + atribuição } console.log(mensagem); => undefined…
-
1
votes1
answer2624
viewsA: How to view image with Angular 2+
Angular has nothing native to render an array of bytes in image. But it can transform an encrypted byte array in Base64 into a rendered image using a directive. I took the example of Soen, but I…
-
2
votes1
answer523
viewsA: How to use other HTTP methods in HTML forms?
The solution The method PUT does not exist in HTML standards. The DELETE neither. It is common to use this workaround: <form method="post"> <input type="hidden" name="_method" value="put"…
-
6
votes1
answer304
viewsQ: What are the delegates?
In iOS programming it is common to use structures that act as delegates. One of them, for example, is the UITextFieldDelegate. This class, according to documentation, informs the implementor of…
-
1
votes1
answer87
viewsA: Ruby Rails Beginner
TL;DR puts 'Qual é seu nome?' nome = gets.chomp puts "E aí, #{nome}!" About Ruby and Rails Ruby is the language. Ruby on Rails is the framework for building web applications. My recommendation is…
-
2
votes1
answer93
viewsA: Mkdir creates directories without permission
The umask is the command that determines the settings of a mask that controls which file permission will be given to new files created on the system. Each process in the operating system has its own…
-
3
votes1
answer379
viewsQ: What is the difference between metaprogramming and reflection?
There are two terms that look a lot like when we are talking about introspection techniques: metaprogramming and reflection. Wikipedia treats reflection as a key strategy of metaprogramming…
-
0
votes0
answers55
viewsQ: How to get a variable name?
Is there any way to get the name of a variable using metaprogramming (or reflection, I believe) in Ruby? I want something like nameof of the C#. I was looking for something like: minha_variavel =…
-
5
votes3
answers3647
viewsA: What are the differences between a source editor, text editor and an IDE?
Complementing the excellent response of Maniero: Text editor: Does not specialize in code editing, but can edit code. Example: iPhone Notes and Windows Notepad. Code editor: specialized in code. It…
-
4
votes1
answer270
viewsQ: What is the difference between mixins and inheritance?
Conceptually, there is a difference between a class that extends a module by mixin and a class that inherits another class (unique inheritance)? I know why mixins, a class can extend multiple…
-
1
votes2
answers1410
viewsA: Alternative to Mysql Workbench
If you use Macos, no doubt Sequel Pro. It is native to Macos Made exclusively for Mysql If you mess with permissions, you have an excellent UI for such It’s open source and free If you don’t use…
-
2
votes1
answer577
viewsA: working with decimal {5,2} Rails
The problem has nothing to do with decimals, but with field nomenclature. Your model does not contemplate ValorAula, and yes, as shown in migration file, valorAula. The…
-
-1
votes2
answers159
viewsA: Problem calling javascript function
Sometimes the event load may not be fired at document. Instead, use the window: window.addEventListener('load', function() { alert('I am working!') });…
-
11
votes5
answers625
viewsA: Allow or not allow end spaces in passwords?
In thesis... If your encryption algorithm accepts them, any data printable should be able to be part of a password, the rest is service policy. Defining a Service Policy You need to define a service…
-
6
votes1
answer991
viewsQ: Why insert a blank line at the end of the code?
Most linters from different programming languages, such as Rubocop (Ruby) and Jslint (Javascript) recommend a blank line from the end of all code files. As an example, Rubocop:…
-
1
votes3
answers53
viewsA: Ruby application on Rails
Yes. RAILS_ENV=<ambiente> <comando> For example, to rotate the seeding from the test database, do: RAILS_ENV=test rails db:seed The environments are test, development, staging and…
-
1
votes1
answer109
viewsA: Display higher word frequency per line and calculate number of words per line
You are on the right track! First of all you need to group the values, for this I will use the Enumerable#each_with_object. frase = 'hustle hustle talent' # precisa do split para obter ['hustle',…
-
1
votes1
answer111
viewsA: Why don’t booleans have a common class in Ruby?
In a e-mail questioning the same to Yukihiro "Matz" Matsumoto, creator of Ruby, he replies: Any good reason why these [TrueClass and FalseClass] do not inherit Bool or something like? Is there any…
-
2
votes1
answer111
viewsQ: Why don’t booleans have a common class in Ruby?
Ruby doesn’t have a class Boolean. I realized that boolean objects are of specific classes depending on the value, see: true.class => TrueClass false.class => FalseClass Different from other…
-
1
votes1
answer152
viewsA: How to change Imagebrush background?
You can set a color to the background of the TextBox using the property TextBox.Background: textBox.Background = Brushes.Black; // a classe Brushes já tem cores pré definidas If you want an image in…
-
0
votes1
answer86
viewsA: bcrypt error in Rails 5.1
Uninstall the Gems relating to bcrypt and reinstall as in the last line below: gem uninstall bcrypt-ruby gem uninstall bcrypt gem install bcrypt --platform=ruby Then, in your Gemfile, replace the…
-
0
votes2
answers736
viewsA: How to make an HTTP request in Ruby?
A Gem HTTP (http.Rb) makes this work easier. To install, just add to your Gemfile: gem "http" and execute bundle install in the shell. require 'http' response = HTTP.post("https://api.test/post",…
-
1
votes1
answer434
viewsQ: How to convert an object to Boolean in Ruby?
Ruby objects have some methods for representation in another type, such as: to_s: convert to string to_a: convert to array to_i: convert to whole to_f: convert to float But there is no standard…
-
1
votes1
answer434
viewsA: How to convert an object to Boolean in Ruby?
The idiomatic way to convert an object of any type to Boolean in Ruby is by using a double negation (also called double bang in the Ruby community): def to_b(obj) !!obj end The double negation does…
-
3
votes1
answer1351
viewsA: How to discover the file extension through the Bytes array?
Find the MIME type Has the package Mime-Detective. It’s in the Nuget repository. You’d use it like this: byte[] myDataBuffer = myWebClient.DownloadData(image_url); FileType fileType =…
-
1
votes1
answer439
viewsA: how to refer by name or half of the name in the birthday management list c# console application?
You need to get the term to be searched by the user. For this you can use the Console.ReadLine. Therefore: var termo = Console.ReadLine(); This variable will save the term to be searched for. To…
-
0
votes2
answers1599
viewsA: What is Github really for?
To understand the importance of Github, you need to understand the importance of a version control system. version control is a system that records changes made to a file or a set of files over time…
-
2
votes1
answer229
viewsA: Are Xamarin Studio and Monodevelop the same IDE?
Xamarin Studio is Monodevelop with Addins and brand of Xamarin. Check out this tweet from the main developer of the project. It’s open source and it’s on Github. If you want to use Xamarin Studio…
-
2
votes1
answer39
viewsA: Texblock - Make a text change event
Code-Behind Binding Use a Binding for the property Text and seven in the DataContext of the screen. From there you can use the NotifyOnTargetUpdated and the TargetUpdated, thus: <TextBlock…
-
1
votes2
answers501
viewsA: How do I determine the search path for Controllers and Views?
In the archive Startup.cs must have a method called Configure. There you will find the configured routes, and one of them is something for the controller Home, no longer exists. Switch to the…
-
3
votes1
answer137
viewsA: Protect the server from "false requests"
If you are moving the data through the HTTPS, through the SSL or TLS protocol, whole data packet is encrypted: the request itself, verb (method), URL, headers and parameters. Through a traffic…