Nokogiri cannot exit opening a url - ruby-on-rails

When I try in pry (which is a substitute for IRB or rails console)
doc = Nokogiri::HTML(open(url))
It reads the file (although I have to keep pressing space bar). However, at the end, it says
(END)
and it doesn't return the command line back to me.
What do I need to do to exit this and get back to the prompt?

type q to exit less viewer. the result of Nokogiri::HTML is too long so you are seeing result bypassing less command

Related

Rails Console output breaks when modifying

Totally lacking intuition here.
First i thought i only happens when copying and pasting code from editor. Unfortunately it's more common. Only thing I am doing is trying to insert more code somewhere in the middle of current input or modifying it.
Expected behavior:
Modify input without side effects.
What actually happens:
VERY OFTEN when modifying input it gets messed up.
If that happens every key press will copy and insert current input alongside with pressed character.
Vital notes:
Encoding is set to UTF-8 in terminal(s)
Issue persists on different emulators ( Terminator, gnome-terminal )
Issue persists when using different Ruby runtime console ( IRB, Pry )
Issue appears to be related to Ruby runtime, NOT Linux shell (i guess...)
Issue appears since:
Since system install. Didn't appear on my MacBook Air
System:
ArchLinux, although coworker reported same thing happens on his MacBook Pro.
How to reproduce (works for me):
Open rails console
Type example code: Shift.where(name: "som").where(name: "dom").where(name: "pom")
Navigate cursor to modify first where statement.
Change "som" to "SOM"
Should see it break
Press random key repeatedly to see it break even more.
Images:
Good input
Now i will navigate to first where statement to change "som" to uppercase "SOM"
I basically navigated my cursor and pressed SHIFT+S, SHIFT+O, SHIFT+M
Hope it's clear enough :-)
Thank you!
EDIT 1:
Tried using zsh instead of bash, didn't help
Disabled spring gem, didn't help
EDIT 2:
Folks on reddit suggested that i should check if there are any Ruby readline warnings eg. "Readline is not installed". None of them appear anywhere. Also reinstalled ruby 2.4.1, seems like it's not the problem in my case.
EDIT 3:
I cannot reproduce the issue in a different Rails project.
Issue appears on Rails 5.1.1, meanwhile 5.0.3 works flawlessly.
Is it possible that Rails itself (or rather one of its gems) can be the cause?
I had a very similar issue, and I boiled it down to my coloring.
I had the following in my IRBRC:
class String
def _colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
_colorize(31)
end
def yellow
_colorize(33)
end
end
IRB.conf[:PROMPT][:MY_PROMPT] = {
:AUTO_INDENT => true, # enables auto-indent mode
:PROMPT_I => "[ME]".red + " > ".yellow, # normal prompt
:PROMPT_S => "[ME]".red + " ".yellow, # prompt for continuated strings
:PROMPT_C => "[ME]".red + " * ".yellow, # prompt for continuated statement
:RETURN => "[ME]".red + "=> ".yellow + "%s\n".red # format to return value
}
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
And when I removed the .red and .yellow, everything was just fine.
I think it's because my coloring characters like \e[31m was getting counted as a length 5 characters instead of 0 characters.
My solution was to remove my coloring for the time being. Hopefully someone will come up with a better solution than that.

interrupting lua interpretation without ctrl -c quitting

I am running code from the book programming in Lua... http://www.lua.org/pil/3.6.html
when I run this code in the terminal interpreter... it continues reading input forever...
list = nil
for line in io.lines() do
list = {next=list, value=line}
end
Ctrl C returns me to the prompt/bash. Is there another command to break? How do I break/return from a chunk of lua code without exiting the interpreter?
By pressing Ctrl-C in a Unix-like system, you are sending your process the signal of SIGINT, which by default will terminate the process.
Your program continues reading from input forever because it's blocking in the call of io.lines(), which keeps reading from standard input. To interrupt it, send your terminal an EOF, this is done by pressing Ctrl-D in a Unix-like system.
On Windows, the key to send EOF is Ctrl-Z.
You can indicate the end of input for stdin by using either Ctrl-Z or Ctrl-D.
CTRL-U deletes all the characters before the cursor position, therefore the whole line. It also works like this in a Linux shell.

Ruby Debugger code for going into next line

I am working on ROR app , with ruby debugger. This is my code:
def render(d)
debugger
folder=d.folders
folders,empty_folders=check_empty_folder(folder)
c = cost(folders)
end
Now in console the break point at folders=d.folders . Now if i do next near around 30 times then it come to next line in this function folders,empty_folders after going through different ruby source file.
Is there any command I can simply go into next line of function in spite of source code.

Simple program that reads and writes to a pipe

Although I am quite familiar with Tcl this is a beginner question. I would like to read and write from a pipe. I would like a solution in pure Tcl and not use a library like Expect. I copied an example from the tcl wiki but could not get it running.
My code is:
cd /tmp
catch {
console show
update
}
proc go {} {
puts "executing go"
set pipe [open "|cat" RDWR]
fconfigure $pipe -buffering line -blocking 0
fileevent $pipe readable [list piperead $pipe]
if {![eof $pipe]} {
puts $pipe "hello cat program!"
flush $pipe
set got [gets $pipe]
puts "result: $got"
}
}
go
The output is executing go\n result:, however I would expect that reading a value from the pipe would return the line that I have sent to the cat program.
What is my error?
--
EDIT:
I followed potrzebie's answer and got a small example working. That's enough to get me going. A quick workaround to test my setup was the following code (not a real solution but a quick fix for the moment).
cd /home/stephan/tmp
catch {
console show
update
}
puts "starting pipe"
set pipe [open "|cat" RDWR]
fconfigure $pipe -buffering line -blocking 0
after 10
puts $pipe "hello cat!"
flush $pipe
set got [gets $pipe]
puts "got from pipe: $got"
Writing to the pipe and flushing won't make the OS multitasking immediately leave your program and switch to the cat program. Try putting after 1000 between the puts and the gets command, and you'll see that you'll probably get the string back. cat has then been given some time slices and has had the chance to read it's input and write it's output.
You can't control when cat reads your input and writes it back, so you'll have to either use fileevent and enter the event loop to wait (or periodically call update), or periodically try reading from the stream. Or you can keep it in blocking mode, in which case gets will do the waiting for you. It will block until there's a line to read, but meanwhile no other events will be responded to. A GUI for example, will stop responding.
The example seem to be for Tk and meant to be run by wish, which enters the event loop automatically at the end of the script. Add the piperead procedure and either run the script with wish or add a vwait command to the end of the script and run it with tclsh.
PS: For line-buffered I/O to work for a pipe, both programs involved have to use it (or no buffering). Many programs (grep, sed, etc) use full buffering when they're not connected to a terminal. One way to prevent them to, is with the unbuffer program, which is part of Expect (you don't have to write an Expect script, it's a stand-alone program that just happens to be included with the Expect package).
set pipe [open "|[list unbuffer grep .]" {RDWR}]
I guess you're executing the code from http://wiki.tcl.tk/3846, the page entitled "Pipe vs Expect". You seem to have omitted the definition of the piperead proc, indeed, when I copy-and-pasted the code from your question, I got an error invalid command name "piperead". If you copy-and-paste the definition from the wiki, you should find that the code works. It certainly did for me.

How do I Quit IRB from the command line? (Using terminal on mac)

Basically, I'm typing along just fine in terminal, using IRB to run ruby commands:
2.0.0-p0 :014 > bank_account.withdraw(2222)
=> -1222
But sometimes I accidentally miss out a quotation mark.
2.0.0-p0 :020 > BankAccount.create_for("Jim","Johnson)
2.0.0-p0 :021"> bank_account.withdraw(333)
If you look carefully, you'll see that the speech mark I missed out appears next to the line number on the left, next to the patch version.
From here on in, that speech mark appears everytime I run a command! And it stops the commands working:
2.0.0-p0 :021"> BankAccount.create_for("Julian","Hurley")
2.0.0-p0 :022"> BankAccount.create_for("Katt","Smith")
2.0.0-p0 :023"> exec($0)
What I want to know is, how do I get rid of that quotation mark? Or quit IRB from the command line in order to reset it?
If you haven't closed a quote, just put a quote in and hit return.
Exiting from the console can be done by typing exit, though in the circumstance your are would need to hit Control - C
Control - C followed by Control - Z.
I hope it helps!
I was having the same problem. To exit irb within the terminal, type exit.
Use Ctrl-D, it is an end-of-input for irb. If you are in the middle of some command, use Ctrl-C first to terminate the input of this command.
Type quit() and hit Enter to exit ruby.
If you're in the middle of a multi-line block (according to the interpreter), hit Ctrl+C to break out of it.
Then you can do any of the following to quit:
exit (or exit())
quit (or quit())
irb_exit (or irb_exit())
Ctrl+D (sends the EOF character)

Resources