pr

Timofei Shatrov: Previewing images in and out of SLIME REPL

As any Common Lisp coder knows, a REPL is an incredibly useful tool. It can be used not just for development, but for running all sorts of tasks. Personally, I don't bother making my Lisp tools into executable scripts and just run them directly from SLIME. As such, any operation that requires leaving the REPL is quite inconvenient. For me, one such operation was viewing image files, for example in conjunction with my match-client:match tool. So lately I've been researching various methods to incorporate this functionality into the normal REPL workflow. Below, I present 3 methods that can be used to achieve this.

Open in external program

This one's easy. When you want to view a file, launch an external process with your favorite image viewer. On Windows a shell command consisting of the image filename would launch the associated application, on Linux it's necessary to provide the name of the image viewer.

(defvar *image-app* nil) ;; set it to '("eog") or something

(defun view-file-native (file)
  (let ((ns (uiop:native-namestring file)))
    (uiop:launch-program (if *image-app*
                             (append *image-app* (list ns))
                             (uiop:escape-shell-token ns)))))

Note that uiop:launch-program is used instead of uiop:run-program. The difference is that launch- is non-blocking - you can continue to work in your REPL while the image is displayed, whereas run- will not return until you close the image viewer.

Also note that when the first argument to run/launch-program is a string, it is not escaped, so I have to do it manually. And if the first argument is a list, it must be a program and a list of its arguments, so merely using (list ns) wouldn’t work on Windows.

Inline image in REPL

The disadvantage of the previous method is that the external program might steal focus, appear on top of your REPL and disrupt your workflow. And it's well known that Emacs can do everything, including viewing images, so why not use that?

In fact, SLIME has a plugin specifically for displaying images in REPL, slime-media. However it’s difficult to find any information on how to use it. Eventually I figured out that SWANK (SLIME’s CL backend) needs to send an event :write-image with appropriate arguments and slime-media's handler will display it right in the REPL. The easiest way is to just send the file path. The second argument is the resulting image's string value. If you copy-paste (sorry, "kill-yank") it in the repl, it would act just like if you typed this string.

(swank::send-to-emacs '(:write-image "/path/to/test.png" "test"))

You can even send raw image data using this method. I don't have anything on hand to generate raw image data so here's some code that reads from a file, converts it to a base64 string and sends it over SWANK.

(with-open-file (in "/path/to/test.png" :direction :input  :element-type '(unsigned-byte 8))
                (let* ((arr (make-array (file-length in) :element-type '(unsigned-byte 8)))
                       (b64 (progn (read-sequence arr in) (cl-base64:usb8-array-to-base64-string arr))))
                  (swank::send-to-emacs `(:write-image ((:data ,b64 :type swank-io-package::png)) "12345"))))

Note that the first argument to :write-image must be a list with a single element, which is itself a plist containing :data and :type keys. :data must be a base64-encoded raw image data. :type must be a symbol in swank-io-package. It’s not exactly convenient, so if you’re going to use this functionality a helper function/macro might be necessary.

Image in a SLIME popup buffer

Inline images are not always convenient. They can’t be resized, and will take up as much space as is necessary to display them. Meanwhile EMACS itself has a built-in image viewer (image-mode) which can fit images to width or height of a buffer. And SLIME has a concept of a “popup buffer” which is for example used by macroexpander (C-c C-m) to display the result of a macro expansion in a separate window.

Interestingly, slime-media.el defines an event :popup-buffer but it seems impossible to trigger it from SWANK. It is however a useful code reference for how to create the popup buffer in ELisp. This time we won’t bother with “events” and just straight up execute some ELisp code using swank::eval-in-emacs. However by default, this feature is disabled on Emacs-side, so you’ll have to set Emacs variable slime-enable-evaluate-in-emacs to t in order for this method to work.

Also Emacs must be compiled with ImageMagick for the resizing functionality to work.

Anyway, the code to view file in the popup buffer looks like this:

(defun view-file-slime (file &key (bufname "*image-viewer*"))
  (let ((ns (namestring file)))
    (swank::eval-in-emacs
     `(progn
        (slime-with-popup-buffer (,bufname :connection t :package t)
          (insert-image (create-image ,ns))
          (image-mode)
          (setf buffer-file-name ,ns)
          (not-modified)
          (image-toggle-display-image))
        ;; try to resize the image after the buffer is displayed
        (with-current-buffer ,bufname (image-toggle-display-image))))))
    ))

Arriving to this solution has required reading image-mode’s source code to understand what exactly makes image-mode behave just like if the image file was opened in Emacs via C-x C-f. First off, image-mode can be a major and a minor mode - and the minor mode is not nearly as useful. slime-with-popup-buffer has a :mode keyword argument but it would cause image-mode to be set before the image is inserted, and it will be a minor mode in this case! Therefore (image-mode) must be called after insert-image.

Next, the buffer must satisfy several conditions in order to get image data from the filename and not from the buffer itself. Technically it shouldn’t be necessary, but I couldn’t get auto resizing to work when data-p is true. So I set buffer-file-name to image’s filename and set not-modified flag on.

Next, image-toggle-display-image is called to possibly resize the image according to image-mode settings. It's called outside of slime-with-popup-buffer for the following reason: the buffer might not yet be visible and have any specific dimensions assigned to it, and therefore resizing will do nothing.

Here’s an example of how calling this function looks in Emacs.

The position of the popup buffer depends on whether the original Emacs window is wide enough or not. I think it looks better when it’s divided vertically. Use M-x image-transform-fit-to-height or M-x image-transform-fit-to-width to set up the auto-resizing method (it gets remembered for future images). Unfortunately there’s no way to fit both height and width, at least with vanilla Emacs. I prefer fit-to-width because in case the image is too tall, it is possible to scroll the image vertically with M-PgDn and M-PgUp from the other buffer. Unlike other image-mode buffers, this buffer supports a shortcut q to close itself, as well as various SLIME shortcuts, for example C-c C-z to return to the REPL.

That's it for now, hope you enjoyed this overview and if you happen to know a better way to display images in Emacs, I would be interested to hear about it.




pr

Vsevolod Dyomkin: Dead-Tree Version of "Programming Algorithms"

I have finally obtained the first batch of the printed "Programming Algorithms" books and will shortly be sending them to the 13 people who asked for a hardcopy.

Here is a short video showing the book "in action":

If you also want to get a copy, here's how you do it:

  1. Send the money to my PayPal account: $30 if you want normal shipping or $35 if you want a tracking number. (The details on shipping are below).
  2. Shoot me an email to vseloved@gmail.com with your postal address.
  3. Once I see the donation, I'll go to the post office and send you the book.
  4. Optionaly step: if you want it to be signed, please, indicate it in your letter.
Shipping details: As I said originally, the price of the dead-tree version will be $20+shipping. I'll ship via the Ukrainian national post. You can do the fee calculation online here (book weight is 0.58 kg, size is 23 x 17 x 2 cm): https://calc.ukrposhta.ua/international-calculator. Alas, the interface is only in Ukrainian. According to the examples I've tried, the cost will be approximately $10-15. To make it easier, I've just settled on $10 shipping without a tracking number of $15 if you want a tracking number. Regardless of your country. I don't know how long it will take - probably depends on the location (I'll try to inquire when sending).

The book was already downloaded more than 1170 times (I'm not putting the exact number here as it's constantly growing little by little). I wish I knew how many people have, actually, read it in full or in part. I've also received some error corrections (special thanks goes to Serge Kruk), several small reviews and letters of encouragement. Those were very valuable and I hope to see more :)

Greetings from the far away city of Lima, Peru!
I loved this part: "Only losers don't comment their code, and comments will be used extensively"
Thank you so much for putting this comprehensive collection of highly important data structures, i'm already recommending this to two of my developers, which I hope i'll induce into my Lisp addiction.
--Flavio Egoavil

And here's another one:

Massively impressive book you've written! I've been a Lisp programmer for a long time and truly appreciate the work put in here. Making Lisp accessible for more people in relation to practical algorithms is very hard to do. But you truly made it. You'll definitely end up in the gallery of great and modern Lisp contributions like "Land of Lisp" and "Let Over Lambda". Totally agree with your path to focus on practical algorithmic thinking with Lisp and not messing it up with macros, oop and other advanced concepts.
--Lars Hård

Thanks guys, it's really appreciated!

If you feel the same or you've liked the book in some respect and have found it useful, please, continue to share news about it: that definitely helps attract more readers. And my main goal is to make it as widely read as possible...




pr

CALL FOR NOMINATIONS: The 2019 Theszies (the rec.sport.pro-wrestling Awards)

This is the Call for Nominations for the 2019 Theszie Awards (the rec.sport.pro-wrestling Awards). To nominate candidates for all categories, you may use this form. Nominations are due by January 5, 2019. Finally, to see previous years’ results, click here for 2018, click here for 2017, here for 2016, here for 2015, here for 2014, […]



  • Interactive Fun Time Party
  • The RSPW Awards / The Theszies
  • Wrestling

pr

Glowforge Pro 3D Laser Printer







pr

Spring 2020 gatherings cancelled

Out of an abundance of caution regarding the developing COVID-19 situation, U.S. Grand Lodge has decided to cancel its scheduled national gatherings this spring, specifically Advanced Initiator Training, Kaaba Colloquium, and the Electoral College meeting. The Electoral College meeting will be held online according to standard Electoral College procedures. For more information regarding COVID-19, please …

Continue reading













pr

Incident At Price Chopper

He’s standing in the dead middle of the meat section at Price Chopper screaming “HOW CAN THERE NOT BE ANY FUCKING STEAK?”  Someone comes out bearing chicken from behind the steel clad gates of the backroom where they cut meat and stage the cases. “Hey, you got any steak back there?” “Steak? No sir. None.” […]





pr

The Government, The Catholic Church and the prostitution in Malta

In today's The Times, you can read in an article by David Pace O’Shea, that, in general, Maltese are a helpful people, generous, hardworking, humble, careful with their money, welcoming, peaceful and unaggressive and that they love their families and, especially, their children. In the Observer’s opinion, anyone who states that he or she has all those qualities also might add the words conceited and boastful. The word humble is not the first that comes to one’s mind when reading all the other characteristics Mr. O’Shea states that Maltese in general possess. Thank God (just an expression!) that most Maltese do not consider themselves to have all those qualities (and I do not know of any other country’s citizens that would claim all these good characteristics). Since the article is written by a convinced catholic believer it might be interesting to hear his humble view, from a moral and Christian standpoint, on prostitution in Malta. Every time one passes the area around the closed Empire Stadium one can see prostitutes hanging out from windows or standing on the street offering men their services. In Malta it is allowed to buy and sell sexual services; such services are forbidden in many other EU states. One can ask how this complies with the Maltese character as described in today’s Times. The Maltese government and the Church might not officially be in favor of prostitution but they certainly do not try hard to solve the problem. Prostitution is closely connected with criminality such as trafficking and drug related crimes. There is no reason whatsoever to let young women be treated like slaves in any country and especially not in a country like Malta, which is said to be one of the most Christian in the world. It is a shame for Malta!




pr

A Maltese priest’s distorted view of the judiciary's role in society

In yesterdays The Times a Maltese priest, Mgr. Anton Gaucia, complains once more that a High Court in London a few weeks ago gave a sentence ruling that “the Catholic Church can be held liable for the wrongdoings of its priests”. Mgr. Gaucia have earlier, January 8 in Sunday Times, made the same complaint. Now Mgr. Gaucia also complains over the fact that a Mr. Justice in London has ruled that “the saying of prayers as part of the formal meeting of a council is not lawful”, adding that “there is no statutory power permitting the practice to continue”.
First things first; of course the Church shall be liable for what its employees/priests do in Alphain their capacity as priests. The children in these cases were in the care of a Catholic institution. I wonder what Mgr. Gaucia would say about if a municipal employee at a daycare sexually molest a child that the child’s parents left in its care. Of course, the municipality would be responsible for its negligence and for its failure to protect a child. The same goes of course for the Church. Mgr. Gaucia may of course, probably not being a father himself in the more down to earth sense, not understand what damage the Church and its priests done to these children. The people The Observer talked to in this matter in Malta all agree with The Observer and I think it would be wise of the Church to listen to the people in this.
Second; it might soon be time for priests like Mgr. Gauci and his colleagues to realize what century they live in. The time when Catholics ruled southern Europe is gone forever. There are Muslims, Hindus, Jews and many other people of different beliefs that have and are going to have positions in the society among which, of course, also positions in a council. Does Mgr. Gauci really mean that these people must attend Catholic or Protestant prayers? Or shall they leave when such prayer is to be said? Another possibility would of course be to have, say ten, different rooms where people of different beliefs could pray in accordance with such belief before the council meeting. Mgr Gauci, please grow up and realize what reality you live in.




pr

High rate of teenage pregnancies in Malta

Malta has the highest number of teenage mothers in Europe relative to population. There is also a very high rate of sexually transmitted diseases in Malta among teenagers. One need not wonder why this is the case. Malta's schools provide no sex education at all. The church opposes any form of sex education and any form of use of contraceptives. Abortion does not exist as such except as a clause regulating the penalty for an abortion.  There is a tendencyAlpha that teenagers debut earlier with sex than before. One may ask whether Malta’s approach to sex education and contraceptives benefits to society. In today's Malta Times one can read that 32 children have been born in 2011 having mothers that are 16 years old or younger. Sure you can understand those who believe that sex is something for adults and preferably within marriage although it is a little bit old fashioned in today’s society. But that does not change the fact that unwanted children are born because of the attitude towards sex education, contraception and abortion and there is probably no method to prevent this from happen if you do not give teenagers sex education and thus tell them how to avoid pregnancy and sexually transmitted diseases. See also Teenage births once more of March 20




pr

Again, the Maltese judicial system is proven to have collapsed and now it also seems ridiculous



Today one can read in The Times of a man being sentenced to one month in prison and fined 233€ for illegal gambling. The fantastic and almost unbelievable fact is that the crime was committed in 2001 and the man pleaded guilty in 2002. The man had to wait ten years to be punished for a crime he had admitted almost immediately! To make this even more surprising (well, maybe not so surprising; this is probably typically for the judicial system in Malta) the judge found that the prosecution had failed to prove the allegations against the man, but, since he had admitted the crime the judge had to find him guilty. The Observer sincerely hopes that the latter is not true. In most other countries, with a more sophisticated and functioning judicial system than Malta, an admission is not enough to prove that a person has committed a crime.  When famous murders occur, quite many people come to the police and plead guilty. This is a well-known fact among Alphacriminologists. Probably and hopefully The Times has not published full details about why the judge had to find the man guilty.




pr

What should we protect, living people or dead?


Once more, one can read the most fantastic true stories in The Times. AlphaIn today's edition of The Times one is told that a group of M`garr residents are complaining about a proposed extension to a fireworks factory because of the damage an explosion would do. Fair enough, of course one should worry about what damage an explosion would do. But what is it the group worries about? The living people in the neighborhood? No, this is Christian Malta; the worries are not concerning the living people but the dead. This despite the fact that several people are statistically expected to die this year because of fireworks explosions. The Observer is well aware of the fact that many Maltese regard the eternal life as the real life, but is this group not going too far? A named couple says that an explosion could disturb the graves of loved ones. The Observer is well aware that continuing this article would probably be considered blasphemy. Presumably this is a criminal offense in Maltese law so The Observer rests his case.







pr

ICFP Programming Contest 2018

Yep, it on!




pr

Histogram: You have to know the past to understand the present by Tomas Petricek

Histogram: You have to know the past to understand the present by Tomas Petricek, University of Kent

Programs are created through a variety of interactions. A programmer might write some code, run it interactively to check whether it works, use copy and paste, apply a refactoring or choose an item from an auto-complete list. Programming research often forgets about these and represents programs as the resulting text. Consequently, thinking about such interactions is often out of scope. This essay shifts focus from programs to a more interesting question of programming.

We represent programs as lists of interactions such as triggering an auto-complete and choosing an option, declaring a value, introducing a variable or evaluating a piece of code. We explore a number of consequences of this way of thinking about programs. First, if we create functions by writing concrete code using a sample input and applying a refactoring, we do not lose the sample input and can use it later for debugging. Second, if we treat executing code interactively as an interaction and store the results, we can later use this information to give more precise suggestions in auto-complete. Third, by moving away from a textual representation, we can display the same program as text, but also in a view inspired by spreadsheets. Fourth, we can let programmers create programs by directly interacting with live previews as those interactions can be recorded and as a part of program history.

We discuss the key ideas through examples in a simple programming environment for data exploration. Our focus in this essay is more on principles than on providing fine tuned user experience. We keep our environment more explicit, especially when this reveals what is happening behind the scenes. We aim to show that seeing programs as lists of interactions is a powerful change of perspective that can help us build better programming systems with novel features that make programming easier and more accessible. The data exploration environment in this interactive essay may not yet be that, but it gives a glimpse of the future.




pr

Applications of Blockchain to Programming Language Theory

Let's talk about Blockchain. Goal is to use this forum topic to highlight its usefulness to programming language theory and practice. If you're familiar with existing research efforts, please share them here. In addition, feel free to generate ideas for how Blockchain could improve languages and developer productivity.

As one tasty example: Blockchain helps to formalize thinking about mutual knowledge and common knowledge, and potentially think about sharing intergalactic computing power through vast distributed computing fabrics. If we can design contracts in such a way that maximizes the usage of mutual knowledge while minimizing common knowledge to situations where you have to "prove your collateral", third-party transactions could eliminate a lot of back office burden. But, there might be benefits in other areas of computer science from such research, as well.

Some language researchers, like Mark S. Miller, have always dreamed of Agoric and the Decades-Long Quest for Secure Smart Contracts.

Some may also be aware that verification of smart contracts is an important research area, because of the notorious theft of purse via logic bug in an Ethereum smart contract.










pr

Spring Is Here…

Cherry Esplanade Walk (Video)




pr

Zero Notebook 5: Hermes/Fire Sprite

.


Another character that didn't make it into The Iron Dragon's Mother. Industrialized Faerie is a rich world. The three novels I've set in it can only only hint at how rich and strange it is.

This image, for a rarity, was hardly altered at all.


And where, you ask, did I find this. . . ?

The image came from the Body Works show that toured the world some years ago. A large number of corpses were flayed and then carefully preserved, in order to display the wonders of anatomy. The show was controversial at the time because the corpses came from China and there were those who claimed the bodies hadn't been voluntarily donated but those of criminals who had died in prison. The truth of the matter was impossible to ascertain.

The show, however, was extremely popular. My son, Sean Swanwick, worked for a summer as a guide when it was displayed at the Franklin Institute and he told me that they had to watch the people touring it like hawks... Every now and then, someone would try to snap off a finger or other appendage to take home as a souvenir.


Above: Image five. Five more to go.


*




pr

Analysis: Tennis pros' US return amid pandemic no true model

Analysis: Tennis pros' US return amid pandemic no true model




pr

Recent Progress in Automatic Sarcasm Detection

‘Sentiment mining’ – i.e. trying to gauge the Public’s attitude towards an institution, product, firm (etc. etc.) though automatic analysis of Social Media posts (etc. etc.) is now considered an essential tool for market researchers and ‘reputation managers’. But there are problems. One of which is sarcasm. Given its prevalence, serious errors can be introduced […]




pr

Software that predicts whether you look like, and so will be, a criminal

Harrisburg University proudly announces, in a press release: HU facial recognition software predicts criminality A group of Harrisburg University professors and a Ph.D. student have developed automated computer facial recognition software capable of predicting whether someone is likely going to be a criminal. With 80 percent accuracy and with no racial bias, the software can […]




pr

A new comic (in 2 languages) about Ig Nobel Prize winners

A new comic strip—in Russian and in English—about some of the curious characters who have won Ig Nobel Prizes. The series appears on Instagram.




pr

Greedy Cloud’s Hidden Spring Furniture and Garden Décor Items Discovered!

Dear Idea Seeker or Ally of the Idea Seekers, I have great news!  Greedy Cloud has been chased away and Spec and Tra discovered some new spring time house and garden items that he was hiding from everyone. Check them out in my house and garden, or go see Spec, Tra and Skeeter’s houses. Here […]




pr

Well, There's Your Problem

Submitter Denene's mechanic took this photo.





pr

Don't Be Surprised if it Doesn't Flush

I think they spent all their money on the fancy toilet paper. ~NSHA




pr

Why your site needs a privacy policy page

Having a privacy policy for your website or blog is a way to declare to your viewers and subscribers on what happens with any information that’s collected on them, why it’s being collected, and how that information is being stored. This is a vital component to your site if your site is for business, or if you have a website that uses affiliate type advertising in order to earn revenue such as Amazon or Google Adsense. In fact not having a privacy policy will get your affiliate account banned on most sites, so apart from that and covering your back to protect yourself from legal action are good enough reasons to have privacy policy.




pr

How to promote your website for free

It seems there are literally thousands of sites that promise to promote your website or blog…..but for a price. The best known one is Google Adwords where you pay so many cents per click depending on the competition of the Keywords you want top rankings in. And while this will get your website to the top page in Google not everyone has the budget to fork out hundreds of dollars in advertising. But you can promote your site for free using some of these methods. Most of these are going to take time to build up before you start noticing huge amounts of traffic, but they will work if your willing to put the time in.




pr

How to promote your website using twitter

Using twitter is a great way to promote your website or blog and increase traffic. If your new to twitter and never used it before it works like this. You get 140 characters to write a short statement or advertisement depending on what you’re using the site for. Most people tweet simple things like there not feeling well or changes in their social life. All that’s fine but you want to use it to promote your website, so here are some simple things to optimize your tweets to get the maximum traffic return.




pr

How To Prepare For An Earthquake Part 1

Unless you live under a rock you know well enough about the devastation that recently happened in Japan and just how fast a devastating earthquake can tear things apart. If you live in an area prone to earthquakes your emergency preparedness plan must encompass earthquake survival. So how do you prepare for an earthquake? In this first of 2 posts on earthquake survival I’ll show you what you can do to better prepare your home.